diff options
Diffstat (limited to 'src/core/dbus-service.c')
-rw-r--r-- | src/core/dbus-service.c | 81 |
1 files changed, 48 insertions, 33 deletions
diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c index 05bdc0a748..0189952124 100644 --- a/src/core/dbus-service.c +++ b/src/core/dbus-service.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. @@ -17,6 +18,8 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include <stdio_ext.h> + #include "alloc-util.h" #include "async.h" #include "bus-util.h" @@ -50,7 +53,6 @@ const sd_bus_vtable bus_service_vtable[] = { SD_BUS_PROPERTY("RuntimeMaxUSec", "t", bus_property_get_usec, offsetof(Service, runtime_max_usec), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("WatchdogUSec", "t", bus_property_get_usec, offsetof(Service, watchdog_usec), SD_BUS_VTABLE_PROPERTY_CONST), BUS_PROPERTY_DUAL_TIMESTAMP("WatchdogTimestamp", offsetof(Service, watchdog_timestamp), 0), - SD_BUS_PROPERTY("FailureAction", "s", property_get_emergency_action, offsetof(Service, emergency_action), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("PermissionsStartOnly", "b", bus_property_get_bool, offsetof(Service, permissions_start_only), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("RootDirectoryStartOnly", "b", bus_property_get_bool, offsetof(Service, root_directory_start_only), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("RemainAfterExit", "b", bus_property_get_bool, offsetof(Service, remain_after_exit), SD_BUS_VTABLE_PROPERTY_CONST), @@ -81,6 +83,7 @@ const sd_bus_vtable bus_service_vtable[] = { SD_BUS_PROPERTY("StartLimitInterval", "t", bus_property_get_usec, offsetof(Unit, start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), SD_BUS_PROPERTY("StartLimitBurst", "u", bus_property_get_unsigned, offsetof(Unit, start_limit.burst), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), SD_BUS_PROPERTY("StartLimitAction", "s", property_get_emergency_action, offsetof(Unit, start_limit_action), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), + SD_BUS_PROPERTY("FailureAction", "s", property_get_emergency_action, offsetof(Unit, failure_action), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), SD_BUS_PROPERTY("RebootArgument", "s", NULL, offsetof(Unit, reboot_arg), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), SD_BUS_VTABLE_END }; @@ -89,15 +92,18 @@ static int bus_service_set_transient_property( Service *s, const char *name, sd_bus_message *message, - UnitSetPropertiesMode mode, + UnitWriteFlags flags, sd_bus_error *error) { + ServiceExecCommand ci; int r; assert(s); assert(name); assert(message); + flags |= UNIT_PRIVATE; + if (streq(name, "RemainAfterExit")) { int b; @@ -105,9 +111,9 @@ static int bus_service_set_transient_property( if (r < 0) return r; - if (mode != UNIT_CHECK) { + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { s->remain_after_exit = b; - unit_write_drop_in_private_format(UNIT(s), mode, name, "RemainAfterExit=%s", yes_no(b)); + unit_write_settingf(UNIT(s), flags, name, "RemainAfterExit=%s", yes_no(b)); } return 1; @@ -124,9 +130,9 @@ static int bus_service_set_transient_property( if (k < 0) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid service type %s", t); - if (mode != UNIT_CHECK) { + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { s->type = k; - unit_write_drop_in_private_format(UNIT(s), mode, name, "Type=%s", service_type_to_string(s->type)); + unit_write_settingf(UNIT(s), flags, name, "Type=%s", service_type_to_string(s->type)); } return 1; @@ -137,9 +143,9 @@ static int bus_service_set_transient_property( if (r < 0) return r; - if (mode != UNIT_CHECK) { + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { s->runtime_max_usec = u; - unit_write_drop_in_private_format(UNIT(s), mode, name, "RuntimeMaxSec=" USEC_FMT "us", u); + unit_write_settingf(UNIT(s), flags, name, "RuntimeMaxSec=" USEC_FMT "us", u); } return 1; @@ -160,9 +166,9 @@ static int bus_service_set_transient_property( return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid restart setting: %s", v); } - if (mode != UNIT_CHECK) { + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { s->restart = sr; - unit_write_drop_in_private_format(UNIT(s), mode, name, "Restart=%s", service_restart_to_string(sr)); + unit_write_settingf(UNIT(s), flags, name, "Restart=%s", service_restart_to_string(sr)); } return 1; @@ -177,7 +183,7 @@ static int bus_service_set_transient_property( if (r < 0) return r; - if (mode != UNIT_CHECK) { + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { int copy; copy = fcntl(fd, F_DUPFD_CLOEXEC, 3); @@ -207,9 +213,9 @@ static int bus_service_set_transient_property( if (r < 0) return r; - if (mode != UNIT_CHECK) { + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { s->n_fd_store_max = (unsigned) u; - unit_write_drop_in_private_format(UNIT(s), mode, name, "FileDescriptorStoreMax=%" PRIu32, u); + unit_write_settingf(UNIT(s), flags, name, "FileDescriptorStoreMax=%" PRIu32, u); } return 1; @@ -226,14 +232,14 @@ static int bus_service_set_transient_property( if (k < 0) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid notify access setting %s", t); - if (mode != UNIT_CHECK) { + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { s->notify_access = k; - unit_write_drop_in_private_format(UNIT(s), mode, name, "NotifyAccess=%s", notify_access_to_string(s->notify_access)); + unit_write_settingf(UNIT(s), flags, name, "NotifyAccess=%s", notify_access_to_string(s->notify_access)); } return 1; - } else if (streq(name, "ExecStart")) { + } else if ((ci = service_exec_command_from_string(name)) >= 0) { unsigned n = 0; r = sd_bus_message_enter_container(message, 'a', "(sasb)"); @@ -250,7 +256,7 @@ static int bus_service_set_transient_property( return r; if (!path_is_absolute(path)) - return sd_bus_error_set_errnof(error, EINVAL, "Path %s is not absolute.", path); + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path); r = sd_bus_message_read_strv(message, &argv); if (r < 0) @@ -264,7 +270,7 @@ static int bus_service_set_transient_property( if (r < 0) return r; - if (mode != UNIT_CHECK) { + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { ExecCommand *c; c = new0(ExecCommand, 1); @@ -283,7 +289,7 @@ static int bus_service_set_transient_property( c->flags = b ? EXEC_COMMAND_IGNORE_FAILURE : 0; path_kill_slashes(c->path); - exec_command_append_list(&s->exec_command[SERVICE_EXEC_START], c); + exec_command_append_list(&s->exec_command[ci], c); } n++; @@ -296,38 +302,47 @@ static int bus_service_set_transient_property( if (r < 0) return r; - if (mode != UNIT_CHECK) { + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { _cleanup_free_ char *buf = NULL; _cleanup_fclose_ FILE *f = NULL; ExecCommand *c; size_t size = 0; if (n == 0) - s->exec_command[SERVICE_EXEC_START] = exec_command_free_list(s->exec_command[SERVICE_EXEC_START]); + s->exec_command[ci] = exec_command_free_list(s->exec_command[ci]); f = open_memstream(&buf, &size); if (!f) return -ENOMEM; - fputs_unlocked("ExecStart=\n", f); + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + + fputs("ExecStart=\n", f); - LIST_FOREACH(command, c, s->exec_command[SERVICE_EXEC_START]) { - _cleanup_free_ char *a; + LIST_FOREACH(command, c, s->exec_command[ci]) { + _cleanup_free_ char *a = NULL, *t = NULL; + const char *p; - a = strv_join_quoted(c->argv); + p = unit_escape_setting(c->path, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS, &t); + if (!p) + return -ENOMEM; + + a = unit_concat_strv(c->argv, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS); if (!a) return -ENOMEM; - fprintf(f, "ExecStart=%s@%s %s\n", + fprintf(f, "%s=%s@%s %s\n", + name, c->flags & EXEC_COMMAND_IGNORE_FAILURE ? "-" : "", - c->path, + p, a); } r = fflush_and_check(f); if (r < 0) return r; - unit_write_drop_in_private(UNIT(s), mode, name, buf); + + unit_write_setting(UNIT(s), flags, name, buf); } return 1; @@ -340,7 +355,7 @@ int bus_service_set_property( Unit *u, const char *name, sd_bus_message *message, - UnitSetPropertiesMode mode, + UnitWriteFlags flags, sd_bus_error *error) { Service *s = SERVICE(u); @@ -350,22 +365,22 @@ int bus_service_set_property( assert(name); assert(message); - r = bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error); + r = bus_cgroup_set_property(u, &s->cgroup_context, name, message, flags, error); if (r != 0) return r; if (u->transient && u->load_state == UNIT_STUB) { /* This is a transient unit, let's load a little more */ - r = bus_service_set_transient_property(s, name, message, mode, error); + r = bus_service_set_transient_property(s, name, message, flags, error); if (r != 0) return r; - r = bus_exec_context_set_transient_property(u, &s->exec_context, name, message, mode, error); + r = bus_exec_context_set_transient_property(u, &s->exec_context, name, message, flags, error); if (r != 0) return r; - r = bus_kill_context_set_transient_property(u, &s->kill_context, name, message, mode, error); + r = bus_kill_context_set_transient_property(u, &s->kill_context, name, message, flags, error); if (r != 0) return r; } |