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 <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-17 06:21:25 +01:00
1 parent de73b06415
commit bf42811a13
3 files changed
+30 -5

No files matched your search

+3
View File
@@ -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
+1
View File
@@ -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, ':');
+26 -5
View File
@@ -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'