[lxc-devel] [lxc/master] tools: use exit(EXIT_*) everywhere

brauner on Github lxc-bot at linuxcontainers.org
Thu Aug 18 07:27:02 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 352 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160818/9a2d5b82/attachment.bin>
-------------- next part --------------
From 233163826da062ca16e09d4b15386c6365aefcab Mon Sep 17 00:00:00 2001
From: Christian Brauner <cbrauner at suse.de>
Date: Thu, 18 Aug 2016 09:16:41 +0200
Subject: [PATCH] tools: use exit(EXIT_*) everywhere

Signed-off-by: Christian Brauner <cbrauner at suse.de>
---
 src/lxc/tools/lxc_autostart.c  |  8 ++++----
 src/lxc/tools/lxc_cgroup.c     | 20 ++++++++++----------
 src/lxc/tools/lxc_checkpoint.c | 19 +++++++++++--------
 src/lxc/tools/lxc_config.c     |  4 ++--
 src/lxc/tools/lxc_console.c    |  2 +-
 src/lxc/tools/lxc_device.c     |  6 +++---
 src/lxc/tools/lxc_execute.c    | 18 +++++++++---------
 src/lxc/tools/lxc_freeze.c     | 16 ++++++++--------
 src/lxc/tools/lxc_info.c       |  6 +++---
 src/lxc/tools/lxc_monitor.c    | 18 +++++++-----------
 src/lxc/tools/lxc_start.c      | 24 +++++++++++------------
 src/lxc/tools/lxc_stop.c       | 43 +++++++++++++++++++++---------------------
 src/lxc/tools/lxc_top.c        |  2 +-
 src/lxc/tools/lxc_unfreeze.c   | 16 ++++++++--------
 src/lxc/tools/lxc_unshare.c    | 18 +++++++++---------
 src/lxc/tools/lxc_usernsexec.c | 18 +++++++++---------
 src/lxc/tools/lxc_wait.c       | 16 ++++++++--------
 17 files changed, 127 insertions(+), 127 deletions(-)

diff --git a/src/lxc/tools/lxc_autostart.c b/src/lxc/tools/lxc_autostart.c
index eed0f5f..267cb6c 100644
--- a/src/lxc/tools/lxc_autostart.c
+++ b/src/lxc/tools/lxc_autostart.c
@@ -334,17 +334,17 @@ int main(int argc, char *argv[])
 	struct lxc_list *cmd_group;
 
 	if (lxc_arguments_parse(&my_args, argc, argv))
-		return 1;
+		exit(EXIT_FAILURE);
 
 	if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
 			 my_args.progname, my_args.quiet, my_args.lxcpath[0]))
-		return 1;
+		exit(EXIT_FAILURE);
 	lxc_log_options_no_override();
 
 	count = list_defined_containers(my_args.lxcpath[0], NULL, &containers);
 
 	if (count < 0)
-		return 1;
+		exit(EXIT_FAILURE);
 
 	if (!my_args.all) {
 		/* Allocate an array for our container group lists */
@@ -522,5 +522,5 @@ int main(int argc, char *argv[])
 	toss_list( cmd_groups_list );
 	free(containers);
 
-	return 0;
+	exit(EXIT_SUCCESS);
 }
diff --git a/src/lxc/tools/lxc_cgroup.c b/src/lxc/tools/lxc_cgroup.c
index 4dc2682..32d333a 100644
--- a/src/lxc/tools/lxc_cgroup.c
+++ b/src/lxc/tools/lxc_cgroup.c
@@ -69,47 +69,47 @@ int main(int argc, char *argv[])
 	struct lxc_container *c;
 
 	if (lxc_arguments_parse(&my_args, argc, argv))
-		return 1;
+		exit(EXIT_FAILURE);
 
 	if (!my_args.log_file)
 		my_args.log_file = "none";
 
 	if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
 			 my_args.progname, my_args.quiet, my_args.lxcpath[0]))
-		return 1;
+		exit(EXIT_FAILURE);
 	lxc_log_options_no_override();
 
 	state_object = my_args.argv[0];
 
 	c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
 	if (!c)
-		return 1;
+		exit(EXIT_FAILURE);
 
 	if (my_args.rcfile) {
 		c->clear_config(c);
 		if (!c->load_config(c, my_args.rcfile)) {
 			ERROR("Failed to load rcfile");
 			lxc_container_put(c);
-			return 1;
+			exit(EXIT_FAILURE);
 		}
 		c->configfile = strdup(my_args.rcfile);
 		if (!c->configfile) {
 			ERROR("Out of memory setting new config filename");
 			lxc_container_put(c);
-			return 1;
+			exit(EXIT_FAILURE);
 		}
 	}
 
 	if (!c->may_control(c)) {
 		ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
 		lxc_container_put(c);
-		return 1;
+		exit(EXIT_FAILURE);
 	}
 
 	if (!c->is_running(c)) {
 		ERROR("'%s:%s' is not running", my_args.lxcpath[0], my_args.name);
 		lxc_container_put(c);
-		return 1;
+		exit(EXIT_FAILURE);
 	}
 
 	if ((my_args.argc) > 1) {
@@ -118,7 +118,7 @@ int main(int argc, char *argv[])
 			ERROR("failed to assign '%s' value to '%s' for '%s'",
 				value, state_object, my_args.name);
 			lxc_container_put(c);
-			return 1;
+			exit(EXIT_FAILURE);
 		}
 	} else {
 		int len = 4096;
@@ -128,11 +128,11 @@ int main(int argc, char *argv[])
 			ERROR("failed to retrieve value of '%s' for '%s:%s'",
 			      state_object, my_args.lxcpath[0], my_args.name);
 			lxc_container_put(c);
-			return 1;
+			exit(EXIT_FAILURE);
 		}
 		printf("%*s", ret, buffer);
 	}
 
 	lxc_container_put(c);
-	return 0;
+	exit(EXIT_SUCCESS);
 }
diff --git a/src/lxc/tools/lxc_checkpoint.c b/src/lxc/tools/lxc_checkpoint.c
index 6de3d23..462aba3 100644
--- a/src/lxc/tools/lxc_checkpoint.c
+++ b/src/lxc/tools/lxc_checkpoint.c
@@ -198,21 +198,21 @@ int main(int argc, char *argv[])
 	bool ret;
 
 	if (lxc_arguments_parse(&my_args, argc, argv))
-		exit(1);
+		exit(EXIT_FAILURE);
 
 	if (!my_args.log_file)
 		my_args.log_file = "none";
 
 	if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
 			 my_args.progname, my_args.quiet, my_args.lxcpath[0]))
-		exit(1);
+		exit(EXIT_FAILURE);
 
 	lxc_log_options_no_override();
 
 	c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
 	if (!c) {
 		fprintf(stderr, "System error loading %s\n", my_args.name);
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 	if (my_args.rcfile) {
@@ -220,26 +220,26 @@ int main(int argc, char *argv[])
 		if (!c->load_config(c, my_args.rcfile)) {
 			fprintf(stderr, "Failed to load rcfile\n");
 			lxc_container_put(c);
-			exit(1);
+			exit(EXIT_FAILURE);
 		}
 		c->configfile = strdup(my_args.rcfile);
 		if (!c->configfile) {
 			fprintf(stderr, "Out of memory setting new config filename\n");
 			lxc_container_put(c);
-			exit(1);
+			exit(EXIT_FAILURE);
 		}
 	}
 
 	if (!c->may_control(c)) {
 		fprintf(stderr, "Insufficent privileges to control %s\n", my_args.name);
 		lxc_container_put(c);
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 	if (!c->is_defined(c)) {
 		fprintf(stderr, "%s is not defined\n", my_args.name);
 		lxc_container_put(c);
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 
@@ -248,5 +248,8 @@ int main(int argc, char *argv[])
 	else
 		ret = checkpoint(c);
 
-	return !ret;
+	if (!ret)
+		exit(EXIT_FAILURE);
+
+	exit(EXIT_SUCCESS);
 }
diff --git a/src/lxc/tools/lxc_config.c b/src/lxc/tools/lxc_config.c
index d146ad8..998fa32 100644
--- a/src/lxc/tools/lxc_config.c
+++ b/src/lxc/tools/lxc_config.c
@@ -73,9 +73,9 @@ int main(int argc, char *argv[])
 				printf("%s\n", value);
 			else
 				printf("%s is not set.\n", argv[1]);
-			exit(0);
+			exit(EXIT_SUCCESS);
 		}
 	}
 	printf("Unknown configuration item: %s\n", argv[1]);
-	exit(1);
+	exit(EXIT_FAILURE);
 }
diff --git a/src/lxc/tools/lxc_console.c b/src/lxc/tools/lxc_console.c
index 829c908..5d8dd4d 100644
--- a/src/lxc/tools/lxc_console.c
+++ b/src/lxc/tools/lxc_console.c
@@ -146,5 +146,5 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 	lxc_container_put(c);
-	return EXIT_SUCCESS;
+	exit(EXIT_SUCCESS);
 }
diff --git a/src/lxc/tools/lxc_device.c b/src/lxc/tools/lxc_device.c
index 49af062..9cd7614 100644
--- a/src/lxc/tools/lxc_device.c
+++ b/src/lxc/tools/lxc_device.c
@@ -106,7 +106,7 @@ int main(int argc, char *argv[])
 
 	if (geteuid() != 0) {
 		ERROR("%s must be run as root", argv[0]);
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 	if (lxc_arguments_parse(&my_args, argc, argv))
@@ -184,9 +184,9 @@ int main(int argc, char *argv[])
 		ERROR("Error: Please use add or del (Please see --help output)");
 		goto err1;
 	}
-	exit(0);
+	exit(EXIT_SUCCESS);
 err1:
 	lxc_container_put(c);
 err:
-	exit(ret);
+	exit(EXIT_FAILURE);
 }
diff --git a/src/lxc/tools/lxc_execute.c b/src/lxc/tools/lxc_execute.c
index c7c5096..13fa799 100644
--- a/src/lxc/tools/lxc_execute.c
+++ b/src/lxc/tools/lxc_execute.c
@@ -102,14 +102,14 @@ int main(int argc, char *argv[])
 	lxc_list_init(&defines);
 
 	if (lxc_caps_init())
-		return 1;
+		exit(EXIT_FAILURE);
 
 	if (lxc_arguments_parse(&my_args, argc, argv))
-		return 1;
+		exit(EXIT_FAILURE);
 
 	if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
 			 my_args.progname, my_args.quiet, my_args.lxcpath[0]))
-		return 1;
+		exit(EXIT_FAILURE);
 	lxc_log_options_no_override();
 
 	/* rcfile is specified in the cli option */
@@ -121,7 +121,7 @@ int main(int argc, char *argv[])
 		rc = asprintf(&rcfile, "%s/%s/config", my_args.lxcpath[0], my_args.name);
 		if (rc == -1) {
 			SYSERROR("failed to allocate memory");
-			return 1;
+			exit(EXIT_FAILURE);
 		}
 
 		/* container configuration does not exist */
@@ -134,16 +134,16 @@ int main(int argc, char *argv[])
 	conf = lxc_conf_init();
 	if (!conf) {
 		ERROR("failed to initialize configuration");
-		return 1;
+		exit(EXIT_FAILURE);
 	}
 
 	if (rcfile && lxc_config_read(rcfile, conf, NULL)) {
 		ERROR("failed to read configuration file");
-		return 1;
+		exit(EXIT_FAILURE);
 	}
 
 	if (lxc_config_define_load(&defines, conf))
-		return 1;
+		exit(EXIT_FAILURE);
 
 	if (my_args.uid)
 		conf->init_uid = my_args.uid;
@@ -156,6 +156,6 @@ int main(int argc, char *argv[])
 	lxc_conf_free(conf);
 
 	if (ret < 0)
-		return 1;
-	return ret;
+		exit(EXIT_FAILURE);
+	exit(EXIT_SUCCESS);
 }
diff --git a/src/lxc/tools/lxc_freeze.c b/src/lxc/tools/lxc_freeze.c
index ac0802e..33445c8 100644
--- a/src/lxc/tools/lxc_freeze.c
+++ b/src/lxc/tools/lxc_freeze.c
@@ -59,20 +59,20 @@ int main(int argc, char *argv[])
 	struct lxc_container *c;
 
 	if (lxc_arguments_parse(&my_args, argc, argv))
-		exit(1);
+		exit(EXIT_FAILURE);
 
 	if (!my_args.log_file)
 		my_args.log_file = "none";
 
 	if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
 			 my_args.progname, my_args.quiet, my_args.lxcpath[0]))
-		exit(1);
+		exit(EXIT_FAILURE);
 	lxc_log_options_no_override();
 
 	c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
 	if (!c) {
 		ERROR("No such container: %s:%s", my_args.lxcpath[0], my_args.name);
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 	if (my_args.rcfile) {
@@ -80,29 +80,29 @@ int main(int argc, char *argv[])
 		if (!c->load_config(c, my_args.rcfile)) {
 			ERROR("Failed to load rcfile");
 			lxc_container_put(c);
-			exit(1);
+			exit(EXIT_FAILURE);
 		}
 		c->configfile = strdup(my_args.rcfile);
 		if (!c->configfile) {
 			ERROR("Out of memory setting new config filename");
 			lxc_container_put(c);
-			exit(1);
+			exit(EXIT_FAILURE);
 		}
 	}
 
 	if (!c->may_control(c)) {
 		ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
 		lxc_container_put(c);
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 	if (!c->freeze(c)) {
 		ERROR("Failed to freeze %s:%s", my_args.lxcpath[0], my_args.name);
 		lxc_container_put(c);
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 	lxc_container_put(c);
 
-	exit(0);
+	exit(EXIT_SUCCESS);
 }
diff --git a/src/lxc/tools/lxc_info.c b/src/lxc/tools/lxc_info.c
index 08c698d..2888537 100644
--- a/src/lxc/tools/lxc_info.c
+++ b/src/lxc/tools/lxc_info.c
@@ -396,18 +396,18 @@ int main(int argc, char *argv[])
 	int ret = EXIT_FAILURE;
 
 	if (lxc_arguments_parse(&my_args, argc, argv))
-		return ret;
+		exit(ret);
 
 	if (!my_args.log_file)
 		my_args.log_file = "none";
 
 	if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
 			 my_args.progname, my_args.quiet, my_args.lxcpath[0]))
-		return ret;
+		exit(ret);
 	lxc_log_options_no_override();
 
 	if (print_info(my_args.name, my_args.lxcpath[0]) == 0)
 		ret = EXIT_SUCCESS;
 
-	return ret;
+	exit(ret);
 }
diff --git a/src/lxc/tools/lxc_monitor.c b/src/lxc/tools/lxc_monitor.c
index 797ae8b..ed36368 100644
--- a/src/lxc/tools/lxc_monitor.c
+++ b/src/lxc/tools/lxc_monitor.c
@@ -92,17 +92,17 @@ int main(int argc, char *argv[])
 	nfds_t nfds;
 	int len, rc_main, rc_snp, i;
 
-	rc_main = 0;
+	rc_main = EXIT_FAILURE;
 
 	if (lxc_arguments_parse(&my_args, argc, argv))
-		return 1;
+		exit(EXIT_FAILURE);
 
 	if (!my_args.log_file)
 		my_args.log_file = "none";
 
 	if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
 			 my_args.progname, my_args.quiet, my_args.lxcpath[0]))
-		return 1;
+		exit(EXIT_FAILURE);
 	lxc_log_options_no_override();
 
 	if (quit_monitord) {
@@ -124,32 +124,29 @@ int main(int argc, char *argv[])
 			}
 			close(fd);
 		}
-		return ret;
+		exit(ret);
 	}
 
 	len = strlen(my_args.name) + 3;
 	regexp = malloc(len + 3);
 	if (!regexp) {
 		ERROR("failed to allocate memory");
-		return 1;
+		exit(EXIT_FAILURE);
 	}
 	rc_snp = snprintf(regexp, len, "^%s$", my_args.name);
 	if (rc_snp < 0 || rc_snp >= len) {
 		ERROR("Name too long");
-		rc_main = 1;
 		goto error;
 	}
 
 	if (regcomp(&preg, regexp, REG_NOSUB|REG_EXTENDED)) {
 		ERROR("failed to compile the regex '%s'", my_args.name);
-		rc_main = 1;
 		goto error;
 	}
 
 	fds = malloc(my_args.lxcpath_cnt * sizeof(struct pollfd));
 	if (!fds) {
 		SYSERROR("out of memory");
-		rc_main = -1;
 		goto cleanup;
 	}
 
@@ -162,7 +159,6 @@ int main(int argc, char *argv[])
 		fd = lxc_monitor_open(my_args.lxcpath[i]);
 		if (fd < 0) {
 			close_fds(fds, i);
-			rc_main = 1;
 			goto cleanup;
 		}
 		fds[i].fd = fd;
@@ -174,7 +170,6 @@ int main(int argc, char *argv[])
 
 	for (;;) {
 		if (lxc_monitor_read_fdset(fds, nfds, &msg, -1) < 0) {
-			rc_main = 1;
 			goto close_and_clean;
 		}
 
@@ -196,6 +191,7 @@ int main(int argc, char *argv[])
 			break;
 		}
 	}
+	rc_main = 0;
 
 close_and_clean:
 	close_fds(fds, nfds);
@@ -207,5 +203,5 @@ int main(int argc, char *argv[])
 error:
 	free(regexp);
 
-	return rc_main;
+	exit(rc_main);
 }
diff --git a/src/lxc/tools/lxc_start.c b/src/lxc/tools/lxc_start.c
index 6b942ac..25d8f19 100644
--- a/src/lxc/tools/lxc_start.c
+++ b/src/lxc/tools/lxc_start.c
@@ -203,7 +203,7 @@ Options :\n\
 
 int main(int argc, char *argv[])
 {
-	int err = 1;
+	int err = EXIT_FAILURE;
 	struct lxc_conf *conf;
 	char *const *args;
 	char *rcfile = NULL;
@@ -216,10 +216,10 @@ int main(int argc, char *argv[])
 	lxc_list_init(&defines);
 
 	if (lxc_caps_init())
-		return err;
+		exit(err);
 
 	if (lxc_arguments_parse(&my_args, argc, argv))
-		return err;
+		exit(err);
 
 	if (!my_args.argc)
 		args = default_args;
@@ -228,7 +228,7 @@ int main(int argc, char *argv[])
 
 	if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
 			 my_args.progname, my_args.quiet, my_args.lxcpath[0]))
-		return err;
+		exit(err);
 	lxc_log_options_no_override();
 
 	const char *lxcpath = my_args.lxcpath[0];
@@ -245,13 +245,13 @@ int main(int argc, char *argv[])
 		c = lxc_container_new(my_args.name, lxcpath);
 		if (!c) {
 			ERROR("Failed to create lxc_container");
-			return err;
+			exit(err);
 		}
 		c->clear_config(c);
 		if (!c->load_config(c, rcfile)) {
 			ERROR("Failed to load rcfile");
 			lxc_container_put(c);
-			return err;
+			exit(err);
 		}
 	} else {
 		int rc;
@@ -259,7 +259,7 @@ int main(int argc, char *argv[])
 		rc = asprintf(&rcfile, "%s/%s/config", lxcpath, my_args.name);
 		if (rc == -1) {
 			SYSERROR("failed to allocate memory");
-			return err;
+			exit(err);
 		}
 		INFO("using rcfile %s", rcfile);
 
@@ -271,7 +271,7 @@ int main(int argc, char *argv[])
 		c = lxc_container_new(my_args.name, lxcpath);
 		if (!c) {
 			ERROR("Failed to create lxc_container");
-			return err;
+			exit(err);
 		}
 	}
 
@@ -336,9 +336,9 @@ int main(int argc, char *argv[])
 		c->want_close_all_fds(c, true);
 
 	if (args == default_args)
-		err = c->start(c, 0, NULL) ? 0 : 1;
+		err = c->start(c, 0, NULL) ? EXIT_SUCCESS : EXIT_FAILURE;
 	else
-		err = c->start(c, 0, args) ? 0 : 1;
+		err = c->start(c, 0, args) ? EXIT_SUCCESS : EXIT_FAILURE;
 
 	if (err) {
 		ERROR("The container failed to start.");
@@ -348,10 +348,10 @@ int main(int argc, char *argv[])
 		      "--logfile and --logpriority options.");
 		err = c->error_num;
 		lxc_container_put(c);
-		return err;
+		exit(err);
 	}
 
 out:
 	lxc_container_put(c);
-	return err;
+	exit(err);
 }
diff --git a/src/lxc/tools/lxc_stop.c b/src/lxc/tools/lxc_stop.c
index cb7cfe2..498aac1 100644
--- a/src/lxc/tools/lxc_stop.c
+++ b/src/lxc/tools/lxc_stop.c
@@ -143,14 +143,14 @@ int main(int argc, char *argv[])
 {
 	struct lxc_container *c;
 	bool s;
-	int ret = 1;
+	int ret = EXIT_FAILURE;
 
 	if (lxc_arguments_parse(&my_args, argc, argv))
-		return 1;
+		exit(ret);
 
 	if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
 			 my_args.progname, my_args.quiet, my_args.lxcpath[0]))
-		return 1;
+		exit(ret);
 	lxc_log_options_no_override();
 
 	/* Set default timeout */
@@ -170,33 +170,35 @@ int main(int argc, char *argv[])
 	/* some checks */
 	if (!my_args.hardstop && my_args.timeout < -1) {
 		fprintf(stderr, "invalid timeout\n");
-		return 1;
+		exit(ret);
 	}
 
 	if (my_args.hardstop && my_args.nokill) {
 		fprintf(stderr, "-k can't be used with --nokill\n");
-		return 1;
+		exit(ret);
 	}
 
 	if (my_args.hardstop && my_args.reboot) {
 		fprintf(stderr, "-k can't be used with -r\n");
-		return 1;
+		exit(ret);
 	}
 
 	if (my_args.hardstop && my_args.timeout) {
 		fprintf(stderr, "-k doesn't allow timeouts\n");
-		return 1;
+		exit(ret);
 	}
 
 	if (my_args.nolock && !my_args.hardstop) {
 		fprintf(stderr, "--nolock may only be used with -k\n");
-		return 1;
+		exit(ret);
 	}
 
 	/* shortcut - if locking is bogus, we should be able to kill
 	 * containers at least */
-	if (my_args.nolock)
-		return lxc_cmd_stop(my_args.name, my_args.lxcpath[0]);
+	if (my_args.nolock) {
+		ret = lxc_cmd_stop(my_args.name, my_args.lxcpath[0]);
+		exit(ret);
+	}
 
 	c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
 	if (!c) {
@@ -224,19 +226,19 @@ int main(int argc, char *argv[])
 
 	if (!c->is_running(c)) {
 		fprintf(stderr, "%s is not running\n", c->name);
-		ret = 2;
+		ret = EXIT_FAILURE;
 		goto out;
 	}
 
 	/* kill */
 	if (my_args.hardstop) {
-		ret = c->stop(c) ? 0 : 1;
+		ret = c->stop(c) ? EXIT_SUCCESS : EXIT_FAILURE;
 		goto out;
 	}
 
 	/* reboot */
 	if (my_args.reboot) {
-		ret = do_reboot_and_check(&my_args, c);
+		ret = do_reboot_and_check(&my_args, c) < 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 		goto out;
 	}
 
@@ -244,17 +246,16 @@ int main(int argc, char *argv[])
 	s = c->shutdown(c, my_args.timeout);
 	if (!s) {
 		if (my_args.timeout == 0)
-			ret = 0;
+			ret = EXIT_SUCCESS;
 		else if (my_args.nokill)
-			ret = 1;
+			ret = EXIT_FAILURE;
 		else
-			ret = c->stop(c) ? 0 : 1;
-	} else
-		ret = 0;
+			ret = c->stop(c) ? EXIT_SUCCESS : EXIT_FAILURE;
+	} else {
+		ret = EXIT_SUCCESS;
+	}
 
 out:
 	lxc_container_put(c);
-	if (ret < 0)
-		return 1;
-	return ret;
+	exit(ret);
 }
diff --git a/src/lxc/tools/lxc_top.c b/src/lxc/tools/lxc_top.c
index 47deddd..faeab33 100644
--- a/src/lxc/tools/lxc_top.c
+++ b/src/lxc/tools/lxc_top.c
@@ -506,5 +506,5 @@ int main(int argc, char *argv[])
 err1:
 	lxc_mainloop_close(&descr);
 out:
-	return ret;
+	exit(EXIT_FAILURE);
 }
diff --git a/src/lxc/tools/lxc_unfreeze.c b/src/lxc/tools/lxc_unfreeze.c
index 24faf5e..539654d 100644
--- a/src/lxc/tools/lxc_unfreeze.c
+++ b/src/lxc/tools/lxc_unfreeze.c
@@ -57,26 +57,26 @@ int main(int argc, char *argv[])
 	struct lxc_container *c;
 
 	if (lxc_arguments_parse(&my_args, argc, argv))
-		exit(1);
+		exit(EXIT_FAILURE);
 
 	if (!my_args.log_file)
 		my_args.log_file = "none";
 
 	if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
 			 my_args.progname, my_args.quiet, my_args.lxcpath[0]))
-		exit(1);
+		exit(EXIT_FAILURE);
 	lxc_log_options_no_override();
 
 	c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
 	if (!c) {
 		ERROR("No such container: %s:%s", my_args.lxcpath[0], my_args.name);
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 	if (!c->may_control(c)) {
 		ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
 		lxc_container_put(c);
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 	if (my_args.rcfile) {
@@ -84,23 +84,23 @@ int main(int argc, char *argv[])
 		if (!c->load_config(c, my_args.rcfile)) {
 			ERROR("Failed to load rcfile");
 			lxc_container_put(c);
-			exit(1);
+			exit(EXIT_FAILURE);
 		}
 		c->configfile = strdup(my_args.rcfile);
 		if (!c->configfile) {
 			ERROR("Out of memory setting new config filename");
 			lxc_container_put(c);
-			exit(1);
+			exit(EXIT_FAILURE);
 		}
 	}
 
 	if (!c->unfreeze(c)) {
 		ERROR("Failed to unfreeze %s:%s", my_args.lxcpath[0], my_args.name);
 		lxc_container_put(c);
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 	lxc_container_put(c);
 
-	exit(0);
+	exit(EXIT_SUCCESS);
 }
diff --git a/src/lxc/tools/lxc_unshare.c b/src/lxc/tools/lxc_unshare.c
index e629525..37f9d85 100644
--- a/src/lxc/tools/lxc_unshare.c
+++ b/src/lxc/tools/lxc_unshare.c
@@ -197,21 +197,21 @@ int main(int argc, char *argv[])
 			break;
 		case 'u':
 			if (!lookup_user(optarg, &uid))
-				return 1;
+				exit(EXIT_FAILURE);
 			start_arg.setuid = true;
 		}
 	}
 
 	if (argv[optind] == NULL) {
 		ERROR("a command to execute in the new namespace is required");
-		return 1;
+		exit(EXIT_FAILURE);
 	}
 
 	args = &argv[optind];
 
 	ret = lxc_caps_init();
 	if (ret)
-		return 1;
+		exit(EXIT_FAILURE);
 
 	ret = lxc_fill_namespace_flags(namespaces, &flags);
 	if (ret)
@@ -219,23 +219,23 @@ int main(int argc, char *argv[])
 
 	if (!(flags & CLONE_NEWNET) && my_iflist) {
 		ERROR("-i <interfacename> needs -s NETWORK option");
-		return 1;
+		exit(EXIT_FAILURE);
 	}
 
 	if (!(flags & CLONE_NEWUTS) && start_arg.want_hostname) {
 		ERROR("-H <hostname> needs -s UTSNAME option");
-		return 1;
+		exit(EXIT_FAILURE);
 	}
 
 	if (!(flags & CLONE_NEWNS) && start_arg.want_default_mounts) {
 		ERROR("-M needs -s MOUNT option");
-		return 1;
+		exit(EXIT_FAILURE);
 	}
 
 	pid = lxc_clone(do_start, &start_arg, flags);
 	if (pid < 0) {
 		ERROR("failed to clone");
-		return 1;
+		exit(EXIT_FAILURE);
 	}
 
 	if (my_iflist) {
@@ -250,8 +250,8 @@ int main(int argc, char *argv[])
 
 	if (waitpid(pid, &status, 0) < 0) {
 		ERROR("failed to wait for '%d'", pid);
-		return 1;
+		exit(EXIT_FAILURE);
 	}
 
-	return  lxc_error_set_and_log(pid, status);
+	exit(lxc_error_set_and_log(pid, status));
 }
diff --git a/src/lxc/tools/lxc_usernsexec.c b/src/lxc/tools/lxc_usernsexec.c
index 27d9cf5..16dd298 100644
--- a/src/lxc/tools/lxc_usernsexec.c
+++ b/src/lxc/tools/lxc_usernsexec.c
@@ -282,7 +282,7 @@ int main(int argc, char *argv[])
 		ret = readlink("/proc/self/fd/0", ttyname0, sizeof(ttyname0));
 		if (ret < 0) {
 			perror("unable to open stdin.");
-			exit(1);
+			exit(EXIT_FAILURE);
 		}
 		ret = readlink("/proc/self/fd/1", ttyname1, sizeof(ttyname1));
 		if (ret < 0) {
@@ -310,7 +310,7 @@ int main(int argc, char *argv[])
 	if (lxc_list_empty(&active_map)) {
 		if (find_default_map()) {
 			fprintf(stderr, "You have no allocated subuids or subgids\n");
-			exit(1);
+			exit(EXIT_FAILURE);
 		}
 	}
 
@@ -323,7 +323,7 @@ int main(int argc, char *argv[])
 
 	if (pipe(pipe1) < 0 || pipe(pipe2) < 0) {
 		perror("pipe");
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 	if ((pid = fork()) == 0) {
 		// Child.
@@ -342,15 +342,15 @@ int main(int argc, char *argv[])
 		buf[0] = '1';
 		if (write(pipe1[1], buf, 1) < 1) {
 			perror("write pipe");
-			exit(1);
+			exit(EXIT_FAILURE);
 		}
 		if (read(pipe2[0], buf, 1) < 1) {
 			perror("read pipe");
-			exit(1);
+			exit(EXIT_FAILURE);
 		}
 		if (buf[0] != '1') {
 			fprintf(stderr, "parent had an error, child exiting\n");
-			exit(1);
+			exit(EXIT_FAILURE);
 		}
 
 		close(pipe1[1]);
@@ -362,7 +362,7 @@ int main(int argc, char *argv[])
 	close(pipe2[0]);
 	if (read(pipe1[0], buf, 1) < 1) {
 		perror("read pipe");
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 	buf[0] = '1';
@@ -373,12 +373,12 @@ int main(int argc, char *argv[])
 	}
 	if (write(pipe2[1], buf, 1) < 0) {
 		perror("write to pipe");
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 	if ((ret = waitpid(pid, &status, __WALL)) < 0) {
 		printf("waitpid() returns %d, errno %d\n", ret, errno);
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 	exit(WEXITSTATUS(status));
diff --git a/src/lxc/tools/lxc_wait.c b/src/lxc/tools/lxc_wait.c
index 61fd869..de95696 100644
--- a/src/lxc/tools/lxc_wait.c
+++ b/src/lxc/tools/lxc_wait.c
@@ -85,24 +85,24 @@ int main(int argc, char *argv[])
 	struct lxc_container *c;
 
 	if (lxc_arguments_parse(&my_args, argc, argv))
-		return 1;
+		exit(EXIT_FAILURE);
 
 	if (!my_args.log_file)
 		my_args.log_file = "none";
 
 	if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
 			 my_args.progname, my_args.quiet, my_args.lxcpath[0]))
-		return 1;
+		exit(EXIT_FAILURE);
 	lxc_log_options_no_override();
 
 	c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
 	if (!c)
-		return 1;
+		exit(EXIT_FAILURE);
 
 	if (!c->may_control(c)) {
 		fprintf(stderr, "Insufficent privileges to control %s\n", c->name);
 		lxc_container_put(c);
-		return 1;
+		exit(EXIT_FAILURE);
 	}
 
 	if (my_args.rcfile) {
@@ -110,19 +110,19 @@ int main(int argc, char *argv[])
 		if (!c->load_config(c, my_args.rcfile)) {
 			fprintf(stderr, "Failed to load rcfile\n");
 			lxc_container_put(c);
-			return 1;
+			exit(EXIT_FAILURE);
 		}
 		c->configfile = strdup(my_args.rcfile);
 		if (!c->configfile) {
 			fprintf(stderr, "Out of memory setting new config filename\n");
 			lxc_container_put(c);
-			return 1;
+			exit(EXIT_FAILURE);
 		}
 	}
 
 	if (!c->wait(c, my_args.states, my_args.timeout)) {
 		lxc_container_put(c);
-		return 1;
+		exit(EXIT_FAILURE);
 	}
-	return 0;
+	exit(EXIT_SUCCESS);
 }


More information about the lxc-devel mailing list