chiark / gitweb /
shutdown: remove explicit sync() invocations
[elogind.git] / src / systemctl / systemctl.c
index 1c06507e4cefbeb839ce8de7fe029d6eaa06739f..14f8a129d58a321ddee28f5970d9906beaf6df45 100644 (file)
@@ -74,7 +74,6 @@ static bool arg_no_block = false;
 static bool arg_no_legend = false;
 static bool arg_no_pager = false;
 static bool arg_no_wtmp = false;
-static bool arg_no_sync = false;
 static bool arg_no_wall = false;
 static bool arg_no_reload = false;
 static bool arg_dry = false;
@@ -202,21 +201,6 @@ static const char *ansi_highlight_green(bool b) {
         return b ? ANSI_HIGHLIGHT_GREEN_ON : ANSI_HIGHLIGHT_OFF;
 }
 
-static bool error_is_no_service(const DBusError *error) {
-        assert(error);
-
-        if (!dbus_error_is_set(error))
-                return false;
-
-        if (dbus_error_has_name(error, DBUS_ERROR_NAME_HAS_NO_OWNER))
-                return true;
-
-        if (dbus_error_has_name(error, DBUS_ERROR_SERVICE_UNKNOWN))
-                return true;
-
-        return startswith(error->name, "org.freedesktop.DBus.Error.Spawn.");
-}
-
 static int translate_bus_error_to_exit_status(int r, const DBusError *error) {
         assert(error);
 
@@ -245,64 +229,6 @@ static int translate_bus_error_to_exit_status(int r, const DBusError *error) {
         return EXIT_FAILURE;
 }
 
-static int bus_method_call_with_reply(DBusConnection *bus,
-                                       const char *destination,
-                                       const char *path,
-                                       const char *interface,
-                                       const char *method,
-                                       DBusMessage **return_reply,
-                                       DBusError *return_error,
-                                       int first_arg_type, ...) {
-        DBusError error;
-        DBusMessage *m, *reply;
-        va_list ap;
-        int r = 0;
-
-        dbus_error_init(&error);
-        assert(bus);
-
-        m = dbus_message_new_method_call(destination, path, interface, method);
-        if (!m) {
-                r = log_oom();
-                goto finish;
-        }
-
-        va_start(ap, first_arg_type);
-        if (!dbus_message_append_args_valist(m, first_arg_type, ap)) {
-                va_end(ap);
-                dbus_message_unref(m);
-                r = log_oom();
-                goto finish;
-        }
-        va_end(ap);
-
-        reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
-        dbus_message_unref(m);
-        if (!reply) {
-                log_error("Failed to issue method call: %s", bus_error_message(&error));
-                if (error_is_no_service(&error))
-                        r = -ENOENT;
-                else if (dbus_error_has_name(&error, DBUS_ERROR_ACCESS_DENIED))
-                        r = -EACCES;
-                else if (dbus_error_has_name(&error, DBUS_ERROR_NO_REPLY))
-                        r = -ETIMEDOUT;
-                else
-                        r = -EIO;
-                goto finish;
-        }
-        if (return_reply)
-                *return_reply = reply;
-        else
-                dbus_message_unref(reply);
-finish:
-        if(return_error)
-                *return_error=error;
-        else
-                dbus_error_free(&error);
-
-        return r;
-}
-
 static void warn_wall(enum action a) {
         static const char *table[_ACTION_MAX] = {
                 [ACTION_HALT]            = "The system is going down for system halt NOW!",
@@ -1610,11 +1536,12 @@ static int start_unit_one(
                         DBUS_TYPE_INVALID);
         free(n);
         if (r) {
-                if (r == -ENOENT && arg_action != ACTION_SYSTEMCTL ) {
+                if (r == -ENOENT && arg_action != ACTION_SYSTEMCTL )
                         /* There's always a fallback possible for
                          * legacy actions. */
                         r = -EADDRNOTAVAIL;
-                }
+                else
+                        log_error("Failed to issue method call: %s", bus_error_message(error));
                 goto finish;
         }
 
@@ -2220,7 +2147,7 @@ static void print_status_info(UnitStatusInfo *i) {
                 printf("\t Process: %u %s=%s ", p->pid, p->name, strna(t));
                 free(t);
 
-                good = is_clean_exit_lsb(p->code, p->status);
+                good = is_clean_exit_lsb(p->code, p->status, NULL);
                 if (!good) {
                         on = ansi_highlight_red(true);
                         off = ansi_highlight_red(false);
@@ -3216,6 +3143,7 @@ finish:
 static int daemon_reload(DBusConnection *bus, char **args) {
         int r;
         const char *method;
+        DBusError error;
 
         if (arg_action == ACTION_RELOAD)
                 method = "Reload";
@@ -3244,7 +3172,7 @@ static int daemon_reload(DBusConnection *bus, char **args) {
                         "org.freedesktop.systemd1.Manager",
                         method,
                         NULL,
-                        NULL,
+                        &error,
                         DBUS_TYPE_INVALID);
 
         if (r == -ENOENT && arg_action != ACTION_SYSTEMCTL)
@@ -3255,6 +3183,9 @@ static int daemon_reload(DBusConnection *bus, char **args) {
                 /* On reexecution, we expect a disconnect, not
                  * a reply */
                 r = 0;
+        else if (r)
+                log_error("Failed to issue method call: %s", bus_error_message(&error));
+        dbus_error_free(&error);
 
         return r;
 }
@@ -3939,7 +3870,7 @@ static int systemctl_help(void) {
                "  -n --lines=INTEGER  Journal entries to show\n"
                "     --follow         Follow journal\n"
                "  -o --output=STRING  Change journal output mode (short, short-monotonic,\n"
-               "                      verbose, export, json, cat)\n\n"
+               "                      verbose, export, json, json-pretty, cat)\n\n"
                "Unit Commands:\n"
                "  list-units                      List loaded units\n"
                "  start [NAME...]                 Start (activate) one or more units\n"
@@ -4017,7 +3948,6 @@ static int halt_help(void) {
                "  -f --force     Force immediate halt/power-off/reboot\n"
                "  -w --wtmp-only Don't halt/power-off/reboot, just write wtmp record\n"
                "  -d --no-wtmp   Don't write wtmp record\n"
-               "  -n --no-sync   Don't sync before halt/power-off/reboot\n"
                "     --no-wall   Don't send wall message before halt/power-off/reboot\n",
                program_invocation_short_name,
                arg_action == ACTION_REBOOT   ? "Reboot" :
@@ -4339,7 +4269,6 @@ static int halt_parse_argv(int argc, char *argv[]) {
                 { "force",     no_argument,       NULL, 'f'         },
                 { "wtmp-only", no_argument,       NULL, 'w'         },
                 { "no-wtmp",   no_argument,       NULL, 'd'         },
-                { "no-sync",   no_argument,       NULL, 'n'         },
                 { "no-wall",   no_argument,       NULL, ARG_NO_WALL },
                 { NULL,        0,                 NULL, 0           }
         };
@@ -4385,16 +4314,13 @@ static int halt_parse_argv(int argc, char *argv[]) {
                         arg_no_wtmp = true;
                         break;
 
-                case 'n':
-                        arg_no_sync = true;
-                        break;
-
                 case ARG_NO_WALL:
                         arg_no_wall = true;
                         break;
 
                 case 'i':
                 case 'h':
+                case 'n':
                         /* Compatibility nops */
                         break;
 
@@ -4826,7 +4752,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)) {
+                if (bus_error_is_no_service(&error)) {
                         r = -EADDRNOTAVAIL;
                         goto finish;
                 }
@@ -5236,9 +5162,6 @@ static int halt_main(DBusConnection *bus) {
                 }
         }
 
-        if (!arg_no_sync)
-                sync();
-
         if (arg_dry)
                 return 0;