run: can launch units with RuntimeDirectory

This commit is contained in:
Evgeny Vereshchagin 2015-10-27 04:56:42 +03:00
parent a9067193dd
commit fa21b5e3d7
2 changed files with 69 additions and 0 deletions

View file

@ -1387,6 +1387,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;

View file

@ -1781,6 +1781,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;