]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dbus-path: add Paths= option to set path specs in transient path unit
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 1 Jan 2018 17:25:57 +0000 (02:25 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 2 Jan 2018 17:32:30 +0000 (02:32 +0900)
src/core/dbus-path.c

index d9cf212eb7afe1a3b60ac563c87b4fa58fd9cfe1..b3f502f4c9872e830759f9b854e97e7706113a98 100644 (file)
@@ -21,6 +21,7 @@
 #include "alloc-util.h"
 #include "bus-util.h"
 #include "dbus-path.h"
+#include "dbus-util.h"
 #include "list.h"
 #include "path.h"
 #include "path-util.h"
@@ -105,30 +106,38 @@ static int bus_path_set_transient_property(
 
         flags |= UNIT_PRIVATE;
 
-        if (STR_IN_SET(name, "PathExists", "PathExistsGlob", "PathChanged", "PathModified", "DirectoryNotEmpty")) {
-                const char *str;
-                PathType b;
+        if (streq(name, "MakeDirectory"))
+                return bus_set_transient_bool(u, name, &p->make_directory, message, flags, error);
 
-                b = path_type_from_string(name);
-                if (b < 0)
-                        return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown path type");
+        if (streq(name, "DirectoryMode"))
+                return bus_set_transient_mode_t(u, name, &p->directory_mode, message, flags, error);
 
-                r = sd_bus_message_read(message, "s", &str);
+        if (streq(name, "Paths")) {
+                const char *type_name, *path;
+                bool empty = true;
+
+                r = sd_bus_message_enter_container(message, 'a', "(ss)");
                 if (r < 0)
                         return r;
 
-                if (!isempty(str) && !path_is_absolute(str))
-                        return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path is not absolute");
+                while ((r = sd_bus_message_read(message, "(ss)", &type_name, &path)) > 0) {
+                        PathType t;
+
+                        t = path_type_from_string(type_name);
+                        if (t < 0)
+                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown path type: %s", type_name);
+
+                        if (isempty(path))
+                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path in %s is empty", type_name);
+
+                        if (!path_is_absolute(path))
+                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path in %s is not absolute: %s", type_name, path);
 
-                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
-                        if (isempty(str)) {
-                                path_free_specs(p);
-                                unit_write_settingf(u, flags, name, "%s=", name);
-                        } else {
+                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                                 _cleanup_free_ char *k;
                                 PathSpec *s;
 
-                                k = strdup(str);
+                                k = strdup(path);
                                 if (!k)
                                         return -ENOMEM;
 
@@ -139,48 +148,29 @@ static int bus_path_set_transient_property(
                                 s->unit = u;
                                 s->path = path_kill_slashes(k);
                                 k = NULL;
-                                s->type = b;
+                                s->type = t;
                                 s->inotify_fd = -1;
 
                                 LIST_PREPEND(spec, p->specs, s);
 
-                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, str);
+                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", type_name, path);
                         }
-                }
-
-                return 1;
-
-        } else if (streq(name, "MakeDirectory")) {
-                int b;
 
-                r = sd_bus_message_read(message, "b", &b);
+                        empty = false;
+                }
                 if (r < 0)
                         return r;
 
-                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
-                        p->make_directory = b;
-                        unit_write_settingf(u, flags, name, "%s=%s", name, yes_no(b));
-                }
-
-                return 1;
-
-        } else if (streq(name, "DirectoryMode")) {
-                mode_t m;
-
-                r = sd_bus_message_read(message, "u", &m);
+                r = sd_bus_message_exit_container(message);
                 if (r < 0)
                         return r;
 
-                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
-                        p->directory_mode = m;
-                        unit_write_settingf(u, flags, name, "%s=%040o", name, m);
+                if (!UNIT_WRITE_FLAGS_NOOP(flags) && empty) {
+                        path_free_specs(p);
+                        unit_write_settingf(u, flags, name, "PathExists=");
                 }
 
                 return 1;
-
-        } else if (streq(name, "Unit")) {
-                /* not implemented yet */
-                return 0;
         }
 
         return 0;