From ed7e9b34ce903218275694f03277c30ddcb29953 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 14 Dec 2017 16:32:59 +0900 Subject: [PATCH 1/7] bus-unit-util: remove unnecessary oom check We cannot detect error by alloca(). --- src/shared/bus-unit-util.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index b58abed2b5..4a9d249f28 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -153,8 +153,6 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen l = strlen(field); n = newa(char, l + 2); - if (!n) - return log_oom(); /* Change suffix Sec → USec */ strcpy(mempcpy(n, field, l - 3), "USec"); From afcb1cd3a30c2c971304bccf3d4040ccf0eaa228 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 14 Dec 2017 16:34:26 +0900 Subject: [PATCH 2/7] bus-unit-util: improve error messages --- src/shared/bus-unit-util.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 4a9d249f28..20bc4c95eb 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -972,6 +972,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen } r = sd_bus_message_append(m, "v", "i", oa); + } else if (STR_IN_SET(field, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories", "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) { const char *p; @@ -1003,7 +1004,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen offset += word[offset] == '+'; if (!path_is_absolute(word + offset)) { - log_error("Failed to parse %s value %s", field, eq); + log_error("Path specified by %s is not absolute: %s", field, eq); return -EINVAL; } @@ -1041,7 +1042,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen break; if (!valid_user_group_name_or_id(word)) { - log_error("Failed to parse %s value %s", field, eq); + log_error("Invalid group name or id is specified by %s: %s", field, eq); return -EINVAL; } @@ -1122,8 +1123,11 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen flags = (~flags) & NAMESPACE_FLAGS_ALL; r = sd_bus_message_append(m, "v", "t", (uint64_t) flags); + } else if ((dep = unit_dependency_from_string(field)) >= 0) + r = sd_bus_message_append(m, "v", "as", 1, eq); + else if (streq(field, "MountFlags")) { unsigned long f; @@ -1132,6 +1136,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen return log_error_errno(r, "Failed to parse mount propagation flags: %s", eq); r = sd_bus_message_append(m, "v", "t", (uint64_t) f); + } else if (STR_IN_SET(field, "BindPaths", "BindReadOnlyPaths")) { const char *p = eq; From 1e3b7b0ec8bb9678e8f569272077585eefe1419f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 14 Dec 2017 21:52:47 +0900 Subject: [PATCH 3/7] core/dbus-timer: improve error messages --- src/core/dbus-timer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/dbus-timer.c b/src/core/dbus-timer.c index 3e64536b17..12cebc2ccc 100644 --- a/src/core/dbus-timer.c +++ b/src/core/dbus-timer.c @@ -200,7 +200,7 @@ static int bus_timer_set_transient_property( b = timer_base_from_string(name); if (b < 0) - return -EINVAL; + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown timer base"); r = sd_bus_message_read(message, "t", &u); if (r < 0) @@ -235,6 +235,8 @@ static int bus_timer_set_transient_property( if (!UNIT_WRITE_FLAGS_NOOP(flags)) { r = calendar_spec_from_string(str, &c); + if (r == -EINVAL) + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid calendar spec"); if (r < 0) return r; From 5b9fbf89897a00200fc0717cfc25e8a4bd70e88d Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 12 Dec 2017 00:10:58 +0900 Subject: [PATCH 4/7] core/path: implement transient path unit --- src/core/dbus-path.c | 119 +++++++++++++++++++++++++++++++++++++++++++ src/core/dbus-path.h | 4 ++ src/core/path.c | 6 ++- 3 files changed, 128 insertions(+), 1 deletion(-) diff --git a/src/core/dbus-path.c b/src/core/dbus-path.c index 0f54b04f76..d9cf212eb7 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 5e7e859b56..ccd88c7f86 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 6b22451a08..8a5ec0a72f 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, }; From 535e0d19a210856fb6097100548c6ba8869ea268 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 15 Dec 2017 09:11:39 +0900 Subject: [PATCH 5/7] bus-unit-util: add path unit related options --- src/shared/bus-unit-util.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 20bc4c95eb..8af738d8ce 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -358,7 +358,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen "NoNewPrivileges", "SyslogLevelPrefix", "RemainAfterElapse", "Persistent", "MemoryDenyWriteExecute", "RestrictRealtime", "DynamicUser", "RemoveIPC", "ProtectKernelTunables", "ProtectKernelModules", "ProtectControlGroups", "MountAPIVFS", - "CPUSchedulingResetOnFork", "LockPersonality")) { + "CPUSchedulingResetOnFork", "LockPersonality", "MakeDirectory")) { r = parse_boolean(eq); if (r < 0) @@ -1057,7 +1057,10 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen r = sd_bus_message_close_container(m); - } else if (STR_IN_SET(field, "RuntimeDirectoryMode", "StateDirectoryMode", "CacheDirectoryMode", "LogsDirectoryMode", "ConfigurationDirectoryMode", "UMask")) { + } else if (STR_IN_SET(field, + "RuntimeDirectoryMode", "StateDirectoryMode", "CacheDirectoryMode", + "LogsDirectoryMode", "ConfigurationDirectoryMode", "UMask", + "DirectoryMode")) { mode_t mode; r = parse_mode(eq, &mode); @@ -1306,6 +1309,17 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen r = sd_bus_message_append(m, "v", "t", t); + } else if (STR_IN_SET(field, + "PathExists", "PathExistsGlob", "PathChanged", + "PathModified", "DirectoryNotEmpty")) { + + if (!path_is_absolute(eq)) { + log_error("Path specified by %s= is not absolute: %s", field, eq); + return -EINVAL; + } + + r = sd_bus_message_append(m, "v", "s", eq); + } else { log_error("Unknown assignment: %s", assignment); return -EINVAL; From d852bda10560539bb9520044eac98c61f56a50fb Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 14 Dec 2017 22:02:06 +0900 Subject: [PATCH 6/7] doc: update TRANSIENT-SETTINGS.md --- TRANSIENT-SETTINGS.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/TRANSIENT-SETTINGS.md b/TRANSIENT-SETTINGS.md index 17fe0604ec..789ffe0dcf 100644 --- a/TRANSIENT-SETTINGS.md +++ b/TRANSIENT-SETTINGS.md @@ -325,7 +325,7 @@ Most timer unit settings are available to transient units. ✓ OnStartupSec= ✓ OnUnitActiveSec= ✓ OnUnitInactiveSec= - Persistent= +✓ Persistent= ✓ WakeSystem= ✓ RemainAfterElapse= ✓ AccuracySec= @@ -421,17 +421,17 @@ Swap units are currently not available at all as transient units: ## Path Unit Settings -Path units are currently not available at all as transient units: +Most path unit settings are available to transient units. ``` - PathExists= - PathExistsGlob= - PathChanged= - PathModified= - DirectoryNotEmpty= +✓ PathExists= +✓ PathExistsGlob= +✓ PathChanged= +✓ PathModified= +✓ DirectoryNotEmpty= Unit= - MakeDirectory= - DirectoryMode= +✓ MakeDirectory= +✓ DirectoryMode= ``` ## Install Section From 69ec5decf006374a28d122b16066f4bd1aee8282 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 14 Dec 2017 22:17:17 +0900 Subject: [PATCH 7/7] TODO: update --- TODO | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/TODO b/TODO index 0c20012b29..b022b601ef 100644 --- a/TODO +++ b/TODO @@ -24,6 +24,10 @@ Janitorial Clean-ups: Features: +* implement transient socket unit. + +* make systemd-run create transient path and socket unit. + * make use of ethtool veth peer info in machined, for automatically finding out host-side interface pointing to the container.