tree-wide: use EXIT_SUCCESS/EXIT_FAILURE in exit() where we can

This commit is contained in:
Lennart Poettering 2017-12-22 13:24:40 +01:00
parent d00c263143
commit a45d7127e7
12 changed files with 31 additions and 15 deletions

16
coccinelle/exit-0.cocci Normal file
View File

@ -0,0 +1,16 @@
@@
@@
- exit(0);
+ exit(EXIT_SUCCESS);
@@
@@
- _exit(0);
+ _exit(EXIT_SUCCESS);
@@
@@
- exit(1);
+ exit(EXIT_FAILURE);
@@
@@
- _exit(1);
+ _exit(EXIT_FAILURE);

View 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
}

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

View 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);

View File

@ -319,7 +319,7 @@ int main(int argc, char *argv[]) {
break;
}
_exit(0);
_exit(EXIT_SUCCESS);
}
CPU_ZERO(&cpuset);

View 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);

View 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);

View 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);
}
}

View 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;

View 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();

View 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;

View 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.");