chiark / gitweb /
units: fix logger/initctl paths
[elogind.git] / initctl.c
index a4356759c2e03fcb1e67c83a9a6599efcb38bb28..a13aed34c2c8b715e4d230317b071a8bf704d4cd 100644 (file)
--- a/initctl.c
+++ b/initctl.c
@@ -39,6 +39,7 @@
 #include "log.h"
 #include "list.h"
 #include "initreq.h"
+#include "manager.h"
 
 #define SERVER_FD_START 3
 #define SERVER_FD_MAX 16
@@ -67,42 +68,35 @@ struct Fifo {
 };
 
 static const char *translate_runlevel(int runlevel) {
+        static const struct {
+                const int runlevel;
+                const char *special;
+        } table[] = {
+                { '0', SPECIAL_RUNLEVEL0_TARGET },
+                { '1', SPECIAL_RUNLEVEL1_TARGET },
+                { 's', SPECIAL_RUNLEVEL1_TARGET },
+                { 'S', SPECIAL_RUNLEVEL1_TARGET },
+                { '2', SPECIAL_RUNLEVEL2_TARGET },
+                { '3', SPECIAL_RUNLEVEL3_TARGET },
+                { '4', SPECIAL_RUNLEVEL4_TARGET },
+                { '5', SPECIAL_RUNLEVEL5_TARGET },
+                { '6', SPECIAL_RUNLEVEL6_TARGET },
+        };
 
-        switch (runlevel) {
-
-        case '0':
-                return "halt.target";
-
-        case '1':
-        case 's':
-        case 'S':
-                return "rescue.target";
-
-        case '2':
-                return "runlevel2.target";
-
-        case '3':
-                return "runlevel3.target";
-
-        case '4':
-                return "runlevel4.target";
-
-        case '5':
-                return "runlevel5.target";
+        unsigned i;
 
-        case '6':
-                return "reboot.target";
+        for (i = 0; i < ELEMENTSOF(table); i++)
+                if (table[i].runlevel == runlevel)
+                        return table[i].special;
 
-        default:
-                return NULL;
-        }
+        return NULL;
 }
 
 static void change_runlevel(Server *s, int runlevel) {
         const char *target;
         DBusMessage *m = NULL, *reply = NULL;
         DBusError error;
-        const char *path, *replace = "replace";
+        const char *path, *replace = "isolate";
 
         assert(s);
 
@@ -115,7 +109,7 @@ static void change_runlevel(Server *s, int runlevel) {
 
         log_debug("Running request %s", target);
 
-        if (!(m = dbus_message_new_method_call("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1", "GetUnit"))) {
+        if (!(m = dbus_message_new_method_call("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "GetUnit"))) {
                 log_error("Could not allocate message.");
                 goto finish;
         }
@@ -246,7 +240,7 @@ static void fifo_free(Fifo *f) {
                 if (f->server)
                         epoll_ctl(f->server->epoll_fd, EPOLL_CTL_DEL, f->fd, NULL);
 
-                assert_se(close_nointr(f->fd) == 0);
+                close_nointr_nofail(f->fd);
         }
 
         free(f);
@@ -302,7 +296,7 @@ static void server_done(Server *s) {
                 fifo_free(s->fifos);
 
         if (s->epoll_fd >= 0)
-                assert_se(close_nointr(s->epoll_fd) == 0);
+                close_nointr_nofail(s->epoll_fd);
 
         if (s->bus)
                 dbus_connection_unref(s->bus);