diff options
author | Giuseppe Scrivano <gscrivan@redhat.com> | 2020-04-29 12:32:34 +0200 |
---|---|---|
committer | Giuseppe Scrivano <gscrivan@redhat.com> | 2020-04-29 16:56:12 +0200 |
commit | b3b889d8a24340249f668df9e68f5e95646cc004 (patch) | |
tree | 2ec2297da7889d74e2f337807b54eac79402a0ac /pkg/rootlessport/rootlessport_linux.go | |
parent | 41853454b0c9ef57736965c6ba7d646c63ff42da (diff) | |
download | podman-b3b889d8a24340249f668df9e68f5e95646cc004.tar.gz podman-b3b889d8a24340249f668df9e68f5e95646cc004.tar.bz2 podman-b3b889d8a24340249f668df9e68f5e95646cc004.zip |
rootlessport: use two different channels
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: https://github.com/containers/libpod/issues/6018
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
(cherry picked from commit 6d545bb2f773ff996ce28e0b6608380206835004)
Diffstat (limited to 'pkg/rootlessport/rootlessport_linux.go')
-rw-r--r-- | pkg/rootlessport/rootlessport_linux.go | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/pkg/rootlessport/rootlessport_linux.go b/pkg/rootlessport/rootlessport_linux.go index 1c1ed39df..c686d80fc 100644 --- a/pkg/rootlessport/rootlessport_linux.go +++ b/pkg/rootlessport/rootlessport_linux.go @@ -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: } }() |