Skip to content

Commit

Permalink
Wait for kissattach to daemonize instead of sleeping. This also clean…
Browse files Browse the repository at this point in the history
…s up the reaped process (defunct).
  • Loading branch information
martinhpedersen committed Oct 31, 2014
1 parent a0269ec commit 73a7c92
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions kissattach.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
krpty "github.com/kr/pty"
"os"
"os/exec"
"time"
)

func KissAttach(port string, mtu int) (pty *os.File, err error) {
Expand All @@ -14,8 +13,6 @@ func KissAttach(port string, mtu int) (pty *os.File, err error) {
return nil, err
}

time.Sleep(100 * time.Millisecond)

args := []string{tty.Name(), port, "-l"}
if mtu > 0 {
args = append(args, fmt.Sprintf("-m %d", mtu))
Expand All @@ -31,9 +28,11 @@ func KissAttach(port string, mtu int) (pty *os.File, err error) {
return nil, err
}

// Wait for kissattach to open tty
time.Sleep(2 * time.Second)
// Wait for kissattach to daemonize
if err = c.Wait(); err != nil {
pty.Close()
return nil, err
}

err = tty.Close()
return pty, err
return pty, tty.Close()
}

0 comments on commit 73a7c92

Please sign in to comment.