summaryrefslogtreecommitdiff
path: root/src/core/dbus-path.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-01-02 02:25:57 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-01-03 02:32:30 +0900
commitf76e92af1c0d29124c7f219f142bed2860edaac8 (patch)
tree8189885b6ccd32b1d86074501cb0dde0bd7a84e2 /src/core/dbus-path.c
parentdea700bffd9510cc5a06460a07734e08023d62d8 (diff)
downloadsystemd-f76e92af1c0d29124c7f219f142bed2860edaac8.tar.gz
dbus-path: add Paths= option to set path specs in transient path unit
Diffstat (limited to 'src/core/dbus-path.c')
-rw-r--r--src/core/dbus-path.c74
1 files changed, 32 insertions, 42 deletions
diff --git a/src/core/dbus-path.c b/src/core/dbus-path.c
index d9cf212eb7..b3f502f4c9 100644
--- a/src/core/dbus-path.c
+++ b/src/core/dbus-path.c
@@ -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;