1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

Merge pull request #28784 from yuwata/udev-vs-tmpfiles-take-3

Udev vs tmpfiles take 3
This commit is contained in:
Yu Watanabe 2023-08-12 13:12:10 +09:00 committed by GitHub
commit 353c8497b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 87 additions and 11 deletions

View File

@ -19,6 +19,7 @@
<refnamediv>
<refname>systemd-tmpfiles</refname>
<refname>systemd-tmpfiles-setup.service</refname>
<refname>systemd-tmpfiles-setup-dev-early.service</refname>
<refname>systemd-tmpfiles-setup-dev.service</refname>
<refname>systemd-tmpfiles-clean.service</refname>
<refname>systemd-tmpfiles-clean.timer</refname>
@ -35,6 +36,7 @@
<para>System units:
<literallayout><filename>systemd-tmpfiles-setup.service</filename>
<filename>systemd-tmpfiles-setup-dev-early.service</filename>
<filename>systemd-tmpfiles-setup-dev.service</filename>
<filename>systemd-tmpfiles-clean.service</filename>
<filename>systemd-tmpfiles-clean.timer</filename></literallayout></para>
@ -64,6 +66,7 @@
searched for a matching file and the file found that has the highest priority is executed.</para>
<para>System services (<filename>systemd-tmpfiles-setup.service</filename>,
<filename>systemd-tmpfiles-setup-dev-early.service</filename>,
<filename>systemd-tmpfiles-setup-dev.service</filename>,
<filename>systemd-tmpfiles-clean.service</filename>) invoke <command>systemd-tmpfiles</command> to create
system files and to perform system wide cleanup. Those services read administrator-controlled

View File

@ -8,5 +8,9 @@ TEST_NO_NSPAWN=1
# shellcheck source=test/test-functions
. "${TEST_BASE_DIR:?}/test-functions"
test_append_files() {
instmods snd_seq snd_timer tun
generate_module_dependencies
}
do_test "$@"

View File

@ -8,14 +8,50 @@ set -o pipefail
# Tests for issue #28588 and #28653.
assert_in "systemd-tmpfiles-setup-dev.service" "$(systemctl show --property After --value systemd-udevd.service)"
assert_in "systemd-udevd.service" "$(systemctl show --property Before --value systemd-tmpfiles-setup-dev.service)"
# On boot, services need to be started in the following order:
# 1. systemd-tmpfiles-setup-dev-early.service
# 2. systemd-sysusers.service
# 3. systemd-tmpfiles-setup-dev.service
# 4. systemd-udevd.service
assert_in "systemd-tmpfiles-setup.service" "$(systemctl show --property After --value systemd-udevd.service)"
assert_in "systemd-udevd.service" "$(systemctl show --property Before --value systemd-tmpfiles-setup.service)"
output="$(systemctl show --property After --value systemd-udevd.service)"
assert_in "systemd-tmpfiles-setup-dev-early.service" "$output"
assert_in "systemd-sysusers.service" "$output"
assert_in "systemd-tmpfiles-setup-dev.service" "$output"
if [[ -f /dev/vfio/vfio ]]; then
assert_in "crw-rw-rw-" "$(stat --format=%A /dev/vfio/vfio)"
fi
output="$(systemctl show --property After --value systemd-tmpfiles-setup-dev.service)"
assert_in "systemd-tmpfiles-setup-dev-early.service" "$output"
assert_in "systemd-sysusers.service" "$output"
output="$(systemctl show --property After --value systemd-sysusers.service)"
assert_in "systemd-tmpfiles-setup-dev-early.service" "$output"
check_owner_and_mode() {
local dev=${1?}
local user=${2?}
local group=${3?}
local mode=${4:-}
if [[ -e "$dev" ]]; then
assert_in "$user" "$(stat --format=%U "$dev")"
assert_in "$group" "$(stat --format=%G "$dev")"
if [[ -n "$mode" ]]; then
assert_in "$mode" "$(stat --format=%#0a "$dev")"
fi
fi
return 0
}
# Check owner and access mode specified in static-nodes-permissions.conf
check_owner_and_mode /dev/snd/seq root audio 0660
check_owner_and_mode /dev/snd/timer root audio 0660
check_owner_and_mode /dev/loop-control root disk 0660
check_owner_and_mode /dev/net/tun root root 0666
check_owner_and_mode /dev/fuse root root 0666
check_owner_and_mode /dev/vfio/vfio root root 0666
check_owner_and_mode /dev/kvm root kvm
check_owner_and_mode /dev/vhost-net root kvm
check_owner_and_mode /dev/vhost-vsock root kvm
exit 0

View File

@ -10,7 +10,7 @@
[Unit]
Description=Create List of Static Device Nodes
DefaultDependencies=no
Before=sysinit.target systemd-tmpfiles-setup-dev.service
Before=sysinit.target systemd-tmpfiles-setup-dev-early.service
ConditionCapability=CAP_SYS_MODULE
ConditionFileNotEmpty=/lib/modules/%v/modules.devname

View File

@ -544,6 +544,11 @@ units = [
'conditions' : ['ENABLE_TMPFILES'],
'symlinks' : ['timers.target.wants/'],
},
{
'file' : 'systemd-tmpfiles-setup-dev-early.service',
'conditions' : ['ENABLE_TMPFILES'],
'symlinks' : ['sysinit.target.wants/'],
},
{
'file' : 'systemd-tmpfiles-setup-dev.service',
'conditions' : ['ENABLE_TMPFILES'],

View File

@ -16,6 +16,8 @@ ConditionCredential=|sysusers.extra
DefaultDependencies=no
After=systemd-remount-fs.service
After=systemd-tmpfiles-setup-dev-early.service
Before=systemd-tmpfiles-setup-dev.service
Before=sysinit.target systemd-update-done.service
Conflicts=shutdown.target initrd-switch-root.target
Before=shutdown.target initrd-switch-root.target

View File

@ -0,0 +1,25 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Create Static Device Nodes in /dev gracefully
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)
DefaultDependencies=no
Before=sysinit.target local-fs-pre.target systemd-udevd.service
Wants=local-fs-pre.target
Conflicts=shutdown.target initrd-switch-root.target
Before=shutdown.target initrd-switch-root.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=systemd-tmpfiles --prefix=/dev --create --boot --graceful
SuccessExitStatus=DATAERR CANTCREAT
ImportCredential=tmpfiles.*

View File

@ -12,6 +12,7 @@ Description=Create Static Device Nodes in /dev
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)
DefaultDependencies=no
After=systemd-tmpfiles-setup-dev-early.service
Before=sysinit.target local-fs-pre.target systemd-udevd.service
Wants=local-fs-pre.target
Conflicts=shutdown.target initrd-switch-root.target
@ -20,6 +21,6 @@ Before=shutdown.target initrd-switch-root.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=systemd-tmpfiles --prefix=/dev --create --boot --graceful
ExecStart=systemd-tmpfiles --prefix=/dev --create --boot
SuccessExitStatus=DATAERR CANTCREAT
ImportCredential=tmpfiles.*

View File

@ -13,7 +13,7 @@ Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)
DefaultDependencies=no
After=local-fs.target systemd-sysusers.service systemd-journald.service
Before=sysinit.target systemd-udevd.service
Before=sysinit.target
Conflicts=shutdown.target initrd-switch-root.target
Before=shutdown.target initrd-switch-root.target
RefuseManualStop=yes
@ -21,7 +21,7 @@ RefuseManualStop=yes
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=systemd-tmpfiles --create --remove --boot
ExecStart=systemd-tmpfiles --create --remove --boot --exclude-prefix=/dev
SuccessExitStatus=DATAERR CANTCREAT
ImportCredential=tmpfiles.*
ImportCredential=login.motd