]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: rename and add comment to ExecParameters cleanup functions
authorLuca Boccassi <bluca@debian.org>
Thu, 26 Oct 2023 20:55:55 +0000 (21:55 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 1 Nov 2023 03:43:22 +0000 (12:43 +0900)
src/core/execute.c
src/core/execute.h
src/core/executor.c
src/core/fuzz-execute-serialize.c
src/core/mount.c
src/core/service.c
src/core/socket.c
src/core/swap.c

index f220e9ee5e894e75fbe05d4a11b103b10d594189..e83a2ab239f78ca648a558497e4bef8d56e8d877 100644 (file)
@@ -2464,10 +2464,13 @@ void exec_runtime_clear(ExecRuntime *rt) {
         rt->ephemeral_copy = mfree(rt->ephemeral_copy);
 }
 
-void exec_params_clear(ExecParameters *p) {
+void exec_params_shallow_clear(ExecParameters *p) {
         if (!p)
                 return;
 
+        /* This is called on the PID1 side, as many of the struct's FDs are only borrowed, and actually
+         * owned by the manager or other objects, and reused across multiple units. */
+
         p->environment = strv_free(p->environment);
         p->fd_names = strv_free(p->fd_names);
         p->files_env = strv_free(p->files_env);
@@ -2481,10 +2484,14 @@ void exec_params_clear(ExecParameters *p) {
         p->confirm_spawn = mfree(p->confirm_spawn);
 }
 
-void exec_params_serialized_done(ExecParameters *p) {
+void exec_params_deep_clear(ExecParameters *p) {
         if (!p)
                 return;
 
+        /* This is called on the sd-executor side, where everything received is owned by the process and has
+         * to be fully cleaned up to make sanitizers and analyzers happy, as opposed as the shallow clean
+         * function above. */
+
         close_many_unset(p->fds, p->n_socket_fds + p->n_storage_fds);
 
         p->cgroup_path = mfree(p->cgroup_path);
@@ -2512,7 +2519,7 @@ void exec_params_serialized_done(ExecParameters *p) {
 
         p->fallback_smack_process_label = mfree(p->fallback_smack_process_label);
 
-        exec_params_clear(p);
+        exec_params_shallow_clear(p);
 }
 
 void exec_directory_done(ExecDirectory *d) {
index 16295da1864e13b76f72a5db69ec028614983130..4896a42492318b25469299d2d195eb092c265249 100644 (file)
@@ -552,9 +552,9 @@ ExecRuntime* exec_runtime_destroy(ExecRuntime *rt);
 void exec_runtime_clear(ExecRuntime *rt);
 
 int exec_params_get_cgroup_path(const ExecParameters *params, const CGroupContext *c, char **ret);
-void exec_params_clear(ExecParameters *p);
+void exec_params_shallow_clear(ExecParameters *p);
 void exec_params_dump(const ExecParameters *p, FILE* f, const char *prefix);
-void exec_params_serialized_done(ExecParameters *p);
+void exec_params_deep_clear(ExecParameters *p);
 
 bool exec_context_get_cpu_affinity_from_numa(const ExecContext *c);
 
index a7fb3112928c559902fe32eb88f24d9f274eb9b7..e19e8718162d54f62be4f0c38a567fa66cdf98a1 100644 (file)
@@ -178,7 +178,7 @@ int main(int argc, char *argv[]) {
         _cleanup_(cgroup_context_done) CGroupContext cgroup_context = {};
         _cleanup_(exec_context_done) ExecContext context = {};
         _cleanup_(exec_command_done) ExecCommand command = {};
-        _cleanup_(exec_params_serialized_done) ExecParameters params = EXEC_PARAMETERS_INIT(/* flags= */ 0);
+        _cleanup_(exec_params_deep_clear) ExecParameters params = EXEC_PARAMETERS_INIT(/* flags= */ 0);
         _cleanup_(exec_shared_runtime_done) ExecSharedRuntime shared = {
                 .netns_storage_socket = EBADF_PAIR,
                 .ipcns_storage_socket = EBADF_PAIR,
index d71fb487e5a93fd5199b80bc3c5d1aca98b7f3f0..862b525974ba461e13496c520f63e1dfa0f2c369 100644 (file)
 #include "service.h"
 
 static void exec_fuzz_one(FILE *f, FDSet *fdset) {
-        _cleanup_(exec_params_serialized_done) ExecParameters params = {
-                .stdin_fd         = -EBADF,
-                .stdout_fd        = -EBADF,
-                .stderr_fd        = -EBADF,
-                .exec_fd          = -EBADF,
-                .user_lookup_fd   = -EBADF,
-                .bpf_outer_map_fd = -EBADF,
-        };
+        _cleanup_(exec_params_deep_clear) ExecParameters params = EXEC_PARAMETERS_INIT(/* flags= */ 0);
         _cleanup_(exec_context_done) ExecContext exec_context = {};
         _cleanup_(cgroup_context_done) CGroupContext cgroup_context = {};
         DynamicCreds dynamic_creds = {};
index 140286792a25a07f1db20dc37c903ea730b72dbc..ded322d33230535bb9f8deb79a0bd0093ea517b9 100644 (file)
@@ -908,7 +908,7 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) {
 
 static int mount_spawn(Mount *m, ExecCommand *c, PidRef *ret_pid) {
 
-        _cleanup_(exec_params_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT(
+        _cleanup_(exec_params_shallow_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT(
                         EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN);
         _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
         pid_t pid;
index c63576ce790eace0ce7d6a8f2bb8e3bee29599ae..d3e8d458544ec0325c76f25a80e2ff6074985795 100644 (file)
@@ -1611,7 +1611,7 @@ static int service_spawn_internal(
                 ExecFlags flags,
                 PidRef *ret_pid) {
 
-        _cleanup_(exec_params_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT(flags);
+        _cleanup_(exec_params_shallow_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT(flags);
         _cleanup_(sd_event_source_unrefp) sd_event_source *exec_fd_source = NULL;
         _cleanup_strv_free_ char **final_env = NULL, **our_env = NULL;
         _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
index 55de5f96eb56c2c3c95eb41aba8b6ec3e6627a15..156ac4a2d59df6e60efe71ebb98427d8a4032771 100644 (file)
@@ -1913,7 +1913,7 @@ static int socket_coldplug(Unit *u) {
 
 static int socket_spawn(Socket *s, ExecCommand *c, PidRef *ret_pid) {
 
-        _cleanup_(exec_params_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT(
+        _cleanup_(exec_params_shallow_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT(
                         EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN);
         _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
         pid_t pid;
index 3a9f0e798dd11bf104c2433b3de004b7cb5e72b3..488b1719c53c4b5c16e5509001b0d68f96ec8264 100644 (file)
@@ -632,7 +632,7 @@ static void swap_dump(Unit *u, FILE *f, const char *prefix) {
 
 static int swap_spawn(Swap *s, ExecCommand *c, PidRef *ret_pid) {
 
-        _cleanup_(exec_params_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT(
+        _cleanup_(exec_params_shallow_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT(
                         EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN);
         _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
         pid_t pid;