]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/unit: add unit_fork_helper_process_full() that takes ForkFlags
authorMike Yuan <me@yhndnzj.com>
Tue, 16 Dec 2025 01:07:22 +0000 (02:07 +0100)
committerMike Yuan <me@yhndnzj.com>
Tue, 16 Dec 2025 20:30:36 +0000 (21:30 +0100)
src/basic/basic-forward.h
src/core/unit.c
src/core/unit.h

index 0f8c3ea06c8bbc376b78e4a954d9d6ce39638af0..d26cc5fe9b2a4afe4ac7058912e3057f65a6ca53 100644 (file)
@@ -86,6 +86,7 @@ typedef enum CGroupFlags CGroupFlags;
 typedef enum CGroupMask CGroupMask;
 typedef enum ChaseFlags ChaseFlags;
 typedef enum ExtractFlags ExtractFlags;
+typedef enum ForkFlags ForkFlags;
 typedef enum Glyph Glyph;
 typedef enum ImageClass ImageClass;
 typedef enum JobMode JobMode;
index f37b12ac622d2608c3043f5d7a75f5a16733e63a..7161c1cb6c44d55eb3462a5298c291653a85a2a3 100644 (file)
@@ -5539,12 +5539,13 @@ int unit_set_exec_params(Unit *u, ExecParameters *p) {
         return 0;
 }
 
-int unit_fork_helper_process(Unit *u, const char *name, bool into_cgroup, PidRef *ret) {
+int unit_fork_helper_process_full(Unit *u, const char *name, bool into_cgroup, ForkFlags flags, PidRef *ret) {
         CGroupRuntime *crt = NULL;
         pid_t pid;
         int r;
 
         assert(u);
+        assert((flags & (FORK_RESET_SIGNALS|FORK_DETACH|FORK_WAIT)) == 0); /* these don't really make sense for manager */
         assert(ret);
 
         /* Forks off a helper process and makes sure it is a member of the unit's cgroup, if configured to
@@ -5559,7 +5560,7 @@ int unit_fork_helper_process(Unit *u, const char *name, bool into_cgroup, PidRef
                 crt = unit_get_cgroup_runtime(u);
         }
 
-        r = safe_fork(name, FORK_REOPEN_LOG|FORK_DEATHSIG_SIGTERM, &pid);
+        r = safe_fork(name, FORK_REOPEN_LOG|FORK_DEATHSIG_SIGTERM|flags, &pid);
         if (r < 0)
                 return r;
         if (r > 0) {
@@ -5592,6 +5593,10 @@ int unit_fork_helper_process(Unit *u, const char *name, bool into_cgroup, PidRef
         return 0;
 }
 
+int unit_fork_helper_process(Unit *u, const char *name, bool into_cgroup, PidRef *ret) {
+        return unit_fork_helper_process_full(u, name, into_cgroup, /* flags = */ 0, ret);
+}
+
 int unit_fork_and_watch_rm_rf(Unit *u, char **paths, PidRef *ret_pid) {
         _cleanup_(pidref_done) PidRef pid = PIDREF_NULL;
         int r;
index b3e0f95e996ebb16d17a509376ba549433fad663..dc546116f9965f1546477bd25d50209f5a575175 100644 (file)
@@ -1005,6 +1005,7 @@ int unit_acquire_invocation_id(Unit *u);
 
 int unit_set_exec_params(Unit *u, ExecParameters *p);
 
+int unit_fork_helper_process_full(Unit *u, const char *name, bool into_cgroup, ForkFlags flags, PidRef *ret);
 int unit_fork_helper_process(Unit *u, const char *name, bool into_cgroup, PidRef *ret);
 int unit_fork_and_watch_rm_rf(Unit *u, char **paths, PidRef *ret);