Commit 22f4096c authored by Lennart Poettering's avatar Lennart Poettering

systemctl: rework exit codes for all utility programs to follow LSB or other standards

parent f73e33d9
......@@ -78,11 +78,7 @@ v9:
* MTA IS KAPUTT
* kill-mode=cgroup muss auch die mainpid killen! https://bugzilla.redhat.com/show_bug.cgi?id=626477
* follow LSB exit codes spec in "systemctl start"
* systemctl wrapping https://bugzilla.redhat.com/show_bug.cgi?id=626891 https://bugzilla.redhat.com/show_bug.cgi?id=626443
* fix terminal setup
External:
......
......@@ -72,7 +72,7 @@ static int parse_argv(int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {
int r = 0, retval = 1;
int r = 0, retval = EXIT_FAILURE;
log_parse_environment();
log_open();
......@@ -80,7 +80,7 @@ int main(int argc, char *argv[]) {
if ((r = parse_argv(argc, argv)) < 0)
goto finish;
else if (r == 0) {
retval = 0;
retval = EXIT_SUCCESS;
goto finish;
}
......@@ -115,7 +115,7 @@ int main(int argc, char *argv[]) {
if (r < 0)
log_error("Failed to list cgroup tree: %s", strerror(-r));
retval = 0;
retval = EXIT_SUCCESS;
finish:
......
......@@ -21,6 +21,8 @@
#include <dbus/dbus.h>
#include <stdlib.h>
#include "log.h"
#include "dbus-common.h"
......@@ -28,7 +30,7 @@ int main(int argc, char *argv[]) {
DBusError error;
DBusConnection *bus = NULL;
DBusMessage *m = NULL;
int r = 1;
int r = EXIT_FAILURE;
dbus_error_init(&error);
......@@ -76,7 +78,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
r = 0;
r = EXIT_SUCCESS;
finish:
if (bus) {
......
......@@ -335,16 +335,16 @@ static int process_event(Server *s, struct epoll_event *ev) {
int main(int argc, char *argv[]) {
Server server;
int r = 3, n;
int r = EXIT_FAILURE, n;
if (getppid() != 1) {
log_error("This program should be invoked by init only.");
return 1;
return EXIT_FAILURE;
}
if (argc > 1) {
log_error("This program does not take arguments.");
return 1;
return EXIT_FAILURE;
}
log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
......@@ -353,16 +353,16 @@ int main(int argc, char *argv[]) {
if ((n = sd_listen_fds(true)) < 0) {
log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
return 1;
return EXIT_FAILURE;
}
if (n <= 0 || n > SERVER_FD_MAX) {
log_error("No or too many file descriptors passed.");
return 2;
return EXIT_FAILURE;
}
if (server_init(&server, (unsigned) n) < 0)
return 2;
return EXIT_FAILURE;
log_debug("systemd-initctl running as pid %lu", (unsigned long) getpid());
......@@ -392,7 +392,7 @@ int main(int argc, char *argv[]) {
goto fail;
}
r = 0;
r = EXIT_SUCCESS;
log_debug("systemd-initctl stopped as pid %lu", (unsigned long) getpid());
......
......@@ -473,16 +473,16 @@ static int process_event(Server *s, struct epoll_event *ev) {
int main(int argc, char *argv[]) {
Server server;
int r = 3, n;
int r = EXIT_FAILURE, n;
if (getppid() != 1) {
log_error("This program should be invoked by init only.");
return 1;
return EXIT_FAILURE;
}
if (argc > 1) {
log_error("This program does not take arguments.");
return 1;
return EXIT_FAILURE;
}
log_set_target(LOG_TARGET_KMSG);
......@@ -491,16 +491,16 @@ int main(int argc, char *argv[]) {
if ((n = sd_listen_fds(true)) < 0) {
log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
return 1;
return EXIT_FAILURE;
}
if (n <= 0 || n > SERVER_FD_MAX) {
log_error("No or too many file descriptors passed.");
return 2;
return EXIT_FAILURE;
}
if (server_init(&server, (unsigned) n) < 0)
return 3;
return EXIT_FAILURE;
log_debug("systemd-kmsg-syslogd running as pid %lu", (unsigned long) getpid());
......@@ -531,7 +531,7 @@ int main(int argc, char *argv[]) {
break;
}
r = 0;
r = EXIT_SUCCESS;
log_debug("systemd-kmsg-syslogd stopped as pid %lu", (unsigned long) getpid());
......
......@@ -557,16 +557,16 @@ static int process_event(Server *s, struct epoll_event *ev) {
int main(int argc, char *argv[]) {
Server server;
int r = 3, n;
int r = EXIT_FAILURE, n;
if (getppid() != 1) {
log_error("This program should be invoked by init only.");
return 1;
return EXIT_FAILURE;
}
if (argc > 1) {
log_error("This program does not take arguments.");
return 1;
return EXIT_FAILURE;
}
log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
......@@ -575,16 +575,16 @@ int main(int argc, char *argv[]) {
if ((n = sd_listen_fds(true)) < 0) {
log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
return 1;
return EXIT_FAILURE;
}
if (n <= 0 || n > SERVER_FD_MAX) {
log_error("No or too many file descriptors passed.");
return 2;
return EXIT_FAILURE;
}
if (server_init(&server, (unsigned) n) < 0)
return 3;
return EXIT_FAILURE;
log_debug("systemd-logger running as pid %lu", (unsigned long) getpid());
......@@ -614,7 +614,7 @@ int main(int argc, char *argv[]) {
goto fail;
}
r = 0;
r = EXIT_SUCCESS;
log_debug("systemd-logger stopped as pid %lu", (unsigned long) getpid());
......
......@@ -876,7 +876,7 @@ fail:
int main(int argc, char *argv[]) {
Manager *m = NULL;
int r, retval = 1;
int r, retval = EXIT_FAILURE;
FDSet *fds = NULL;
bool reexecute = false;
......@@ -937,10 +937,10 @@ int main(int argc, char *argv[]) {
goto finish;
} else if (arg_action == ACTION_DUMP_CONFIGURATION_ITEMS) {
unit_dump_config_items(stdout);
retval = 0;
retval = EXIT_SUCCESS;
goto finish;
} else if (arg_action == ACTION_DONE) {
retval = 0;
retval = EXIT_SUCCESS;
goto finish;
}
......@@ -1072,7 +1072,7 @@ int main(int argc, char *argv[]) {
if (arg_action == ACTION_TEST) {
printf("-> By jobs:\n");
manager_dump_jobs(m, stdout, "\t");
retval = 0;
retval = EXIT_SUCCESS;
goto finish;
}
}
......@@ -1086,7 +1086,7 @@ int main(int argc, char *argv[]) {
switch (m->exit_code) {
case MANAGER_EXIT:
retval = 0;
retval = EXIT_SUCCESS;
log_debug("Exit.");
goto finish;
......
......@@ -51,13 +51,13 @@ static int scandir_filter(const struct dirent *d) {
int main(int argc, char *argv[]) {
struct dirent **de = NULL;
int r = 1, n, i;
int r = EXIT_FAILURE, n, i;
char **arguments = NULL;
unsigned n_arguments = 0, n_allocated = 0;
if (argc > 1) {
log_error("This program takes no argument.");
return 1;
return EXIT_FAILURE;
}
log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
......@@ -74,14 +74,14 @@ int main(int argc, char *argv[]) {
if ((n = scandir("/etc/modules.d/", &de, scandir_filter, alphasort)) < 0) {
if (errno == ENOENT)
r = 0;
r = EXIT_SUCCESS;
else
log_error("Failed to enumerate /etc/modules.d/ files: %m");
goto finish;
}
r = 0;
r = EXIT_SUCCESS;
for (i = 0; i < n; i++) {
int k;
......@@ -93,7 +93,7 @@ int main(int argc, char *argv[]) {
if (k < 0) {
log_error("Failed to allocate file name.");
r = 1;
r = EXIT_FAILURE;
continue;
}
......@@ -102,7 +102,7 @@ int main(int argc, char *argv[]) {
if (!f) {
log_error("Failed to open %s: %m", fn);
r = 1;
r = EXIT_FAILURE;
continue;
}
......@@ -130,7 +130,7 @@ int main(int argc, char *argv[]) {
if (!(a = realloc(arguments, sizeof(char*) * (m+1)))) {
log_error("Failed to increase module array size.");
free(t);
r = 1;
r = EXIT_FAILURE;
continue;
}
......@@ -142,7 +142,7 @@ int main(int argc, char *argv[]) {
}
if (ferror(f)) {
r = 1;
r = EXIT_FAILURE;
log_error("Failed to read from file: %m");
}
......@@ -158,7 +158,7 @@ finish:
execv("/sbin/modprobe", arguments);
log_error("Failed to execute /sbin/modprobe: %m");
r = 1;
r = EXIT_FAILURE;
}
strv_free(arguments);
......
......@@ -131,13 +131,13 @@ int main(int argc, char* argv[]) {
char* our_env[4], **final_env = NULL;
unsigned i = 0;
char *status = NULL, *cpid = NULL, *n = NULL;
int r, retval = 1;
int r, retval = EXIT_FAILURE;
log_parse_environment();
log_open();
if ((r = parse_argv(argc, argv)) <= 0) {
retval = r < 0;
retval = r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
goto finish;
}
......@@ -173,7 +173,7 @@ int main(int argc, char* argv[]) {
}
if (strv_length(final_env) <= 0) {
retval = 0;
retval = EXIT_SUCCESS;
goto finish;
}
......@@ -187,7 +187,7 @@ int main(int argc, char* argv[]) {
goto finish;
}
retval = r <= 0;
retval = r <= 0 ? EXIT_FAILURE : EXIT_SUCCESS;
finish:
free(status);
......
......@@ -32,7 +32,7 @@
int main(int argc, char *argv[]) {
int seed_fd = -1, random_fd = -1;
int ret = 1;
int ret = EXIT_FAILURE;
void* buf;
size_t buf_size = 0;
ssize_t r;
......@@ -40,7 +40,7 @@ int main(int argc, char *argv[]) {
if (argc != 2) {
log_error("This program requires one argument.");
return 1;
return EXIT_FAILURE;
}
log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
......@@ -119,7 +119,7 @@ int main(int argc, char *argv[]) {
log_error("Failed to write new random seed file: %s", r < 0 ? strerror(errno) : "short write");
}
ret = 0;
ret = EXIT_SUCCESS;
finish:
if (random_fd >= 0)
......
......@@ -37,14 +37,14 @@
* respected */
int main(int argc, char *argv[]) {
int ret = 1;
int ret = EXIT_FAILURE;
FILE *f = NULL;
struct mntent* me;
Hashmap *pids = NULL;
if (argc > 1) {
log_error("This program takes no argument.");
return 1;
return EXIT_FAILURE;
}
log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
......@@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
ret = 0;
ret = EXIT_SUCCESS;
while ((me = getmntent(f))) {
pid_t pid;
......@@ -92,7 +92,7 @@ int main(int argc, char *argv[]) {
execv("/bin/mount", (char **) arguments);
log_error("Failed to execute /bin/mount: %m");
_exit(1);
_exit(EXIT_FAILURE);
}
/* Parent */
......@@ -101,7 +101,7 @@ int main(int argc, char *argv[]) {
if ((k = hashmap_put(pids, UINT_TO_PTR(pid), s)) < 0) {
log_error("Failed to add PID to set: %s", strerror(-k));
ret = 1;
ret = EXIT_FAILURE;
continue;
}
}
......@@ -117,7 +117,7 @@ int main(int argc, char *argv[]) {
continue;
log_error("waitid() failed: %m");
ret = 1;
ret = EXIT_FAILURE;
break;
}
......@@ -128,7 +128,7 @@ int main(int argc, char *argv[]) {
else
log_error("/bin/mount for %s terminated by signal %s.", s, signal_to_string(si.si_status));
ret = 1;
ret = EXIT_FAILURE;
}
free(s);
......
......@@ -176,7 +176,7 @@ int main(int argc, char *argv[]) {
_FD_MAX
};
int r = 4, n_fds;
int r = EXIT_FAILURE, n_fds;
int one = 1;
struct shutdownd_command c;
struct pollfd pollfd[_FD_MAX];
......@@ -185,12 +185,12 @@ int main(int argc, char *argv[]) {
if (getppid() != 1) {
log_error("This program should be invoked by init only.");
return 1;
return EXIT_FAILURE;
}
if (argc > 1) {
log_error("This program does not take arguments.");
return 1;
return EXIT_FAILURE;
}
log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
......@@ -199,17 +199,17 @@ int main(int argc, char *argv[]) {
if ((n_fds = sd_listen_fds(true)) < 0) {
log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
return 1;
return EXIT_FAILURE;
}
if (n_fds != 1) {
log_error("Need exactly one file descriptor.");
return 2;
return EXIT_FAILURE;
}
if (setsockopt(SD_LISTEN_FDS_START, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)) < 0) {
log_error("SO_PASSCRED failed: %m");
return 3;
return EXIT_FAILURE;
}
zero(c);
......@@ -335,7 +335,7 @@ int main(int argc, char *argv[]) {
} while (c.elapse > 0);
r = 0;
r = EXIT_SUCCESS;
log_debug("systemd-shutdownd stopped as pid %lu", (unsigned long) getpid());
......
This diff is collapsed.
......@@ -361,12 +361,12 @@ int main(int argc, char *argv[]) {
if (getppid() != 1) {
log_error("This program should be invoked by init only.");
return 1;
return EXIT_FAILURE;
}
if (argc != 2) {
log_error("This program requires one argument.");
return 1;
return EXIT_FAILURE;
}
log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
......@@ -413,5 +413,5 @@ finish:
dbus_error_free(&error);
dbus_shutdown();
return r < 0 ? 1 : 0;
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment