tree-wide: use EXIT_SUCCESS/EXIT_FAILURE in exit() where we can
authorLennart Poettering <lennart@poettering.net>
Fri, 22 Dec 2017 12:24:40 +0000 (13:24 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 25 Dec 2017 10:48:21 +0000 (11:48 +0100)
12 files changed:
coccinelle/exit-0.cocci [new file with mode: 0644]
src/core/main.c
src/core/shutdown.c
src/coredump/coredumpctl.c
src/libsystemd/sd-bus/test-bus-benchmark.c
src/libsystemd/sd-event/test-event.c
src/quotacheck/quotacheck.c
src/shared/tests.c
src/test/test-capability.c
src/test/test-process-util.c
src/udev/mtd_probe/probe_smartmedia.c
src/udev/scsi_id/scsi_id.c

diff --git a/coccinelle/exit-0.cocci b/coccinelle/exit-0.cocci
new file mode 100644 (file)
index 0000000..8b81600
--- /dev/null
@@ -0,0 +1,16 @@
+@@
+@@
+- exit(0);
++ exit(EXIT_SUCCESS);
+@@
+@@
+- _exit(0);
++ _exit(EXIT_SUCCESS);
+@@
+@@
+- exit(1);
++ exit(EXIT_FAILURE);
+@@
+@@
+- _exit(1);
++ _exit(EXIT_FAILURE);
index c717473..66c2101 100644 (file)
@@ -1457,7 +1457,7 @@ static void redirect_telinit(int argc, char *argv[]) {
 
         execv(SYSTEMCTL_BINARY_PATH, argv);
         log_error_errno(errno, "Failed to exec " SYSTEMCTL_BINARY_PATH ": %m");
-        exit(1);
+        exit(EXIT_FAILURE);
 #endif
 }
 
index 877f882..efcc264 100644 (file)
@@ -544,7 +544,7 @@ int main(int argc, char *argv[]) {
                  * CAP_SYS_BOOT just exit, this will kill our
                  * container for good. */
                 log_info("Exiting container.");
-                exit(0);
+                exit(EXIT_SUCCESS);
         }
 
         r = log_error_errno(errno, "Failed to invoke reboot(): %m");
index 5013758..a3f86aa 100644 (file)
@@ -936,7 +936,7 @@ static int run_gdb(sd_journal *j) {
         if (r == 0) {
                 execlp("gdb", "gdb", exe, path, NULL);
                 log_error_errno(errno, "Failed to invoke gdb: %m");
-                _exit(1);
+                _exit(EXIT_FAILURE);
         }
 
         r = wait_for_terminate(pid, &st);
index a466cdd..bfd0f39 100644 (file)
@@ -319,7 +319,7 @@ int main(int argc, char *argv[]) {
                         break;
                 }
 
-                _exit(0);
+                _exit(EXIT_SUCCESS);
         }
 
         CPU_ZERO(&cpuset);
index 7f32838..87a0c85 100644 (file)
@@ -97,7 +97,7 @@ static int signal_handler(sd_event_source *s, const struct signalfd_siginfo *si,
         assert_se(pid >= 0);
 
         if (pid == 0)
-                _exit(0);
+                _exit(EXIT_SUCCESS);
 
         assert_se(sd_event_add_child(sd_event_source_get_event(s), &p, pid, WEXITED, child_handler, INT_TO_PTR('f')) >= 0);
         assert_se(sd_event_source_set_enabled(p, SD_EVENT_ONESHOT) >= 0);
index b5636e6..cd44167 100644 (file)
@@ -116,7 +116,7 @@ int main(int argc, char *argv[]) {
                 /* Child */
 
                 execv(cmdline[0], (char**) cmdline);
-                _exit(1); /* Operational error */
+                _exit(EXIT_FAILURE); /* Operational error */
         }
 
         r = wait_for_terminate_and_warn("quotacheck", pid, true);
index d78ab7b..d4781ac 100644 (file)
@@ -48,7 +48,7 @@ const char* get_testdata_dir(const char *suffix) {
         if (env) {
                 if (access(env, F_OK) < 0) {
                         fputs("ERROR: $SYSTEMD_TEST_DATA directory does not exist\n", stderr);
-                        exit(1);
+                        exit(EXIT_FAILURE);
                 }
                 strncpy(testdir, env, sizeof(testdir) - 1);
         } else {
@@ -65,7 +65,7 @@ const char* get_testdata_dir(const char *suffix) {
                 /* test this without the suffix, as it may contain a glob */
                 if (access(testdir, F_OK) < 0) {
                         fputs("ERROR: Cannot find testdata directory, set $SYSTEMD_TEST_DATA\n", stderr);
-                        exit(1);
+                        exit(EXIT_FAILURE);
                 }
         }
 
index e5db52d..10cddaf 100644 (file)
@@ -80,7 +80,7 @@ static void fork_test(void (*test_func)(void)) {
         assert_se(pid >= 0);
         if (pid == 0) {
                 test_func();
-                exit(0);
+                exit(EXIT_SUCCESS);
         } else if (pid > 0) {
                 int status;
 
index 2e262dd..c2debf6 100644 (file)
@@ -354,7 +354,7 @@ static void test_get_process_cmdline_harder(void) {
         line = mfree(line);
 
         safe_close(fd);
-        _exit(0);
+        _exit(EXIT_SUCCESS);
 }
 
 static void test_rename_process_now(const char *p, int ret) {
@@ -463,7 +463,7 @@ static void test_getpid_cached(void) {
                 c = getpid();
 
                 assert_se(a == b && a == c);
-                _exit(0);
+                _exit(EXIT_SUCCESS);
         }
 
         d = raw_getpid();
index eb74fe1..8980ebf 100644 (file)
@@ -90,7 +90,7 @@ void probe_smart_media(int mtd_fd, mtd_info_t* info)
 
         printf("MTD_FTL=smartmedia\n");
         free(cis_buffer);
-        exit(0);
+        exit(EXIT_SUCCESS);
 exit:
         free(cis_buffer);
         return;
index ab4ee7b..32c1a8d 100644 (file)
@@ -358,7 +358,7 @@ static int set_options(struct udev *udev,
 
                 case 'h':
                         help();
-                        exit(0);
+                        exit(EXIT_SUCCESS);
 
                 case 'p':
                         if (streq(optarg, "0x80"))
@@ -393,7 +393,7 @@ static int set_options(struct udev *udev,
 
                 case 'V':
                         printf("%s\n", PACKAGE_VERSION);
-                        exit(0);
+                        exit(EXIT_SUCCESS);
 
                 case 'x':
                         export = true;
@@ -608,7 +608,7 @@ int main(int argc, char **argv)
          * Get command line options (overriding any config file settings).
          */
         if (set_options(udev, argc, argv, maj_min_dev) < 0)
-                exit(1);
+                exit(EXIT_FAILURE);
 
         if (!dev_specified) {
                 log_error("No device specified.");