Ensure all a process' children are in the same cgroup

The logger redirection process was sometimes in the init group instead
of the system/<svc>/ group.  This was due to the parent PID being moved
after the logger was forked.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2023-03-21 16:32:28 +01:00
1 parent 9ee2be121f
commit 3bb826b22b
1 file changed
+6 -6
+6 -6
View File
@@ -657,8 +657,13 @@ static int service_start(svc_t *svc)
char *args[MAX_NUM_SVC_ARGS + 1];
int status;
if (!svc_is_tty(svc))
pid = getpid();
if (svc_is_tty(svc)) {
cgroup_user("getty", pid);
} else {
cgroup_service(group_name(svc, grnam, sizeof(grnam)), pid, &svc->cgroup);
redirect(svc);
}
if (!svc_is_sysv(svc)) {
wordexp_t we = { 0 };
@@ -806,11 +811,6 @@ static int service_start(svc_t *svc)
dbg("Starting PID %d: %s", svc->pid, cmdline);
}
if (svc_is_tty(svc))
cgroup_user("getty", pid);
else
cgroup_service(group_name(svc, grnam, sizeof(grnam)), pid, &svc->cgroup);
if (!svc_is_sysv(svc))
logit(LOG_CONSOLE | LOG_NOTICE, "Starting %s[%d]", svc_ident(svc, NULL, 0), pid);