diff --git a/main.go b/main.go index 9874217..53248f3 100644 --- a/main.go +++ b/main.go @@ -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{} diff --git a/pty_master.go b/pty_master.go index 8a26a09..ed0c9b2 100644 --- a/pty_master.go +++ b/pty_master.go @@ -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) {