chiark / gitweb /
systemctl: properly iterate through service array when dispatching to sysv
[elogind.git] / src / systemctl / systemctl.c
index 060bfe28e4e96403260eaad43110712c42a46ac6..3d939f050b707722eb20a0017ec6a85522b9bba0 100644 (file)
@@ -1951,32 +1951,6 @@ static void dump_unit_file_changes(const UnitFileChange *changes, unsigned n_cha
         }
 }
 
-static int deserialize_and_dump_unit_file_changes(sd_bus_message *m) {
-        const char *type, *path, *source;
-        int r;
-
-        r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(sss)");
-        if (r < 0)
-                return bus_log_parse_error(r);
-
-        while ((r = sd_bus_message_read(m, "(sss)", &type, &path, &source)) > 0) {
-                if (!arg_quiet) {
-                        if (streq(type, "symlink"))
-                                log_info("Created symlink from %s to %s.", path, source);
-                        else
-                                log_info("Removed symlink %s.", path);
-                }
-        }
-        if (r < 0)
-                return bus_log_parse_error(r);
-
-        r = sd_bus_message_exit_container(m);
-        if (r < 0)
-                return bus_log_parse_error(r);
-
-        return 0;
-}
-
 static int set_default(sd_bus *bus, char **args) {
         _cleanup_free_ char *unit = NULL;
         UnitFileChange *changes = NULL;
@@ -2024,7 +1998,7 @@ static int set_default(sd_bus *bus, char **args) {
                         return r;
                 }
 
-                r = deserialize_and_dump_unit_file_changes(reply);
+                r = bus_deserialize_and_dump_unit_file_changes(reply, arg_quiet);
                 if (r < 0)
                         return r;
 
@@ -2992,7 +2966,7 @@ static int start_special(sd_bus *bus, char **args) {
              a == ACTION_HIBERNATE ||
              a == ACTION_HYBRID_SLEEP)) {
                 r = reboot_with_logind(bus, a);
-                if (r >= 0)
+                if (r >= 0 || IN_SET(r, -ENOTSUP, -EINPROGRESS))
                         return r;
         }
 
@@ -5214,8 +5188,10 @@ static int enable_sysv_units(const char *verb, char **args) {
                         return -EPROTO;
 
                 /* Remove this entry, so that we don't try enabling it as native unit */
-                assert(f > 0 && streq(args[f-1], name));
-                assert_se(strv_remove(args + f - 1, name));
+                assert(f > 0);
+                f--;
+                assert(args[f] == name);
+                strv_remove(args, name);
         }
 
 #endif
@@ -5389,7 +5365,7 @@ static int enable_unit(sd_bus *bus, char **args) {
                                 return bus_log_parse_error(r);
                 }
 
-                r = deserialize_and_dump_unit_file_changes(reply);
+                r = bus_deserialize_and_dump_unit_file_changes(reply, arg_quiet);
                 if (r < 0)
                         return r;
 
@@ -5488,7 +5464,7 @@ static int add_dependency(sd_bus *bus, char **args) {
                         return r;
                 }
 
-                r = deserialize_and_dump_unit_file_changes(reply);
+                r = bus_deserialize_and_dump_unit_file_changes(reply, arg_quiet);
                 if (r < 0)
                         return r;
 
@@ -5552,7 +5528,7 @@ static int preset_all(sd_bus *bus, char **args) {
                         return r;
                 }
 
-                r = deserialize_and_dump_unit_file_changes(reply);
+                r = bus_deserialize_and_dump_unit_file_changes(reply, arg_quiet);
                 if (r < 0)
                         return r;