]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: allow Markers to be set using set-property
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 6 Feb 2021 10:39:55 +0000 (11:39 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 15 Feb 2021 19:49:14 +0000 (20:49 +0100)
src/core/dbus-unit.c
src/shared/bus-unit-util.c

index 561a4e887f91332ec279ebcc0cbab28675ee36eb..1e7e51ffbaceb4bc7a35f6d2864b62417683276c 100644 (file)
@@ -1871,6 +1871,63 @@ static int bus_unit_set_live_property(
                 return 1;
         }
 
+        /* A setting that only applies to active units. We don't actually write this to /run, this state is
+         * managed internally. "+foo" sets flag foo, "-foo" unsets flag foo, just "foo" resets flags to
+         * foo. The last type cannot be mixed with "+" or "-". */
+
+        if (streq(name, "Markers")) {
+                unsigned settings = 0, mask = 0;
+                bool some_plus_minus = false, some_absolute = false;
+
+                r = sd_bus_message_enter_container(message, 'a', "s");
+                if (r < 0)
+                        return r;
+
+                for (;;) {
+                        const char *word;
+                        bool b;
+
+                        r = sd_bus_message_read(message, "s", &word);
+                        if (r < 0)
+                                return r;
+                        if (r == 0)
+                                break;
+
+                        if (IN_SET(word[0], '+', '-')) {
+                                b = word[0] == '+';
+                                word++;
+                                some_plus_minus = true;
+                        } else {
+                                b = true;
+                                some_absolute = true;
+                        }
+
+                        UnitMarker m = unit_marker_from_string(word);
+                        if (m < 0)
+                                return sd_bus_error_setf(error, BUS_ERROR_BAD_UNIT_SETTING,
+                                                         "Unknown marker \"%s\".", word);
+
+                        SET_FLAG(settings, 1u << m, b);
+                        SET_FLAG(mask, 1u << m, true);
+                }
+
+                r = sd_bus_message_exit_container(message);
+                if (r < 0)
+                        return r;
+
+                if (some_plus_minus && some_absolute)
+                        return sd_bus_error_setf(error, BUS_ERROR_BAD_UNIT_SETTING, "Bad marker syntax.");
+
+                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
+                        if (some_absolute)
+                                u->markers = settings;
+                        else
+                                u->markers = settings | (u->markers & ~mask);
+                }
+
+                return 1;
+        }
+
         return 0;
 }
 
index 84f57d94d2358e14458f8d512ee607fe4a356328..80345ef46ae07b13364734a35874c1ffddd038fc 100644 (file)
@@ -2191,7 +2191,8 @@ static int bus_append_unit_property(sd_bus_message *m, const char *field, const
 
         if (unit_dependency_from_string(field) >= 0 ||
             STR_IN_SET(field, "Documentation",
-                              "RequiresMountsFor"))
+                              "RequiresMountsFor",
+                              "Markers"))
                 return bus_append_strv(m, field, eq, EXTRACT_UNQUOTE);
 
         t = condition_type_from_string(field);