diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-06-02 04:35:18 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-06-02 04:35:18 +0000 |
commit | c36d6852de35bdd2cceec369a8e6c47d1ef730a3 (patch) | |
tree | 9556806f38b8822120909ce964819ec45c4e1b5a /runsc/specutils | |
parent | 5d44e115d2b4de8390d26b58db4b154fd1149773 (diff) | |
parent | ca5912d13c63dcaff72bf6eb6d49bde8fc4e3f73 (diff) |
Merge release-20200522.0-58-gca5912d1 (automated)
Diffstat (limited to 'runsc/specutils')
-rw-r--r-- | runsc/specutils/namespace.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/runsc/specutils/namespace.go b/runsc/specutils/namespace.go index 60bb7b7ee..23001d67c 100644 --- a/runsc/specutils/namespace.go +++ b/runsc/specutils/namespace.go @@ -18,6 +18,7 @@ import ( "fmt" "os" "os/exec" + "os/signal" "path/filepath" "runtime" "syscall" @@ -261,7 +262,18 @@ func MaybeRunAsRoot() error { cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - if err := cmd.Run(); err != nil { + if err := cmd.Start(); err != nil { + return fmt.Errorf("re-executing self: %w", err) + } + ch := make(chan os.Signal, 1) + signal.Notify(ch) + go func() { + for { + // Forward all signals to child process. + cmd.Process.Signal(<-ch) + } + }() + if err := cmd.Wait(); err != nil { if exit, ok := err.(*exec.ExitError); ok { if ws, ok := exit.Sys().(syscall.WaitStatus); ok { os.Exit(ws.ExitStatus()) @@ -269,7 +281,7 @@ func MaybeRunAsRoot() error { log.Warningf("No wait status provided, exiting with -1: %v", err) os.Exit(-1) } - return fmt.Errorf("re-executing self: %v", err) + return err } // Child completed with success. os.Exit(0) |