[lxc-devel] [lxc/master] attach: report standard shell exit codes

brauner on Github lxc-bot at linuxcontainers.org
Wed Sep 19 07:17:09 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 449 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180919/92e0e0d4/attachment.bin>
-------------- next part --------------
From 61d34943c2ca87b465f6253b42363918f505c048 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 19 Sep 2018 09:15:36 +0200
Subject: [PATCH] attach: report standard shell exit codes

POSIX mandates that on ENOEXEC 126 and on ENOENT 127 is supposed to be
reported.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/attach.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index ffae98539..0f00c555a 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -1512,9 +1512,18 @@ int lxc_attach(const char *name, const char *lxcpath,
 
 int lxc_attach_run_command(void* payload)
 {
+	int ret;
 	lxc_attach_command_t* cmd = (lxc_attach_command_t*)payload;
 
-	execvp(cmd->program, cmd->argv);
+	ret = execvp(cmd->program, cmd->argv);
+	if (ret < 0) {
+		switch (errno) {
+		case ENOEXEC:
+			return 126;
+		case ENOENT:
+			return 127;
+		}
+	}
 
 	SYSERROR("Failed to exec \"%s\"", cmd->program);
 	return -1;


More information about the lxc-devel mailing list