chiark / gitweb /
units: start logger only after syslog is up
[elogind.git] / src / systemctl.c
index 41aea093cd01621d0027467a9b3c57666b0f2b15..627b9055aeb9f71eb020568b83db2b0a04fd0d7d 100644 (file)
@@ -52,6 +52,7 @@
 #include "shutdownd.h"
 #include "exit-status.h"
 #include "bus-errors.h"
+#include "build.h"
 
 static const char *arg_type = NULL;
 static char **arg_property = NULL;
@@ -1134,7 +1135,7 @@ static int start_unit_one(
                 if (arg_action != ACTION_SYSTEMCTL && error_is_no_service(error)) {
                         /* There's always a fallback possible for
                          * legacy actions. */
-                        r = 0;
+                        r = -EADDRNOTAVAIL;
                         goto finish;
                 }
 
@@ -1171,11 +1172,7 @@ static int start_unit_one(
                 }
         }
 
-        r = 1;
-
-        /* Returns 1 if we managed to issue the request, and 0 if we
-         * failed due to systemd not being around. This is then used
-         * as indication to try a fallback mechanism. */
+        r = 0;
 
 finish:
         if (m)
@@ -1281,12 +1278,7 @@ static int start_unit(DBusConnection *bus, char **args, unsigned n) {
         } else {
                 for (i = 1; i < n; i++)
                         if ((r = start_unit_one(bus, method, args[i], mode, &error, s)) != 0) {
-
-                                if (r > 0)
-                                        ret = r;
-                                else
-                                        ret = translate_bus_error_to_exit_status(r, &error);
-
+                                ret = translate_bus_error_to_exit_status(r, &error);
                                 dbus_error_free(&error);
                         }
         }
@@ -2937,7 +2929,7 @@ static int daemon_reload(DBusConnection *bus, char **args, unsigned n) {
                 if (arg_action != ACTION_SYSTEMCTL && error_is_no_service(&error)) {
                         /* There's always a fallback possible for
                          * legacy actions. */
-                        r = 0;
+                        r = -EADDRNOTAVAIL;
                         goto finish;
                 }
 
@@ -2946,7 +2938,7 @@ static int daemon_reload(DBusConnection *bus, char **args, unsigned n) {
                 goto finish;
         }
 
-        r = 1;
+        r = 0;
 
 finish:
         if (m)
@@ -3854,6 +3846,7 @@ static int systemctl_help(void) {
         printf("%s [OPTIONS...] {COMMAND} ...\n\n"
                "Send control commands to or query the systemd manager.\n\n"
                "  -h --help          Show this help\n"
+               "     --version       Show package version\n"
                "  -t --type=TYPE     List only units of a particular type\n"
                "  -p --property=NAME Show only properties by this name\n"
                "  -a --all           Show all units/properties, including dead/empty ones\n"
@@ -3988,6 +3981,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
 
         enum {
                 ARG_FAIL = 0x100,
+                ARG_VERSION,
                 ARG_SESSION,
                 ARG_SYSTEM,
                 ARG_GLOBAL,
@@ -4003,6 +3997,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
 
         static const struct option options[] = {
                 { "help",      no_argument,       NULL, 'h'           },
+                { "version",   no_argument,       NULL, ARG_VERSION   },
                 { "type",      required_argument, NULL, 't'           },
                 { "property",  required_argument, NULL, 'p'           },
                 { "all",       no_argument,       NULL, 'a'           },
@@ -4035,6 +4030,12 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                         systemctl_help();
                         return 0;
 
+                case ARG_VERSION:
+                        puts(PACKAGE_STRING);
+                        puts(DISTRIBUTION);
+                        puts(SYSTEMD_FEATURES);
+                        return 0;
+
                 case 't':
                         arg_type = optarg;
                         break;
@@ -4614,7 +4615,7 @@ static int talk_upstart(void) {
         if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error))) {
 
                 if (error_is_no_service(&error)) {
-                        r = 0;
+                        r = -EADDRNOTAVAIL;
                         goto finish;
                 }
 
@@ -4623,7 +4624,7 @@ static int talk_upstart(void) {
                 goto finish;
         }
 
-        r = 1;
+        r = 0;
 
 finish:
         if (m)
@@ -4633,6 +4634,7 @@ finish:
                 dbus_message_unref(reply);
 
         if (bus) {
+                dbus_connection_flush(bus);
                 dbus_connection_close(bus);
                 dbus_connection_unref(bus);
         }
@@ -4867,7 +4869,7 @@ static int start_with_fallback(DBusConnection *bus) {
 
         if (bus) {
                 /* First, try systemd via D-Bus. */
-                if (start_unit(bus, NULL, 0) > 0)
+                if (start_unit(bus, NULL, 0) >= 0)
                         goto done;
         }
 
@@ -5048,6 +5050,7 @@ int main(int argc, char*argv[]) {
 finish:
 
         if (bus) {
+                dbus_connection_flush(bus);
                 dbus_connection_close(bus);
                 dbus_connection_unref(bus);
         }