chiark / gitweb /
everywhere: remove configurability of sysv runlevel to target mapping
[elogind.git] / src / initctl / initctl.c
index f9613ea3b1fe282ab2f1f67e85cea28b564d15fc..8b632e88aeaf64870c92f9614f8c557c157431a2 100644 (file)
@@ -27,7 +27,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
-#include <sys/poll.h>
+#include <poll.h>
 #include <sys/epoll.h>
 #include <sys/un.h>
 #include <fcntl.h>
@@ -78,15 +78,15 @@ static const char *translate_runlevel(int runlevel, bool *isolate) {
                 const char *special;
                 bool isolate;
         } table[] = {
-                { '0', SPECIAL_POWEROFF_TARGET,  false },
-                { '1', SPECIAL_RESCUE_TARGET,    true  },
-                { 's', SPECIAL_RESCUE_TARGET,    true  },
-                { 'S', SPECIAL_RESCUE_TARGET,    true  },
-                { '2', SPECIAL_RUNLEVEL2_TARGET, true  },
-                { '3', SPECIAL_RUNLEVEL3_TARGET, true  },
-                { '4', SPECIAL_RUNLEVEL4_TARGET, true  },
-                { '5', SPECIAL_RUNLEVEL5_TARGET, true  },
-                { '6', SPECIAL_REBOOT_TARGET,    false },
+                { '0', SPECIAL_POWEROFF_TARGET,   false },
+                { '1', SPECIAL_RESCUE_TARGET,     true  },
+                { 's', SPECIAL_RESCUE_TARGET,     true  },
+                { 'S', SPECIAL_RESCUE_TARGET,     true  },
+                { '2', SPECIAL_MULTI_USER_TARGET, true  },
+                { '3', SPECIAL_MULTI_USER_TARGET, true  },
+                { '4', SPECIAL_MULTI_USER_TARGET, true  },
+                { '5', SPECIAL_GRAPHICAL_TARGET,  true  },
+                { '6', SPECIAL_REBOOT_TARGET,     false },
         };
 
         unsigned i;
@@ -162,7 +162,7 @@ static void request_process(Server *s, const struct init_request *req) {
                         case 'u':
                         case 'U':
                                 if (kill(1, SIGTERM) < 0)
-                                        log_error("kill() failed: %m");
+                                        log_error_errno(errno, "kill() failed: %m");
 
                                 /* The bus connection will be
                                  * terminated if PID 1 is reexecuted,
@@ -175,7 +175,7 @@ static void request_process(Server *s, const struct init_request *req) {
                         case 'q':
                         case 'Q':
                                 if (kill(1, SIGHUP) < 0)
-                                        log_error("kill() failed: %m");
+                                        log_error_errno(errno, "kill() failed: %m");
                                 break;
 
                         default:
@@ -217,8 +217,8 @@ static int fifo_process(Fifo *f) {
                 if (errno == EAGAIN)
                         return 0;
 
-                log_warning("Failed to read from fifo: %m");
-                return -1;
+                log_warning_errno(errno, "Failed to read from fifo: %m");
+                return -errno;
         }
 
         f->bytes_read += l;
@@ -277,7 +277,7 @@ static int server_init(Server *s, unsigned n_sockets) {
         s->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
         if (s->epoll_fd < 0) {
                 r = -errno;
-                log_error("Failed to create epoll object: %m");
+                log_error_errno(errno, "Failed to create epoll object: %m");
                 goto fail;
         }
 
@@ -290,8 +290,7 @@ static int server_init(Server *s, unsigned n_sockets) {
 
                 r = sd_is_fifo(fd, NULL);
                 if (r < 0) {
-                        log_error("Failed to determine file descriptor type: %s",
-                                  strerror(-r));
+                        log_error_errno(r, "Failed to determine file descriptor type: %m");
                         goto fail;
                 }
 
@@ -304,7 +303,7 @@ static int server_init(Server *s, unsigned n_sockets) {
                 f = new0(Fifo, 1);
                 if (!f) {
                         r = -ENOMEM;
-                        log_error("Failed to create fifo object: %m");
+                        log_error_errno(errno, "Failed to create fifo object: %m");
                         goto fail;
                 }
 
@@ -316,7 +315,7 @@ static int server_init(Server *s, unsigned n_sockets) {
                 if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0) {
                         r = -errno;
                         fifo_free(f);
-                        log_error("Failed to add fifo fd to epoll object: %m");
+                        log_error_errno(errno, "Failed to add fifo fd to epoll object: %m");
                         goto fail;
                 }
 
@@ -328,7 +327,7 @@ static int server_init(Server *s, unsigned n_sockets) {
 
         r = bus_open_system_systemd(&s->bus);
         if (r < 0) {
-                log_error("Failed to get D-Bus connection: %s", strerror(-r));
+                log_error_errno(r, "Failed to get D-Bus connection: %m");
                 r = -EIO;
                 goto fail;
         }
@@ -355,7 +354,7 @@ static int process_event(Server *s, struct epoll_event *ev) {
         f = (Fifo*) ev->data.ptr;
         r = fifo_process(f);
         if (r < 0) {
-                log_info("Got error on fifo: %s", strerror(-r));
+                log_info_errno(r, "Got error on fifo: %m");
                 fifo_free(f);
                 return r;
         }
@@ -383,8 +382,9 @@ int main(int argc, char *argv[]) {
 
         umask(0022);
 
-        if ((n = sd_listen_fds(true)) < 0) {
-                log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
+        n = sd_listen_fds(true);
+        if (n < 0) {
+                log_error_errno(r, "Failed to read listening file descriptors from environment: %m");
                 return EXIT_FAILURE;
         }
 
@@ -396,7 +396,7 @@ int main(int argc, char *argv[]) {
         if (server_init(&server, (unsigned) n) < 0)
                 return EXIT_FAILURE;
 
-        log_debug("systemd-initctl running as pid %lu", (unsigned long) getpid());
+        log_debug("systemd-initctl running as pid "PID_FMT, getpid());
 
         sd_notify(false,
                   "READY=1\n"
@@ -413,7 +413,7 @@ int main(int argc, char *argv[]) {
                         if (errno == EINTR)
                                 continue;
 
-                        log_error("epoll_wait() failed: %m");
+                        log_error_errno(errno, "epoll_wait() failed: %m");
                         goto fail;
                 }
 
@@ -426,10 +426,11 @@ int main(int argc, char *argv[]) {
 
         r = EXIT_SUCCESS;
 
-        log_debug("systemd-initctl stopped as pid %lu", (unsigned long) getpid());
+        log_debug("systemd-initctl stopped as pid "PID_FMT, getpid());
 
 fail:
         sd_notify(false,
+                  "STOPPING=1\n"
                   "STATUS=Shutting down...");
 
         server_done(&server);