Improve the error handling when starting a session

If the command cannot be started, or the proxy server can't be reached,
exit early and a bit nicer.
pull/25/head
Vasile Popescu 4 years ago committed by Elis Popescu
parent 8802e00ef3
commit 9573987434

@ -125,6 +125,13 @@ Flags:
os.Exit(1)
}
ptyMaster := ptyMasterNew()
err := ptyMaster.Start(*commandName, strings.Fields(*commandArgs))
if err != nil {
log.Errorf("Cannot start the %s command: %s", *commandName, err.Error())
return
}
sessionID := "local"
if *publicSession {
proxy, err := proxy.NewProxyConnection(*listenAddress, *proxyServerAddress, *noTLS)
@ -145,11 +152,8 @@ Flags:
fmt.Printf("Press Enter to continue!\n")
bufio.NewReader(os.Stdin).ReadString('\n')
ptyMaster := ptyMasterNew()
ptyMaster.MakeRaw()
defer ptyMaster.Restore()
ptyMaster.Start(*commandName, strings.Fields(*commandArgs))
var pty server.PTYHandler = ptyMaster
if *readOnly {
pty = &nilPTY{}

@ -31,15 +31,6 @@ func isStdinTerminal() bool {
}
func (pty *ptyMaster) Start(command string, args []string) (err error) {
// Save the initial state of the terminal, before making it RAW. Note that this terminal is the
// terminal under which the tty-share command has been started, and it's identified via the
// stdin file descriptor (0 in this case)
// We need to make this terminal RAW so that when the command (passed here as a string, a shell
// usually), is receiving all the input, including the special characters:
// so no SIGINT for Ctrl-C, but the RAW character data, so no line discipline.
// Read more here: https://www.linusakesson.net/programming/tty/
pty.terminalInitState, err = terminal.MakeRaw(0)
pty.command = exec.Command(command, args...)
pty.ptyFile, err = ptyDevice.Start(pty.command)
@ -53,6 +44,19 @@ func (pty *ptyMaster) Start(command string, args []string) (err error) {
return
}
func (pty *ptyMaster) MakeRaw() (err error) {
// Save the initial state of the terminal, before making it RAW. Note that this terminal is the
// terminal under which the tty-share command has been started, and it's identified via the
// stdin file descriptor (0 in this case)
// We need to make this terminal RAW so that when the command (passed here as a string, a shell
// usually), is receiving all the input, including the special characters:
// so no SIGINT for Ctrl-C, but the RAW character data, so no line discipline.
// Read more here: https://www.linusakesson.net/programming/tty/
pty.terminalInitState, err = terminal.MakeRaw(int(os.Stdin.Fd()))
return
}
func (pty *ptyMaster) SetWinChangeCB(winChangedCB onWindowChangedCB) {
// Start listening for window changes
go onWindowChanges(func(cols, rows int) {

Loading…
Cancel
Save