[lxc-devel] [lxc/master] fix up lxc-usernsexec's exit status

tych0 on Github lxc-bot at linuxcontainers.org
Mon Jan 8 16:22:10 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 501 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180108/02608b9a/attachment.bin>
-------------- next part --------------
From d8208db47785d93d8dcb96a83c0b015587a77448 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho at tycho.ws>
Date: Mon, 8 Jan 2018 16:20:24 +0000
Subject: [PATCH] fix up lxc-usernsexec's exit status

* exit(1) when there is an option parsing error
* exit(0) when the user explicitly asks for help
* exit(1) when the user specifies an invalid option

Signed-off-by: Tycho Andersen <tycho at tycho.ws>
---
 src/lxc/tools/lxc_usernsexec.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/lxc/tools/lxc_usernsexec.c b/src/lxc/tools/lxc_usernsexec.c
index 72d4a005b..766bd72e6 100644
--- a/src/lxc/tools/lxc_usernsexec.c
+++ b/src/lxc/tools/lxc_usernsexec.c
@@ -71,7 +71,6 @@ static void usage(const char *name)
 	printf("  Note: This program uses newuidmap(2) and newgidmap(2).\n");
 	printf("        As such, /etc/subuid and /etc/subgid must grant the\n");
 	printf("        calling user permission to use the mapped ranges\n");
-	exit(EXIT_SUCCESS);
 }
 
 static void opentty(const char * tty, int which) {
@@ -300,10 +299,18 @@ int main(int argc, char *argv[])
 
 	while ((c = getopt(argc, argv, "m:h")) != EOF) {
 		switch (c) {
-			case 'm': if (parse_map(optarg)) usage(argv[0]); break;
+			case 'm':
+				if (parse_map(optarg)) {
+					usage(argv[0]);
+					exit(EXIT_FAILURE);
+				}
+				break;
 			case 'h':
+				  usage(argv[0]);
+				  exit(EXIT_SUCCESS);
 			default:
 				  usage(argv[0]);
+				  exit(EXIT_FAILURE);
 		}
 	};
 


More information about the lxc-devel mailing list