From bf42811a13dcafb5f0fc5e8e86e56d079fd0a90b Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 13 Nov 2026 16:47:15 +0100 Subject: [PATCH] service: drop a service's group when the configuration drops it Changing a service from @alice:wheel to @alice, or removing group from a block, and reloading kept the service running as group wheel, also after a restart. The group is only set when the configuration has one, and on reload the service is updated in place, so the old one stayed. Clear it before parsing, like a new service gets it. Signed-off-by: Joachim Wiberg --- doc/ChangeLog.md | 3 +++ src/service.c | 1 + test/conf-groups.sh | 31 ++++++++++++++++++++++++++----- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index b10f87d5..78ef9224 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -147,6 +147,9 @@ All relevant changes are documented in this file. `@user:group,sup1,sup2,...`. The list may now be up to 511 characters. Groups dropped from a service's configuration are now also dropped the next time it starts, before they lingered until reboot +- Fix a service's group lingering after it was dropped from the + configuration, e.g. `@alice:wheel` changed to `@alice` kept running as + `wheel` until reboot - `stop:` and `reload:` scripts take a timeout of their own, `stop:5,/path`, defaulting to the kill delay as before. Such a line used to crash Finit at config load diff --git a/src/service.c b/src/service.c index 720d3819..af57948c 100644 --- a/src/service.c +++ b/src/service.c @@ -2492,6 +2492,7 @@ svc_t *service_register_desc(int type, char *cfg, const char *desc, svc_unblock(svc); } + svc->group[0] = 0; svc->supgroups[0] = 0; if (username) { char *ptr = strchr(username, ':'); diff --git a/test/conf-groups.sh b/test/conf-groups.sh index 2e1a3b97..bfc4bb49 100755 --- a/test/conf-groups.sh +++ b/test/conf-groups.sh @@ -1,15 +1,18 @@ #!/bin/sh -# Verify extra-groups sets every listed group on the service, and that -# dropping the setting drops the groups. +# Verify group and extra-groups are set on the service, and that +# dropping either setting drops the group(s) too. set -eu TEST_DIR=$(dirname "$0") -# Optional argument is the extra-groups list +# Optional arguments are the extra-groups list and the group write_conf() { run "echo 'service grp {' > $FINIT_CONF" - run "echo ' group = \"root\"' >> $FINIT_CONF" + run "echo ' user = \"root\"' >> $FINIT_CONF" + if [ -n "${2:-}" ]; then + run "echo ' group = \"$2\"' >> $FINIT_CONF" + fi if [ -n "${1:-}" ]; then run "echo ' extra-groups = { $1 }' >> $FINIT_CONF" fi @@ -25,6 +28,13 @@ assert_groups() "$(texec cat "/proc/$pid/status" | sed -n 's/^Groups:[[:space:]]*//p' | xargs)" = "$1" } +assert_gid() +{ + pid=$(texec initctl -j status grp | jq .pid) + assert "Service gid == $1" \ + "$(texec cat "/proc/$pid/status" | awk '/^Gid:/ {print $2}')" = "$1" +} + test_teardown() { say "Running test teardown." @@ -35,7 +45,7 @@ test_teardown() . "$TEST_DIR/lib/setup.sh" say 'Seven extra groups' -write_conf '"daemon", "bin", "sys", "adm", "tty", "disk", "dialout"' +write_conf '"daemon", "bin", "sys", "adm", "tty", "disk", "dialout"' root run "initctl reload" retry 'assert_num_children 1 serv' @@ -48,3 +58,14 @@ run "initctl reload" run "initctl restart grp" retry 'assert_groups "0"' + +say 'Dropping group drops the group' +write_conf "" adm +run "initctl reload" +run "initctl restart grp" +retry 'assert_gid 4' + +write_conf +run "initctl reload" +run "initctl restart grp" +retry 'assert_gid 0'