diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-11-02 20:16:18 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-11-02 20:16:18 +0100 |
commit | 5732a7dbb0efa79cc36c6864a4af2e98685b53d6 (patch) | |
tree | 9f2d3e9f7a5f489eca92b4a39af543c810caac35 | |
parent | 3e66a83cc34a5f201e3afa831c7ad8bc22a8549f (diff) | |
parent | dcebcd7ade39f4137a34dd08991432f8df995867 (diff) |
Merge pull request #1690 from evverx/run-runtime-directory
systemd-run can launch units with RuntimeDirectory
-rw-r--r-- | shell-completion/bash/systemd-run | 2 | ||||
-rw-r--r-- | shell-completion/zsh/_systemd-run | 2 | ||||
-rw-r--r-- | src/core/dbus-execute.c | 35 | ||||
-rw-r--r-- | src/shared/bus-util.c | 34 |
4 files changed, 71 insertions, 2 deletions
diff --git a/shell-completion/bash/systemd-run b/shell-completion/bash/systemd-run index dfcb01231f..7379431b71 100644 --- a/shell-completion/bash/systemd-run +++ b/shell-completion/bash/systemd-run @@ -86,7 +86,7 @@ _systemd_run() { TTYPath= SyslogIdentifier= SyslogLevelPrefix= SyslogLevel= SyslogFacility= TimerSlackNSec= OOMScoreAdjust= ReadWriteDirectories= ReadOnlyDirectories= InaccessibleDirectories= EnvironmentFile= - ProtectSystem= ProtectHome=' + ProtectSystem= ProtectHome= RuntimeDirectory=' COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) return 0 diff --git a/shell-completion/zsh/_systemd-run b/shell-completion/zsh/_systemd-run index d4fa39341c..8bb0156a85 100644 --- a/shell-completion/zsh/_systemd-run +++ b/shell-completion/zsh/_systemd-run @@ -39,7 +39,7 @@ _arguments \ TTYPath= SyslogIdentifier= SyslogLevelPrefix= SyslogLevel= \ SyslogFacility= TimerSlackNSec= OOMScoreAdjust= ReadWriteDirectories= \ ReadOnlyDirectories= InaccessibleDirectories= EnvironmentFile= \ - ProtectSystem= ProtectHome= \ + ProtectSystem= ProtectHome= RuntimeDirectory= \ ))' \ '--description=[Description for unit]:description' \ '--slice=[Run in the specified slice]:slices:__slices' \ diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 04a5a22b72..db4206a523 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -1391,6 +1391,41 @@ int bus_exec_context_set_transient_property( return 1; + } else if (streq(name, "RuntimeDirectory")) { + _cleanup_strv_free_ char **l = NULL; + char **p; + + r = sd_bus_message_read_strv(message, &l); + if (r < 0) + return r; + + STRV_FOREACH(p, l) { + if (!filename_is_valid(*p)) + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Runtime directory is not valid %s", *p); + } + + if (mode != UNIT_CHECK) { + _cleanup_free_ char *joined = NULL; + + if (strv_isempty(l)) { + c->runtime_directory = strv_free(c->runtime_directory); + unit_write_drop_in_private_format(u, mode, name, "%s=\n", name); + } else { + r = strv_extend_strv(&c->runtime_directory, l, true); + + if (r < 0) + return -ENOMEM; + + joined = strv_join_quoted(c->runtime_directory); + if (!joined) + return -ENOMEM; + + unit_write_drop_in_private_format(u, mode, name, "%s=%s\n", name, joined); + } + } + + return 1; + } else if (rlimit_from_string(name) >= 0) { uint64_t rl; rlim_t x; diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index dbae6e7c85..a13991a960 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -1789,6 +1789,40 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen r = sd_bus_message_close_container(m); + } else if (streq(field, "RuntimeDirectory")) { + const char *p; + + r = sd_bus_message_open_container(m, 'v', "as"); + if (r < 0) + return bus_log_create_error(r); + + r = sd_bus_message_open_container(m, 'a', "s"); + if (r < 0) + return bus_log_create_error(r); + + p = eq; + + for (;;) { + _cleanup_free_ char *word = NULL; + + r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES); + if (r < 0) + return log_error_errno(r, "Failed to parse %s value %s", field, eq); + + if (r == 0) + break; + + r = sd_bus_message_append_basic(m, 's', word); + if (r < 0) + return bus_log_create_error(r); + } + + r = sd_bus_message_close_container(m); + if (r < 0) + return bus_log_create_error(r); + + r = sd_bus_message_close_container(m); + } else { log_error("Unknown assignment %s.", assignment); return -EINVAL; |