mirror of
https://github.com/troglobit/finit.git
synced 2026-11-20 19:41:51 +00:00
service: drop a service's group when the configuration drops it
Changing a service from @alice:wheel to @alice 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>
(cherry picked from commit bf42811a13)
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
3 files changed
+33
-6
No files matched your search
@@ -39,6 +39,9 @@ All relevant changes are documented in this file.
|
||||
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
|
||||
- Remove stale daemon-owned (`pid:!`) pidfiles after unclean exits.
|
||||
When a daemon dies via SIGKILL/OOM/segfault, or exits early during
|
||||
startup, its pidfile lingers and can prevent the next instance from
|
||||
|
||||
@@ -2142,6 +2142,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
svc_unblock(svc);
|
||||
}
|
||||
|
||||
svc->group[0] = 0;
|
||||
svc->supgroups[0] = 0;
|
||||
if (username) {
|
||||
char *ptr = strchr(username, ':');
|
||||
|
||||
+29
-6
@@ -1,14 +1,19 @@
|
||||
#!/bin/sh
|
||||
# Verify supplementary groups, @user:group,sup1,sup2,..., are all set on
|
||||
# the service, and that dropping them drops the groups.
|
||||
# Verify group and supplementary groups, @user:group,sup1,sup2,..., are
|
||||
# set on the service, and that dropping either drops the group(s) too.
|
||||
set -eu
|
||||
|
||||
TEST_DIR=$(dirname "$0")
|
||||
|
||||
# Optional argument is the supplementary group list, ",sup1,sup2,..."
|
||||
# Optional arguments are the group and the supplementary group list,
|
||||
# ",sup1,sup2,...", the latter requires a group
|
||||
write_conf()
|
||||
{
|
||||
run "echo 'service @root:root${1:-} name:grp serv -np -i grp -- Groups' > $FINIT_CONF"
|
||||
user="@root"
|
||||
if [ -n "${1:-}" ]; then
|
||||
user="@root:$1${2:-}"
|
||||
fi
|
||||
run "echo 'service $user name:grp serv -np -i grp -- Groups' > $FINIT_CONF"
|
||||
}
|
||||
|
||||
# Kernel sorts the list, so it compares as a plain string.
|
||||
@@ -19,6 +24,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."
|
||||
@@ -29,7 +41,7 @@ test_teardown()
|
||||
. "$TEST_DIR/lib/setup.sh"
|
||||
|
||||
say 'Seven supplementary groups'
|
||||
write_conf ',daemon,bin,sys,adm,tty,disk,dialout'
|
||||
write_conf root ',daemon,bin,sys,adm,tty,disk,dialout'
|
||||
run "initctl reload"
|
||||
|
||||
retry 'assert_num_children 1 serv'
|
||||
@@ -37,8 +49,19 @@ retry 'assert_groups "0 1 2 3 4 5 6 20"'
|
||||
|
||||
# The running process keeps its groups, the next start drops them
|
||||
say 'Dropping supplementary groups drops the groups'
|
||||
write_conf
|
||||
write_conf root
|
||||
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'
|
||||
Reference in new issue
Block a user