From 73a7c9245ecc1fbc449b571db3f87ff25651721a Mon Sep 17 00:00:00 2001 From: Martin Hebnes Pedersen Date: Fri, 31 Oct 2014 23:00:03 +0100 Subject: [PATCH] Wait for kissattach to daemonize instead of sleeping. This also cleans up the reaped process (defunct). --- kissattach.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/kissattach.go b/kissattach.go index 93bd52d..7aa4336 100644 --- a/kissattach.go +++ b/kissattach.go @@ -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) { @@ -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)) @@ -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() }