From: Lennart Poettering Date: Tue, 1 Aug 2017 09:02:30 +0000 (+0200) Subject: core: introduce unit_set_exec_params() X-Git-Tag: v235~237^2~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f0d477979e0d759c4160df010ec9c44863c7032a;p=platform%2Fupstream%2Fsystemd.git core: introduce unit_set_exec_params() The new unit_set_exec_params() call is to units what manager_set_exec_params() is to the manager object: it initializes the various fields from the relevant generic properties set. --- diff --git a/src/core/mount.c b/src/core/mount.c index 6b04593..d0b0cfe 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -771,9 +771,7 @@ static int mount_spawn(Mount *m, ExecCommand *c, pid_t *_pid) { return r; manager_set_exec_params(UNIT(m)->manager, &exec_params); - - exec_params.cgroup_path = UNIT(m)->cgroup_path; - SET_FLAG(exec_params.flags, EXEC_CGROUP_DELEGATE, m->cgroup_context.delegate); + unit_set_exec_params(UNIT(m), &exec_params); r = exec_spawn(UNIT(m), c, diff --git a/src/core/service.c b/src/core/service.c index a97ebb1..2e94c4a 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -1218,7 +1218,6 @@ static int service_spawn( _cleanup_strv_free_ char **final_env = NULL, **our_env = NULL, **fd_names = NULL; _cleanup_free_ int *fds = NULL; unsigned n_storage_fds = 0, n_socket_fds = 0, n_env = 0; - const char *path; pid_t pid; ExecParameters exec_params = { @@ -1345,16 +1344,16 @@ static int service_spawn( } manager_set_exec_params(UNIT(s)->manager, &exec_params); + unit_set_exec_params(UNIT(s), &exec_params); final_env = strv_env_merge(2, exec_params.environment, our_env, NULL); if (!final_env) return -ENOMEM; if ((flags & EXEC_IS_CONTROL) && UNIT(s)->cgroup_path) { - path = strjoina(UNIT(s)->cgroup_path, "/control"); - (void) cg_create(SYSTEMD_CGROUP_CONTROLLER, path); - } else - path = UNIT(s)->cgroup_path; + exec_params.cgroup_path = strjoina(UNIT(s)->cgroup_path, "/control"); + (void) cg_create(SYSTEMD_CGROUP_CONTROLLER, exec_params.cgroup_path); + } /* System services should get a new keyring by default. */ SET_FLAG(exec_params.flags, EXEC_NEW_KEYRING, MANAGER_IS_SYSTEM(UNIT(s)->manager)); @@ -1363,15 +1362,12 @@ static int service_spawn( SET_FLAG(exec_params.flags, EXEC_NSS_BYPASS_BUS, MANAGER_IS_SYSTEM(UNIT(s)->manager) && unit_has_name(UNIT(s), SPECIAL_DBUS_SERVICE)); - SET_FLAG(exec_params.flags, EXEC_CGROUP_DELEGATE, s->cgroup_context.delegate); - exec_params.argv = c->argv; exec_params.environment = final_env; exec_params.fds = fds; exec_params.fd_names = fd_names; exec_params.n_storage_fds = n_storage_fds; exec_params.n_socket_fds = n_socket_fds; - exec_params.cgroup_path = path; exec_params.watchdog_usec = s->watchdog_usec; exec_params.selinux_context_net = s->socket_fd_selinux_context_net; if (s->type == SERVICE_IDLE) diff --git a/src/core/socket.c b/src/core/socket.c index 078c20f..aed7861 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1791,11 +1791,9 @@ static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) { return r; manager_set_exec_params(UNIT(s)->manager, &exec_params); + unit_set_exec_params(UNIT(s), &exec_params); exec_params.argv = c->argv; - exec_params.cgroup_path = UNIT(s)->cgroup_path; - - SET_FLAG(exec_params.flags, EXEC_CGROUP_DELEGATE, s->cgroup_context.delegate); r = exec_spawn(UNIT(s), c, diff --git a/src/core/swap.c b/src/core/swap.c index 2550768..86995a4 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -637,9 +637,7 @@ static int swap_spawn(Swap *s, ExecCommand *c, pid_t *_pid) { goto fail; manager_set_exec_params(UNIT(s)->manager, &exec_params); - - exec_params.cgroup_path = UNIT(s)->cgroup_path; - SET_FLAG(exec_params.flags, EXEC_CGROUP_DELEGATE, s->cgroup_context.delegate); + unit_set_exec_params(UNIT(s), &exec_params); r = exec_spawn(UNIT(s), c, diff --git a/src/core/unit.c b/src/core/unit.c index a42c667..c6d96c6 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -4399,3 +4399,15 @@ int unit_acquire_invocation_id(Unit *u) { return 0; } + +void unit_set_exec_params(Unit *s, ExecParameters *p) { + CGroupContext *c; + + assert(s); + assert(s); + + p->cgroup_path = s->cgroup_path; + + c = unit_get_cgroup_context(s); + SET_FLAG(p->flags, EXEC_CGROUP_DELEGATE, c && c->delegate); +} diff --git a/src/core/unit.h b/src/core/unit.h index a384f26..4d9751a 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -659,6 +659,8 @@ int unit_acquire_invocation_id(Unit *u); bool unit_shall_confirm_spawn(Unit *u); +void unit_set_exec_params(Unit *s, ExecParameters *p); + /* Macros which append UNIT= or USER_UNIT= to the message */ #define log_unit_full(unit, level, error, ...) \