chiark / gitweb /
dbus: to make sure that systemd stays controllable during early bootup, register...
[elogind.git] / src / systemctl.c
index 447a24458adc31071c6189365851e82ec9c2b09c..429d6a7a21440cf5bb13c55f0140428da36ef32c 100644 (file)
@@ -39,6 +39,7 @@
 #include "utmp-wtmp.h"
 #include "special.h"
 #include "initreq.h"
+#include "strv.h"
 
 static const char *arg_type = NULL;
 static bool arg_all = false;
@@ -139,6 +140,23 @@ static void warn_wall(enum action action) {
         if (arg_no_wall)
                 return;
 
+        if (arg_wall) {
+                char *p;
+
+                if (!(p = strv_join(arg_wall, " "))) {
+                        log_error("Failed to join strings.");
+                        return;
+                }
+
+                if (*p) {
+                        utmp_wall(p);
+                        free(p);
+                        return;
+                }
+
+                free(p);
+        }
+
         if (!table[action])
                 return;
 
@@ -1447,7 +1465,7 @@ static int halt_help(void) {
 
 static int shutdown_help(void) {
 
-        printf("%s [options] [IGNORED] [WALL...]\n\n"
+        printf("%s [options] [now] [WALL...]\n\n"
                "Shut down the system.\n\n"
                "     --help      Show this help\n"
                "  -H --halt      Halt the machine\n"
@@ -1723,6 +1741,9 @@ static int shutdown_parse_argv(int argc, char *argv[]) {
                 }
         }
 
+        if (argc > optind && !streq(argv[optind], "now"))
+                log_warning("First argument '%s' isn't 'now'. Ignoring.", argv[optind]);
+
         /* We ignore the time argument */
         if (argc > optind + 1)
                 arg_wall = argv + optind + 1;
@@ -1730,7 +1751,6 @@ static int shutdown_parse_argv(int argc, char *argv[]) {
         optind = argc;
 
         return 1;
-
 }
 
 static int telinit_parse_argv(int argc, char *argv[]) {
@@ -2241,7 +2261,13 @@ int main(int argc, char*argv[]) {
                 goto finish;
         }
 
-        if ((bus = dbus_bus_get(arg_session ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &error)))
+        /* If we are root, then let's not go via the bus */
+        if (geteuid() == 0 && !arg_session)
+                bus = dbus_connection_open("unix:abstract=/org/freedesktop/systemd1/private", &error);
+        else
+                bus = dbus_bus_get(arg_session ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &error);
+
+        if (bus)
                 dbus_connection_set_exit_on_disconnect(bus, FALSE);
 
         switch (arg_action) {