The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/3039
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
From 880c5f2b70a9852abfe78812b0691557bbd58982 Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Wed, 8 Mar 2017 01:51:46 +0100 Subject: [PATCH] exec: replace os.FindProcess() with syscall.Wait4() Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- lxd/container_exec.go | 27 ++++++++------------------- lxd/main_forkexec.go | 27 ++++++++------------------- 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/lxd/container_exec.go b/lxd/container_exec.go index d4da9aa..ca3ba7f 100644 --- a/lxd/container_exec.go +++ b/lxd/container_exec.go @@ -301,30 +301,19 @@ func (s *execWs) Do(op *operation) error { attachedChildIsBorn <- attachedPid } - proc, err := os.FindProcess(pid) - if err != nil { + var ws syscall.WaitStatus + wpid, err := syscall.Wait4(pid, &ws, 0, nil) + if err != nil || wpid != pid { return finisher(-1, fmt.Errorf("Failed finding process: %q", err)) } - procState, err := proc.Wait() - if err != nil { - return finisher(-1, fmt.Errorf("Failed waiting on process %d: %q", pid, err)) - } - - if procState.Success() { - return finisher(0, nil) + if ws.Exited() { + return finisher(ws.ExitStatus(), nil) } - status, ok := procState.Sys().(syscall.WaitStatus) - if ok { - if status.Exited() { - return finisher(status.ExitStatus(), nil) - } - - if status.Signaled() { - // 128 + n == Fatal error signal "n" - return finisher(128+int(status.Signal()), nil) - } + if ws.Signaled() { + // 128 + n == Fatal error signal "n" + return finisher(128+int(ws.Signal()), nil) } return finisher(-1, nil) diff --git a/lxd/main_forkexec.go b/lxd/main_forkexec.go index 917219f..bdbdcac 100644 --- a/lxd/main_forkexec.go +++ b/lxd/main_forkexec.go @@ -103,30 +103,19 @@ func cmdForkExec(args []string) (int, error) { return -1, fmt.Errorf("Failed sending PID of executing command: %q", err) } - proc, err := os.FindProcess(status) - if err != nil { + var ws syscall.WaitStatus + wpid, err := syscall.Wait4(status, &ws, 0, nil) + if err != nil || wpid != status { return -1, fmt.Errorf("Failed finding process: %q", err) } - procState, err := proc.Wait() - if err != nil { - return -1, fmt.Errorf("Failed waiting on process %d: %q", status, err) - } - - if procState.Success() { - return 0, nil + if ws.Exited() { + return ws.ExitStatus(), nil } - exCode, ok := procState.Sys().(syscall.WaitStatus) - if ok { - if exCode.Signaled() { - // 128 + n == Fatal error signal "n" - return 128 + int(exCode.Signal()), nil - } - - if exCode.Exited() { - return exCode.ExitStatus(), nil - } + if ws.Signaled() { + // 128 + n == Fatal error signal "n" + return 128 + int(ws.Signal()), nil } return -1, fmt.Errorf("Command failed")
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel