core: introduce unit_set_exec_params()
authorLennart Poettering <lennart@poettering.net>
Tue, 1 Aug 2017 09:02:30 +0000 (11:02 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 10 Aug 2017 13:02:50 +0000 (15:02 +0200)
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.

src/core/mount.c
src/core/service.c
src/core/socket.c
src/core/swap.c
src/core/unit.c
src/core/unit.h

index 6b045939d6237f43f7027efcc80fe8554d009a68..d0b0cfe4b66ed1225e67e73b2a468c18c33c48b7 100644 (file)
@@ -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,
index a97ebb1642a028f77ef08c97578065f625ccf630..2e94c4aea5db970058ea1f7bf302de3721cdad64 100644 (file)
@@ -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)
index 078c20fc91b4edbe5377afd59ec8e6ec67d75b2b..aed78613f68f186893a6b61512d919d0795b2f4c 100644 (file)
@@ -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,
index 255076839a54dfafccd9668fa750acf3d23b4faa..86995a45d01ca2a8ee85e32939e78fee6ae8c799 100644 (file)
@@ -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,
index a42c667754af86da9514213c22040596b6721bce..c6d96c69dc29a4d805a0f14b1420d8f37e82c843 100644 (file)
@@ -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);
+}
index a384f264ee412b87972ab09b5e6452adc24307d5..4d9751a4069c738cb87b5ffe0070e3c65a98aa97 100644 (file)
@@ -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, ...)                          \