[lxc-devel] [lxd/master] forkexec: remove os.FindProcess

brauner on Github lxc-bot at linuxcontainers.org
Fri Apr 14 12:38:28 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 508 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170414/2fd0e725/attachment.bin>
-------------- next part --------------
From 1a215c0bb0b378763d552d9eea97e9d47d076c79 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 14 Apr 2017 14:34:39 +0200
Subject: [PATCH] forkexec: remove os.FindProcess

Replace it by syscall.Wait4() in this case. This should remove the last traces
of FindProcess.

Closes #3037.
Possibly relates to #3157.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxd/main_forkexec.go | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

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")


More information about the lxc-devel mailing list