From: Yu Watanabe Date: Mon, 11 Dec 2017 15:10:58 +0000 (+0900) Subject: core/path: implement transient path unit X-Git-Tag: v237~218^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5b9fbf89897a00200fc0717cfc25e8a4bd70e88d;p=thirdparty%2Fsystemd.git core/path: implement transient path unit --- diff --git a/src/core/dbus-path.c b/src/core/dbus-path.c index 0f54b04f76c..d9cf212eb7a 100644 --- a/src/core/dbus-path.c +++ b/src/core/dbus-path.c @@ -18,9 +18,12 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "bus-util.h" #include "dbus-path.h" +#include "list.h" #include "path.h" +#include "path-util.h" #include "string-util.h" #include "unit.h" @@ -85,3 +88,119 @@ const sd_bus_vtable bus_path_vtable[] = { SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Path, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_VTABLE_END }; + +static int bus_path_set_transient_property( + Path *p, + const char *name, + sd_bus_message *message, + UnitWriteFlags flags, + sd_bus_error *error) { + + Unit *u = UNIT(p); + int r; + + assert(p); + assert(name); + assert(message); + + flags |= UNIT_PRIVATE; + + if (STR_IN_SET(name, "PathExists", "PathExistsGlob", "PathChanged", "PathModified", "DirectoryNotEmpty")) { + const char *str; + PathType b; + + b = path_type_from_string(name); + if (b < 0) + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown path type"); + + r = sd_bus_message_read(message, "s", &str); + 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"); + + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { + if (isempty(str)) { + path_free_specs(p); + unit_write_settingf(u, flags, name, "%s=", name); + } else { + _cleanup_free_ char *k; + PathSpec *s; + + k = strdup(str); + if (!k) + return -ENOMEM; + + s = new0(PathSpec, 1); + if (!s) + return -ENOMEM; + + s->unit = u; + s->path = path_kill_slashes(k); + k = NULL; + s->type = b; + s->inotify_fd = -1; + + LIST_PREPEND(spec, p->specs, s); + + unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, str); + } + } + + return 1; + + } else if (streq(name, "MakeDirectory")) { + int b; + + r = sd_bus_message_read(message, "b", &b); + 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); + 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); + } + + return 1; + + } else if (streq(name, "Unit")) { + /* not implemented yet */ + return 0; + } + + return 0; +} + +int bus_path_set_property( + Unit *u, + const char *name, + sd_bus_message *message, + UnitWriteFlags mode, + sd_bus_error *error) { + + Path *p = PATH(u); + + assert(p); + assert(name); + assert(message); + + if (u->transient && u->load_state == UNIT_STUB) + return bus_path_set_transient_property(p, name, message, mode, error); + + return 0; +} diff --git a/src/core/dbus-path.h b/src/core/dbus-path.h index 5e7e859b569..ccd88c7f867 100644 --- a/src/core/dbus-path.h +++ b/src/core/dbus-path.h @@ -20,6 +20,10 @@ along with systemd; If not, see . ***/ +#include "sd-bus.h" +#include "unit.h" extern const sd_bus_vtable bus_path_vtable[]; + +int bus_path_set_property(Unit *u, const char *name, sd_bus_message *i, UnitWriteFlags flags, sd_bus_error *error); diff --git a/src/core/path.c b/src/core/path.c index 6b22451a08a..8a5ec0a72f6 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -772,6 +772,9 @@ const UnitVTable path_vtable = { "Unit\0" "Path\0" "Install\0", + .private_section = "Path", + + .can_transient = true, .init = path_init, .done = path_done, @@ -794,5 +797,6 @@ const UnitVTable path_vtable = { .reset_failed = path_reset_failed, - .bus_vtable = bus_path_vtable + .bus_vtable = bus_path_vtable, + .bus_set_property = bus_path_set_property, };