Skip to content

Commit

Permalink
rootlessport: use two different channels
Browse files Browse the repository at this point in the history
The same channel is written to by two different goroutines.

Use a different channel for each of them so to avoid writing to a
closed channel.

Closes: containers#6018

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe authored and snj33v committed May 31, 2020
1 parent 4d89a8a commit 98b407c
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions pkg/rootlessport/rootlessport_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,27 @@ func parent() error {
return err
}

sigC := make(chan os.Signal, 1)
signal.Notify(sigC, unix.SIGPIPE)
defer func() {
// dummy signal to terminate the goroutine
sigC <- unix.SIGKILL
}()
exitC := make(chan os.Signal, 1)
defer close(exitC)

go func() {
sigC := make(chan os.Signal, 1)
signal.Notify(sigC, unix.SIGPIPE)
defer func() {
signal.Stop(sigC)
close(sigC)
}()

s := <-sigC
if s == unix.SIGPIPE {
if f, err := os.OpenFile("/dev/null", os.O_WRONLY, 0755); err == nil {
unix.Dup2(int(f.Fd()), 1) // nolint:errcheck
unix.Dup2(int(f.Fd()), 2) // nolint:errcheck
f.Close()
select {
case s := <-sigC:
if s == unix.SIGPIPE {
if f, err := os.OpenFile("/dev/null", os.O_WRONLY, 0755); err == nil {
unix.Dup2(int(f.Fd()), 1) // nolint:errcheck
unix.Dup2(int(f.Fd()), 2) // nolint:errcheck
f.Close()
}
}
case <-exitC:
}
}()

Expand Down

0 comments on commit 98b407c

Please sign in to comment.