Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recttty: nits #2694

Merged
merged 3 commits into from
Dec 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions contrib/cmd/recvtty/recvtty.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net"
"os"
"strings"
"sync"

"github.com/containerd/console"
"github.com/opencontainers/runc/libcontainer/utils"
Expand Down Expand Up @@ -110,22 +111,32 @@ func handleSingle(path string, noStdin bool) error {
}

// Copy from our stdio to the master fd.
quitChan := make(chan struct{})
var (
wg sync.WaitGroup
inErr, outErr error
)
wg.Add(1)
go func() {
io.Copy(os.Stdout, c)
quitChan <- struct{}{}
_, outErr = io.Copy(os.Stdout, c)
wg.Done()
}()
if !noStdin {
wg.Add(1)
go func() {
io.Copy(c, os.Stdin)
quitChan <- struct{}{}
_, inErr = io.Copy(c, os.Stdin)
wg.Done()
}()
}

// Only close the master fd once we've stopped copying.
<-quitChan
wg.Wait()
c.Close()
return nil

if outErr != nil {
return outErr
}

return inErr
}

func handleNull(path string) error {
Expand Down Expand Up @@ -165,15 +176,7 @@ func handleNull(path string) error {
return
}

// Just do a dumb copy to /dev/null.
devnull, err := os.OpenFile("/dev/null", os.O_RDWR, 0)
if err != nil {
// TODO: Handle this nicely.
return
}

io.Copy(devnull, master)
devnull.Close()
_, _ = io.Copy(ioutil.Discard, master)
}(conn)
}
}
Expand Down