diff options
author | Kevin Krakauer <krakauer@google.com> | 2018-09-12 15:22:24 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-09-12 15:23:35 -0700 |
commit | 2eff1fdd061be9cfabc36532dda8cbefeb02e534 (patch) | |
tree | 009e2a9cbca191a2d2a471b30380888cd50c0b4a /runsc/cmd | |
parent | 0efde2bfbde2fea78134a32f5fb34332ec0ce531 (diff) |
runsc: Add exec flag that specifies where to save the sandbox-internal pid.
This is different from the existing -pid-file flag, which saves a host pid.
PiperOrigin-RevId: 212713968
Change-Id: I2c486de8dd5cfd9b923fb0970165ef7c5fc597f0
Diffstat (limited to 'runsc/cmd')
-rw-r--r-- | runsc/cmd/exec.go | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/runsc/cmd/exec.go b/runsc/cmd/exec.go index da1642c08..0d1fa6e20 100644 --- a/runsc/cmd/exec.go +++ b/runsc/cmd/exec.go @@ -45,12 +45,13 @@ type Exec struct { cwd string env stringSlice // user contains the UID and GID with which to run the new process. - user user - extraKGIDs stringSlice - caps stringSlice - detach bool - processPath string - pidFile string + user user + extraKGIDs stringSlice + caps stringSlice + detach bool + processPath string + pidFile string + internalPidFile string // consoleSocket is the path to an AF_UNIX socket which will receive a // file descriptor referencing the master end of the console's @@ -97,6 +98,7 @@ func (ex *Exec) SetFlags(f *flag.FlagSet) { f.BoolVar(&ex.detach, "detach", false, "detach from the container's process") f.StringVar(&ex.processPath, "process", "", "path to the process.json") f.StringVar(&ex.pidFile, "pid-file", "", "filename that the container pid will be written to") + f.StringVar(&ex.internalPidFile, "internal-pid-file", "", "filename that the container-internal pid will be written to") f.StringVar(&ex.consoleSocket, "console-socket", "", "path to an AF_UNIX socket which will receive a file descriptor referencing the master end of the console's pseudoterminal") } @@ -146,10 +148,25 @@ func (ex *Exec) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) } } - ws, err := c.Execute(e) + // Start the new process and get it pid. + pid, err := c.Execute(e) if err != nil { Fatalf("error getting processes for container: %v", err) } + + // Write the sandbox-internal pid if required. + if ex.internalPidFile != "" { + pidStr := []byte(strconv.Itoa(int(pid))) + if err := ioutil.WriteFile(ex.internalPidFile, pidStr, 0644); err != nil { + Fatalf("error writing internal pid file %q: %v", ex.internalPidFile, err) + } + } + + // Wait for the process to exit. + ws, err := c.WaitPID(pid) + if err != nil { + Fatalf("error waiting on pid %d: %v", pid, err) + } *waitStatus = ws return subcommands.ExitSuccess } |