2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4 PATH
=/sbin
:/bin
:/usr
/sbin
:/usr
/bin
7 LOOKS_LIKE_DEBIAN
=$
(source /etc
/os-release
&& [[ "$ID" = "debian" ||
" $ID_LIKE " = *" debian "* ]] && echo yes || true
)
8 LOOKS_LIKE_ARCH
=$
(source /etc
/os-release
&& [[ "$ID" = "arch" ||
" $ID_LIKE " = *" arch "* ]] && echo yes || true
)
9 LOOKS_LIKE_SUSE
=$
(source /etc
/os-release
&& [[ " $ID_LIKE " = *" suse "* ]] && echo yes || true
)
10 KERNEL_VER
=${KERNEL_VER-$(uname -r)}
11 KERNEL_MODS
="/lib/modules/$KERNEL_VER/"
12 QEMU_TIMEOUT
="${QEMU_TIMEOUT:-infinity}"
13 NSPAWN_TIMEOUT
="${NSPAWN_TIMEOUT:-infinity}"
14 TIMED_OUT
= # will be 1 after run_* if *_TIMEOUT is set and test timed out
15 [[ "$LOOKS_LIKE_SUSE" ]] && FSTYPE
="${FSTYPE:-btrfs}" || FSTYPE
="${FSTYPE:-ext4}"
16 UNIFIED_CGROUP_HIERARCHY
="${UNIFIED_CGROUP_HIERARCHY:-default}"
17 EFI_MOUNT
="$(bootctl -p 2>/dev/null || echo /boot)"
19 if ! ROOTLIBDIR
=$
(pkg-config
--variable=systemdutildir systemd
); then
20 echo "WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&2
21 ROOTLIBDIR
=/usr
/lib
/systemd
24 PATH_TO_INIT
=$ROOTLIBDIR/systemd
26 BASICTOOLS
="test sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm true false chmod chown ln xargs"
27 DEBUGTOOLS
="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname find"
29 STATEDIR
="${BUILD_DIR:-.}/test/$(basename $(dirname $(realpath $0)))"
30 STATEFILE
="$STATEDIR/.testdir"
31 TESTLOG
="$STATEDIR/test.log"
33 is_built_with_asan
() {
34 if ! type -P objdump
>/dev
/null
; then
35 ddebug
"Failed to find objdump. Assuming systemd hasn't been built with ASAN."
39 # Borrowed from https://github.com/google/oss-fuzz/blob/cd9acd02f9d3f6e80011cc1e9549be526ce5f270/infra/base-images/base-runner/bad_build_check#L182
40 local _asan_calls
=$
(objdump
-dC $BUILD_DIR/systemd-journald |
egrep "callq\s+[0-9a-f]+\s+<__asan" -c)
41 if (( $_asan_calls < 1000 )); then
48 IS_BUILT_WITH_ASAN
=$
(is_built_with_asan
&& echo yes ||
echo no
)
50 if [[ "$IS_BUILT_WITH_ASAN" = "yes" ]]; then
53 PATH_TO_INIT
=$ROOTLIBDIR/systemd-under-asan
56 function find_qemu_bin
() {
57 # SUSE and Red Hat call the binary qemu-kvm. Debian and Gentoo call it kvm.
58 # Either way, only use this version if we aren't running in KVM, because
59 # nested KVM is flaky still.
60 if [ `systemd-detect-virt -v` != kvm
] ; then
61 [ "$QEMU_BIN" ] || QEMU_BIN
=$
(which -a kvm qemu-kvm
2>/dev
/null |
grep '^/' -m1)
64 [ "$ARCH" ] || ARCH
=$
(uname
-m)
67 # QEMU's own build system calls it qemu-system-x86_64
68 [ "$QEMU_BIN" ] || QEMU_BIN
=$
(which -a qemu-system-x86_64
2>/dev
/null |
grep '^/' -m1)
71 # new i386 version of QEMU
72 [ "$QEMU_BIN" ] || QEMU_BIN
=$
(which -a qemu-system-i386
2>/dev
/null |
grep '^/' -m1)
74 # i386 version of QEMU
75 [ "$QEMU_BIN" ] || QEMU_BIN
=$
(which -a qemu
2>/dev
/null |
grep '^/' -m1)
78 [ "$QEMU_BIN" ] || QEMU_BIN
=$
(which -a qemu-system-
$ARCH 2>/dev
/null |
grep '^/' -m1)
82 if [ ! -e "$QEMU_BIN" ]; then
83 echo "Could not find a suitable QEMU binary" >&2
88 # Return 0 if QEMU did run (then you must check the result state/logs for actual
89 # success), or 1 if QEMU is not available.
91 if [ -f /etc
/machine-id
]; then
92 read MACHINE_ID
< /etc
/machine-id
93 [ -z "$INITRD" ] && [ -e "$EFI_MOUNT/$MACHINE_ID/$KERNEL_VER/initrd" ] \
94 && INITRD
="$EFI_MOUNT/$MACHINE_ID/$KERNEL_VER/initrd"
95 [ -z "$KERNEL_BIN" ] && [ -e "$EFI_MOUNT/$MACHINE_ID/$KERNEL_VER/linux" ] \
96 && KERNEL_BIN
="$EFI_MOUNT/$MACHINE_ID/$KERNEL_VER/linux"
99 if [[ ! "$KERNEL_BIN" ]]; then
100 if [[ "$LOOKS_LIKE_ARCH" ]]; then
101 KERNEL_BIN
=/boot
/vmlinuz-linux
103 KERNEL_BIN
=/boot
/vmlinuz-
$KERNEL_VER
107 default_fedora_initrd
=/boot
/initramfs-
${KERNEL_VER}.img
108 default_debian_initrd
=/boot
/initrd.img-
${KERNEL_VER}
109 default_arch_initrd
=/boot
/initramfs-linux.img
110 default_suse_initrd
=/boot
/initrd-
${KERNEL_VER}
111 if [[ ! "$INITRD" ]]; then
112 if [[ -e "$default_fedora_initrd" ]]; then
113 INITRD
="$default_fedora_initrd"
114 elif [[ "$LOOKS_LIKE_DEBIAN" && -e "$default_debian_initrd" ]]; then
115 INITRD
="$default_debian_initrd"
116 elif [[ "$LOOKS_LIKE_ARCH" && -e "$default_arch_initrd" ]]; then
117 INITRD
="$default_arch_initrd"
118 elif [[ "$LOOKS_LIKE_SUSE" && -e "$default_suse_initrd" ]]; then
119 INITRD
="$default_suse_initrd"
123 [ "$QEMU_SMP" ] || QEMU_SMP
=1
125 find_qemu_bin ||
return 1
128 if [[ "$UNIFIED_CGROUP_HIERARCHY" = "yes" ]]; then
129 _cgroup_args
="systemd.unified_cgroup_hierarchy=yes"
130 elif [[ "$UNIFIED_CGROUP_HIERARCHY" = "no" ]]; then
131 _cgroup_args
="systemd.unified_cgroup_hierarchy=no systemd.legacy_systemd_cgroup_controller=yes"
132 elif [[ "$UNIFIED_CGROUP_HIERARCHY" = "hybrid" ]]; then
133 _cgroup_args
="systemd.unified_cgroup_hierarchy=no systemd.legacy_systemd_cgroup_controller=no"
134 elif [[ "$UNIFIED_CGROUP_HIERARCHY" != "default" ]]; then
135 dfatal
"Unknown UNIFIED_CGROUP_HIERARCHY. Got $UNIFIED_CGROUP_HIERARCHY, expected [yes|no|hybrid|default]"
139 if [[ "$LOOKS_LIKE_SUSE" ]]; then
140 PARAMS
+="rd.hostonly=0"
145 KERNEL_APPEND
="$PARAMS \
157 QEMU_OPTIONS
="-smp $QEMU_SMP \
161 -kernel $KERNEL_BIN \
162 -drive format=raw,cache=unsafe,file=${TESTDIR}/rootdisk.img \
165 if [[ "$INITRD" && "$SKIP_INITRD" != "yes" ]]; then
166 QEMU_OPTIONS
="$QEMU_OPTIONS -initrd $INITRD"
169 # Let's use KVM if it is available, but let's avoid using nested KVM as that is still flaky
170 if [ -c /dev
/kvm
-a `systemd-detect-virt -v` != kvm
]; then
171 QEMU_OPTIONS
="$QEMU_OPTIONS -machine accel=kvm -enable-kvm -cpu host"
174 if [[ "$QEMU_TIMEOUT" != "infinity" ]]; then
175 QEMU_BIN
="timeout --foreground $QEMU_TIMEOUT $QEMU_BIN"
177 (set -x; $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND")
179 if [ "$rc" = 124 ] && [ "$QEMU_TIMEOUT" != "infinity" ]; then
180 derror
"test timed out after $QEMU_TIMEOUT s"
183 [ "$rc" != 0 ] && derror
"QEMU failed with exit code $rc"
188 # Return 0 if nspawn did run (then you must check the result state/logs for actual
189 # success), or 1 if nspawn is not available.
191 [[ -d /run
/systemd
/system
]] ||
return 1
193 local _nspawn_cmd
="$BUILD_DIR/systemd-nspawn $NSPAWN_ARGUMENTS --register=no --kill-signal=SIGKILL --directory=$TESTDIR/$1 $PATH_TO_INIT $KERNEL_APPEND"
194 if [[ "$NSPAWN_TIMEOUT" != "infinity" ]]; then
195 _nspawn_cmd
="timeout --foreground $NSPAWN_TIMEOUT $_nspawn_cmd"
198 if [[ "$UNIFIED_CGROUP_HIERARCHY" = "hybrid" ]]; then
199 dwarn
"nspawn doesn't support UNIFIED_CGROUP_HIERARCHY=hybrid, skipping"
201 elif [[ "$UNIFIED_CGROUP_HIERARCHY" = "yes" ||
"$UNIFIED_CGROUP_HIERARCHY" = "no" ]]; then
202 _nspawn_cmd
="env UNIFIED_CGROUP_HIERARCHY=$UNIFIED_CGROUP_HIERARCHY $_nspawn_cmd"
203 elif [[ "$UNIFIED_CGROUP_HIERARCHY" = "default" ]]; then
204 _nspawn_cmd
="env --unset=UNIFIED_CGROUP_HIERARCHY $_nspawn_cmd"
206 dfatal
"Unknown UNIFIED_CGROUP_HIERARCHY. Got $UNIFIED_CGROUP_HIERARCHY, expected [yes|no|hybrid|default]"
210 (set -x; $_nspawn_cmd)
212 if [ "$rc" = 124 ] && [ "$NSPAWN_TIMEOUT" != "infinity" ]; then
213 derror
"test timed out after $NSPAWN_TIMEOUT s"
216 [ "$rc" != 0 ] && derror
"nspawn failed with exit code $rc"
221 setup_basic_environment
() {
222 # create the basic filesystem layout
226 install_missing_libraries
244 generate_module_dependencies
245 if [[ "$IS_BUILT_WITH_ASAN" = "yes" ]]; then
251 # don't forget KERNEL_APPEND='... selinux=1 ...'
252 if [[ "$SETUP_SELINUX" != "yes" ]]; then
253 ddebug
"Don't setup SELinux"
256 ddebug
"Setup SELinux"
257 local _conf_dir
=/etc
/selinux
258 local _fixfiles_tools
="bash uname cat sort uniq awk grep egrep head expr find rm secon setfiles"
260 rm -rf $initdir/$_conf_dir
261 if ! cp -ar $_conf_dir $initdir/$_conf_dir; then
262 dfatal
"Failed to copy $_conf_dir"
266 cat <<EOF >$initdir/etc/systemd/system/autorelabel.service
268 Description=Relabel all filesystems
269 DefaultDependencies=no
270 Requires=local-fs.target
271 Conflicts=shutdown.target
272 After=local-fs.target
273 Before=sysinit.target shutdown.target
274 ConditionSecurity=selinux
275 ConditionPathExists=|/.autorelabel
278 ExecStart=/bin/sh -x -c 'echo 0 >/sys/fs/selinux/enforce && fixfiles -f -F relabel && rm /.autorelabel && systemctl --force reboot'
284 touch $initdir/.autorelabel
285 mkdir
-p $initdir/etc
/systemd
/system
/basic.target.wants
286 ln -fs autorelabel.service
$initdir/etc
/systemd
/system
/basic.target.wants
/autorelabel.service
288 dracut_install
$_fixfiles_tools
289 dracut_install fixfiles
290 dracut_install sestatus
294 if ! type -p valgrind
; then
295 dfatal
"Failed to install valgrind"
299 local _valgrind_bins
=$
(strace
-e execve valgrind
/bin
/true
2>&1 >/dev
/null | perl
-lne 'print $1 if /^execve\("([^"]+)"/')
300 dracut_install
$_valgrind_bins
302 local _valgrind_libs
=$
(LD_DEBUG
=files valgrind
/bin
/true
2>&1 >/dev
/null | perl
-lne 'print $1 if m{calling init: (/.*vgpreload_.*)}')
303 dracut_install
$_valgrind_libs
305 local _valgrind_dbg_and_supp
=$
(
306 strace
-e open valgrind
/bin
/true
2>&1 >/dev
/null |
307 perl
-lne 'if (my ($fname) = /^open\("([^"]+).*= (?!-)\d+/) { print $fname if $fname =~ /debug|\.supp$/ }'
309 dracut_install
$_valgrind_dbg_and_supp
312 create_valgrind_wrapper
() {
313 local _valgrind_wrapper
=$initdir/$ROOTLIBDIR/systemd-under-valgrind
314 ddebug
"Create $_valgrind_wrapper"
315 cat >$_valgrind_wrapper <<EOF
318 mount -t proc proc /proc
319 exec valgrind --leak-check=full --log-file=/valgrind.out $ROOTLIBDIR/systemd "\$@"
321 chmod 0755 $_valgrind_wrapper
324 create_asan_wrapper
() {
325 local _asan_wrapper
=$initdir/$ROOTLIBDIR/systemd-under-asan
326 ddebug
"Create $_asan_wrapper"
327 cat >$_asan_wrapper <<EOF
332 DEFAULT_ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1
333 DEFAULT_UBSAN_OPTIONS=print_stacktrace=1:print_summary=1
334 DEFAULT_ENVIRONMENT="ASAN_OPTIONS=\$DEFAULT_ASAN_OPTIONS UBSAN_OPTIONS=\$DEFAULT_UBSAN_OPTIONS:halt_on_error=1"
336 mount -t proc proc /proc
337 mount -t sysfs sysfs /sys
338 mount -o remount,rw /
340 PATH_TO_ASAN=\$(find / -name '*libasan*' | sed 1q)
341 if [[ "\$PATH_TO_ASAN" ]]; then
342 # A lot of services (most notably dbus) won't start without preloading libasan
343 # See https://github.com/systemd/systemd/issues/5004
344 DEFAULT_ENVIRONMENT="\$DEFAULT_ENVIRONMENT LD_PRELOAD=\$PATH_TO_ASAN"
346 echo DefaultEnvironment=\$DEFAULT_ENVIRONMENT >>/etc/systemd/system.conf
347 echo DefaultTimeoutStartSec=180s >>/etc/systemd/system.conf
349 # ASAN and syscall filters aren't compatible with each other.
350 find / -name '*.service' -type f | xargs sed -i 's/^\\(MemoryDeny\\|SystemCall\\)/#\\1/'
352 # The redirection of ASAN reports to a file prevents them from ending up in /dev/null.
353 # But, apparently, sometimes it doesn't work: https://github.com/google/sanitizers/issues/886.
354 JOURNALD_CONF_DIR=/etc/systemd/system/systemd-journald.service.d
355 mkdir -p "\$JOURNALD_CONF_DIR"
356 printf "[Service]\nEnvironment=ASAN_OPTIONS=\$DEFAULT_ASAN_OPTIONS:log_path=/systemd-journald.asan.log\n" >"\$JOURNALD_CONF_DIR/env.conf"
358 # 90s isn't enough for some services to finish when literally everything is run
359 # under ASan+UBSan in containers, which, in turn, are run in VMs.
360 mkdir -p /etc/systemd/system/systemd-hwdb-update.service.d
361 printf "[Service]\nTimeoutSec=180s\n" >/etc/systemd/system/systemd-hwdb-update.service.d/timeout.conf
363 export ASAN_OPTIONS=\$DEFAULT_ASAN_OPTIONS:log_path=/systemd.asan.log UBSAN_OPTIONS=\$DEFAULT_UBSAN_OPTIONS
364 exec $ROOTLIBDIR/systemd "\$@"
367 chmod 0755 $_asan_wrapper
370 create_strace_wrapper
() {
371 local _strace_wrapper
=$initdir/$ROOTLIBDIR/systemd-under-strace
372 ddebug
"Create $_strace_wrapper"
373 cat >$_strace_wrapper <<EOF
376 exec strace -D -o /strace.out $ROOTLIBDIR/systemd "\$@"
378 chmod 0755 $_strace_wrapper
382 dracut_install
/sbin
/fsck
*
383 dracut_install
-o /bin
/fsck
*
385 # fskc.reiserfs calls reiserfsck. so, install it
386 dracut_install
-o reiserfsck
390 instmods dm_crypt
=crypto
391 type -P dmeventd
>/dev
/null
&& dracut_install dmeventd
392 inst_libdir_file
"libdevmapper-event.so*"
393 if [[ "$LOOKS_LIKE_DEBIAN" ]]; then
394 # dmsetup installs 55-dm and 60-persistent-storage-dm on Debian/Ubuntu
395 # and since buster/bionic 95-dm-notify.rules
396 # see https://gitlab.com/debian-lvm/lvm2/blob/master/debian/patches/udev.patch
397 inst_rules
55-dm.rules
60-persistent-storage-dm.rules
95-dm-notify.rules
399 inst_rules
10-dm.rules
13-dm-disk.rules
95-dm-notify.rules
404 # install compiled files
405 local _ninja_bin
=$
(type -P ninja ||
type -P ninja-build
)
406 if [[ -z "$_ninja_bin" ]]; then
407 dfatal
"ninja was not found"
410 (set -x; DESTDIR
=$initdir "$_ninja_bin" -C $BUILD_DIR install)
411 # remove unneeded documentation
412 rm -fr $initdir/usr
/share
/{man
,doc
}
413 # we strip binaries since debug symbols increase binaries size a lot
414 # and it could fill the available space
417 [[ "$LOOKS_LIKE_SUSE" ]] && setup_suse
419 # enable debug logging in PID1
420 echo LogLevel
=debug
>> $initdir/etc
/systemd
/system.conf
425 objdump
-p "$_bin" 2>/dev
/null |
awk "/R(UN)?PATH/ { print \"$initdir\" \$2 }" |
paste -sd :
428 install_missing_libraries
() {
429 # install possible missing libraries
430 for i
in $initdir{,/usr
}/{sbin
,bin
}/* $initdir{,/usr
}/lib
/systemd
/{,tests
/{,manual
/,unsafe
/}}*; do
431 LD_LIBRARY_PATH
=$
(get_ldpath
$i) inst_libs
$i
435 create_empty_image
() {
437 if [[ "$STRIP_BINARIES" = "no" ]]; then
440 rm -f "$TESTDIR/rootdisk.img"
441 # Create the blank file to use as a root filesystem
442 dd if=/dev
/null of
="$TESTDIR/rootdisk.img" bs
=1M seek
="$_size"
443 LOOPDEV
=$
(losetup
--show -P -f $TESTDIR/rootdisk.img
)
444 [ -b "$LOOPDEV" ] ||
return 1
445 echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
446 sfdisk
"$LOOPDEV" <<EOF
453 local _label
="-L systemd"
454 # mkfs.reiserfs doesn't know -L. so, use --label instead
455 [[ "$FSTYPE" == "reiserfs" ]] && _label
="--label systemd"
456 if ! mkfs
-t "${FSTYPE}" ${_label} "${LOOPDEV}p1" -q; then
457 dfatal
"Failed to mkfs -t ${FSTYPE}"
462 check_asan_reports
() {
466 if [[ "$IS_BUILT_WITH_ASAN" = "yes" ]]; then
468 if [[ -e "$root/systemd.asan.log.1" ]]; then
469 cat "$root/systemd.asan.log.1"
473 journald_report
=$
(find "$root" -name "systemd-journald.asan.log*" -exec cat {} \
;)
474 if [[ ! -z "$journald_report" ]]; then
475 printf "%s" "$journald_report"
479 pids
=$
("$BUILD_DIR/journalctl" -D "$root/var/log/journal" | perl
-alne 'print $1 if /\[(\d+)\]:\s*SUMMARY:\s+\w+Sanitizer/')
480 if [[ ! -z "$pids" ]]; then
483 "$BUILD_DIR/journalctl" -D "$root/var/log/journal" _PID
=$pid --no-pager
491 check_result_nspawn
() {
493 local journald_report
=""
495 [[ -e $TESTDIR/$1/testok
]] && ret
=0
496 [[ -f $TESTDIR/$1/failed
]] && cp -a $TESTDIR/$1/failed
$TESTDIR
497 cp -a $TESTDIR/$1/var
/log
/journal
$TESTDIR
498 [[ -f $TESTDIR/failed
]] && cat $TESTDIR/failed
499 ls -l $TESTDIR/journal
/*/*.journal
500 test -s $TESTDIR/failed
&& ret
=$
(($ret+1))
501 [ -n "$TIMED_OUT" ] && ret
=$
(($ret+1))
502 check_asan_reports
"$TESTDIR/$1" || ret
=$
(($ret+1))
506 # can be overridden in specific test
507 check_result_qemu
() {
509 mkdir
-p $TESTDIR/root
510 mount
${LOOPDEV}p1
$TESTDIR/root
511 [[ -e $TESTDIR/root
/testok
]] && ret
=0
512 [[ -f $TESTDIR/root
/failed
]] && cp -a $TESTDIR/root
/failed
$TESTDIR
513 cp -a $TESTDIR/root
/var
/log
/journal
$TESTDIR
514 check_asan_reports
"$TESTDIR/root" || ret
=$
(($ret+1))
516 [[ -f $TESTDIR/failed
]] && cat $TESTDIR/failed
517 ls -l $TESTDIR/journal
/*/*.journal
518 test -s $TESTDIR/failed
&& ret
=$
(($ret+1))
519 [ -n "$TIMED_OUT" ] && ret
=$
(($ret+1))
524 if [[ "$STRIP_BINARIES" = "no" ]]; then
525 ddebug
"Don't strip binaries"
528 ddebug
"Strip binaries"
529 find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f |
xargs strip
--strip-unneeded | ddebug
533 mkdir
-p $initdir/etc
/rc.d
534 cat >$initdir/etc
/rc.d
/rc.
local <<EOF
538 chmod 0755 $initdir/etc
/rc.d
/rc.
local
542 ddebug
"install any Execs from the service files"
544 export PKG_CONFIG_PATH
=$BUILD_DIR/src
/core
/
545 systemdsystemunitdir
=$
(pkg-config
--variable=systemdsystemunitdir systemd
)
546 systemduserunitdir
=$
(pkg-config
--variable=systemduserunitdir systemd
)
547 sed -r -n 's|^Exec[a-zA-Z]*=[@+!-]*([^ ]+).*|\1|gp' $initdir/{$systemdsystemunitdir,$systemduserunitdir}/*.service \
548 |
sort -u |
while read i
; do
549 # some {rc,halt}.local scripts and programs are okay to not exist, the rest should
550 inst
$i ||
[ "${i%.local}" != "$i" ] ||
[ "${i%systemd-update-done}" != "$i" ]
555 generate_module_dependencies
() {
556 if [[ -d $initdir/lib
/modules
/$KERNEL_VER ]] && \
557 ! depmod
-a -b "$initdir" $KERNEL_VER; then
558 dfatal
"\"depmod -a $KERNEL_VER\" failed."
563 install_depmod_files
() {
564 inst
/lib
/modules
/$KERNEL_VER/modules.order
565 inst
/lib
/modules
/$KERNEL_VER/modules.
builtin
569 # install plymouth, if found... else remove plymouth service files
570 # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
571 # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
572 # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
573 # dracut_install plymouth plymouthd
575 rm -f $initdir/{usr
/lib
,etc
}/systemd
/system
/plymouth
* $initdir/{usr
/lib
,etc
}/systemd
/system
/*/plymouth
*
579 install_ld_so_conf
() {
580 cp -a /etc
/ld.so.conf
* $initdir/etc
581 ldconfig
-r "$initdir"
584 install_config_files
() {
585 inst
/etc
/sysconfig
/init || true
591 inst
/etc
/nsswitch.conf
592 inst
/etc
/pam.conf || true
593 inst
/etc
/securetty || true
596 # we want an empty environment
597 > $initdir/etc
/environment
598 > $initdir/etc
/machine-id
600 echo systemd-testsuite
> $initdir/etc
/hostname
602 if [[ "$LOOKS_LIKE_SUSE" ]]; then
603 ROOTMOUNT
="/dev/sda1 / ${FSTYPE} rw 0 1"
605 ROOTMOUNT
="LABEL=systemd / ${FSTYPE} rw 0 1"
608 cat >$initdir/etc
/fstab
<<EOF
613 install_basic_tools
() {
614 [[ $BASICTOOLS ]] && dracut_install
$BASICTOOLS
615 dracut_install
-o sushell
616 # in Debian ldconfig is just a shell script wrapper around ldconfig.real
617 dracut_install
-o ldconfig.real
620 install_debug_tools
() {
621 [[ $DEBUGTOOLS ]] && dracut_install
$DEBUGTOOLS
625 # install libnss_files for login
626 NSS_LIBS
=$
(LD_DEBUG
=files getent passwd
2>&1 >/dev
/null |
sed -n '/calling init: .*libnss_/ {s!^.* /!/!; p}')
627 dracut_install
$NSS_LIBS
631 inst
$ROOTLIBDIR/system
/dbus.socket
633 # Fedora rawhide replaced dbus.service with dbus-daemon.service
634 if [ -f $ROOTLIBDIR/system
/dbus-daemon.service
]; then
635 inst
$ROOTLIBDIR/system
/dbus-daemon.service
637 inst_symlink
/etc
/systemd
/system
/dbus.service
639 inst
$ROOTLIBDIR/system
/dbus.service
643 /etc
/dbus-1
/usr
/share
/dbus-1
-xtype f \
644 |
while read file; do
651 if [[ "$LOOKS_LIKE_DEBIAN" ]] && type -p dpkg-architecture
&>/dev
/null
; then
652 find "/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/security" -xtype f
654 find /lib
*/security
-xtype f
656 find /etc
/pam.d
/etc
/security
-xtype f
657 ) |
while read file; do
661 # pam_unix depends on unix_chkpwd.
662 # see http://www.linux-pam.org/Linux-PAM-html/sag-pam_unix.html
663 dracut_install
-o unix_chkpwd
665 [[ "$LOOKS_LIKE_DEBIAN" ]] &&
666 cp /etc
/pam.d
/systemd-user
$initdir/etc
/pam.d
/
668 # set empty root password for easy debugging
669 sed -i 's/^root:x:/root::/' $initdir/etc
/passwd
673 # The first three paths may be deprecated.
674 # It seems now the last two paths are used by many distributions.
676 /usr
/lib
/kbd
/keymaps
/include
/* \
677 /usr
/lib
/kbd
/keymaps
/i386
/include
/* \
678 /usr
/lib
/kbd
/keymaps
/i386
/qwerty
/us.
* \
679 /usr
/lib
/kbd
/keymaps
/legacy
/include
/* \
680 /usr
/lib
/kbd
/keymaps
/legacy
/i386
/qwerty
/us.
*; do
681 [[ -f $i ]] ||
continue
685 # When it takes any argument, then install more keymaps.
688 /usr
/lib
/kbd
/keymaps
/i386
/*/* \
689 /usr
/lib
/kbd
/keymaps
/legacy
/i386
/*/*; do
690 [[ -f $i ]] ||
continue
697 for i
in /usr
/share
/zoneinfo
/{,*/,*/*/}*; do
698 [[ -f $i ]] ||
continue
705 /usr
/lib
/kbd
/consolefonts
/eurlatgr
* \
706 /usr
/lib
/kbd
/consolefonts
/latarcyrheb-sun16
*; do
707 [[ -f $i ]] ||
continue
713 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
714 [ -f ${_terminfodir}/l
/linux
] && break
716 dracut_install
-o ${_terminfodir}/l
/linux
720 cp $TEST_BASE_DIR/testsuite.target
$initdir/etc
/systemd
/system
/
721 cp $TEST_BASE_DIR/end.service
$initdir/etc
/systemd
/system
/
723 mkdir
-p $initdir/etc
/systemd
/system
/testsuite.target.wants
724 ln -fs $TEST_BASE_DIR/testsuite.service
$initdir/etc
/systemd
/system
/testsuite.target.wants
/testsuite.service
725 ln -fs $TEST_BASE_DIR/end.service
$initdir/etc
/systemd
/system
/testsuite.target.wants
/end.service
727 # make the testsuite the default target
728 ln -fs testsuite.target
$initdir/etc
/systemd
/system
/default.target
731 setup_nspawn_root
() {
732 rm -fr $TESTDIR/nspawn-root
733 ddebug
"cp -ar $initdir $TESTDIR/nspawn-root"
734 cp -ar $initdir $TESTDIR/nspawn-root
735 # we don't mount in the nspawn root
736 rm -f $TESTDIR/nspawn-root
/etc
/fstab
737 if [[ "$RUN_IN_UNPRIVILEGED_CONTAINER" = "yes" ]]; then
738 cp -ar $TESTDIR/nspawn-root
$TESTDIR/unprivileged-nspawn-root
743 mkdir
-p $initdir/run
744 mkdir
-p $initdir/etc
/systemd
/system
745 mkdir
-p $initdir/var
/log
/journal
747 for d
in usr
/bin usr
/sbin bin etc lib
"$libdir" sbin tmp usr var var
/log dev proc sys sysroot root run run
/lock run
/initramfs
; do
748 if [ -L "/$d" ]; then
755 ln -sfn /run
"$initdir/var/run"
756 ln -sfn /run
/lock
"$initdir/var/lock"
761 local _so_regex
='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
764 LC_ALL
=C ldd
"$_bin" 2>/dev
/null |
while read _line
; do
765 [[ $_line = 'not a dynamic executable' ]] && break
767 if [[ $_line =~
$_so_regex ]]; then
768 _file
=${BASH_REMATCH[1]}
769 [[ -e ${initdir}/$_file ]] && continue
770 inst_library
"$_file"
774 if [[ $_line =~ not\ found
]]; then
775 dfatal
"Missing a shared library required by $_bin."
776 dfatal
"Run \"ldd $_bin\" to find out what it is."
778 dfatal
"dracut cannot create an initrd."
785 [[ -e $STATEFILE ]] && .
$STATEFILE
786 if [[ -z "$TESTDIR" ]] ||
[[ ! -d "$TESTDIR" ]]; then
787 TESTDIR
=$
(mktemp
--tmpdir=/var
/tmp
-d -t systemd-test.XXXXXX
)
788 echo "TESTDIR=\"$TESTDIR\"" > $STATEFILE
794 initdir
=$TESTDIR/root
798 ## @brief Converts numeric logging level to the first letter of level name.
800 # @param lvl Numeric logging level in range from 1 to 6.
801 # @retval 1 if @a lvl is out of range.
802 # @retval 0 if @a lvl is correct.
803 # @result Echoes first letter of level name.
816 ## @brief Internal helper function for _do_dlog()
818 # @param lvl Numeric logging level.
819 # @param msg Message.
820 # @retval 0 It's always returned, even if logging failed.
822 # @note This function is not supposed to be called manually. Please use
823 # dtrace(), ddebug(), or others instead which wrap this one.
825 # This function calls _do_dlog() either with parameter msg, or if
826 # none is given, it will read standard input and will use every line as
830 # dwarn "This is a warning"
831 # echo "This is a warning" | dwarn
832 LOG_LEVEL
=${LOG_LEVEL:-4}
835 [ -z "$LOG_LEVEL" ] && return 0
836 [ $1 -le $LOG_LEVEL ] ||
return 0
837 local lvl
="$1"; shift
838 local lvlc
=$
(_lvl2char
"$lvl") ||
return 0
840 if [ $# -ge 1 ]; then
844 echo "$lvlc: " "$line"
849 ## @brief Logs message at TRACE level (6)
851 # @param msg Message.
852 # @retval 0 It's always returned, even if logging failed.
856 [ -n "$debug" ] && set -x ||
:
859 ## @brief Logs message at DEBUG level (5)
861 # @param msg Message.
862 # @retval 0 It's always returned, even if logging failed.
866 # [ -n "$debug" ] && set -x || :
869 ## @brief Logs message at INFO level (4)
871 # @param msg Message.
872 # @retval 0 It's always returned, even if logging failed.
876 [ -n "$debug" ] && set -x ||
:
879 ## @brief Logs message at WARN level (3)
881 # @param msg Message.
882 # @retval 0 It's always returned, even if logging failed.
886 [ -n "$debug" ] && set -x ||
:
889 ## @brief Logs message at ERROR level (2)
891 # @param msg Message.
892 # @retval 0 It's always returned, even if logging failed.
896 # [ -n "$debug" ] && set -x || :
899 ## @brief Logs message at FATAL level (1)
901 # @param msg Message.
902 # @retval 0 It's always returned, even if logging failed.
906 [ -n "$debug" ] && set -x ||
:
910 # Generic substring function. If $2 is in $1, return 0.
911 strstr
() { [ "${1#*$2*}" != "$1" ]; }
913 # normalize_path <path>
914 # Prints the normalized path, where it removes any duplicated
915 # and trailing slashes.
917 # $ normalize_path ///test/test//
921 set -- "${1//+(\/)//}"
926 # convert_abs_rel <from> <to>
927 # Prints the relative path, when creating a symlink to <to> from <from>.
929 # $ convert_abs_rel /usr/bin/test /bin/test-2
931 # $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
933 local __current __absolute __abssize __cursize __newpath
936 set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
938 # corner case #1 - self looping link
939 [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }
941 # corner case #2 - own dir link
942 [[ "${1%/*}" == "$2" ]] && { echo "."; return; }
944 IFS
="/" __current
=($1)
945 IFS
="/" __absolute
=($2)
947 __abssize
=${#__absolute[@]}
948 __cursize
=${#__current[@]}
950 while [[ ${__absolute[__level]} == ${__current[__level]} ]]
953 if (( __level
> __abssize || __level
> __cursize
))
959 for ((__i
= __level
; __i
< __cursize-1
; __i
++))
963 __newpath
=$__newpath"/"
965 __newpath
=$__newpath".."
968 for ((__i
= __level
; __i
< __abssize
; __i
++))
970 if [[ -n $__newpath ]]
972 __newpath
=$__newpath"/"
974 __newpath
=$__newpath${__absolute[__i]}
981 # Install a directory, keeping symlinks as on the original system.
982 # Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
983 # will create ${initdir}/lib64, ${initdir}/lib64/file,
984 # and a symlink ${initdir}/lib -> lib64.
986 [[ -e ${initdir}/"$1" ]] && return 0 # already there
988 local _dir
="$1" _part
="${1%/*}" _file
989 while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
994 # iterate over parent directories
995 for _file
in $_dir; do
996 [[ -e "${initdir}/$_file" ]] && continue
997 if [[ -L $_file ]]; then
998 inst_symlink
"$_file"
1001 mkdir
-m 0755 -p "${initdir}/$_file" ||
return 1
1002 [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
1003 chmod u
+w
"${initdir}/$_file"
1008 # $1 = file to copy to ramdisk
1009 # $2 (optional) Name for the file on the ramdisk
1010 # Location of the image dir is assumed to be $initdir
1011 # We never overwrite the target if it exists.
1013 [[ -f "$1" ]] ||
return 1
1014 strstr
"$1" "/" ||
return 1
1016 local _src
=$1 target
="${2:-$1}"
1017 if ! [[ -d ${initdir}/$target ]]; then
1018 [[ -e ${initdir}/$target ]] && return 0
1019 [[ -L ${initdir}/$target ]] && return 0
1020 [[ -d "${initdir}/${target%/*}" ]] || inst_dir "${target%/*}"
1022 # install checksum files also
1023 if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
1024 inst
"${_src%/*}/.${_src##*/}.hmac" "${target%/*}/.${target##*/}.hmac"
1026 ddebug
"Installing $_src"
1027 cp --sparse=always
-pfL "$_src" "${initdir}/$target"
1030 # find symlinks linked to given library file
1032 # Function searches for symlinks by stripping version numbers appended to
1033 # library filename, checks if it points to the same target and finally
1034 # prints the list of symlinks to stdout.
1037 # rev_lib_symlinks libfoo.so.8.1
1038 # output: libfoo.so.8 libfoo.so
1039 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
1040 rev_lib_symlinks
() {
1041 [[ ! $1 ]] && return 0
1043 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
1045 [[ ${fn} =~ .
*\.so\..
* ]] ||
return 1
1047 until [[ ${fn##*.} == so
]]; do
1049 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
1055 # Same as above, but specialized to handle dynamic libraries.
1056 # It handles making symlinks according to how the original library
1059 local _src="$1" _dest=${2:-$1} _lib _reallib _symlink
1060 strstr "$1" "/" || return 1
1061 [[ -e $initdir/$_dest ]] && return 0
1062 if [[ -L $_src ]]; then
1063 # install checksum files also
1064 if [[ -e "${_src%/*}/.
${_src##*/}.hmac
" ]]; then
1065 inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac
"
1067 _reallib=$(readlink -f "$_src")
1068 inst_simple "$_reallib" "$_reallib"
1069 inst_dir "${_dest%/*}"
1070 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
1071 ln -sfn $
(convert_abs_rel
"${_dest}" "${_reallib}") "${initdir}/${_dest}"
1073 inst_simple
"$_src" "$_dest"
1076 # Create additional symlinks. See rev_symlinks description.
1077 for _symlink
in $
(rev_lib_symlinks
$_src) $
(rev_lib_symlinks
$_reallib); do
1078 [[ -e $initdir/$_symlink ]] ||
{
1079 ddebug
"Creating extra symlink: $_symlink"
1080 inst_symlink
$_symlink
1085 # find a binary. If we were not passed the full path directly,
1086 # search in the usual places to find the binary.
1088 if [[ -z ${1##/*} ]]; then
1089 if [[ -x $1 ]] ||
{ strstr
"$1" ".so" && ldd
$1 &>/dev
/null
; }; then
1098 # Same as above, but specialized to install binary executables.
1099 # Install binary executable, and all shared library dependencies, if any.
1102 _bin
=$
(find_binary
"$1") ||
return 1
1104 [[ -e $initdir/$_target ]] && return 0
1105 [[ -L $_bin ]] && inst_symlink
$_bin $_target && return 0
1107 local _so_regex
='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
1109 LC_ALL
=C ldd
"$_bin" 2>/dev
/null |
while read _line
; do
1110 [[ $_line = 'not a dynamic executable' ]] && break
1112 if [[ $_line =~
$_so_regex ]]; then
1113 _file
=${BASH_REMATCH[1]}
1114 [[ -e ${initdir}/$_file ]] && continue
1115 inst_library
"$_file"
1119 if [[ $_line =~ not\ found
]]; then
1120 dfatal
"Missing a shared library required by $_bin."
1121 dfatal
"Run \"ldd $_bin\" to find out what it is."
1123 dfatal
"dracut cannot create an initrd."
1127 inst_simple
"$_bin" "$_target"
1130 # same as above, except for shell scripts.
1131 # If your shell script does not start with shebang, it is not a shell script.
1134 _bin
=$
(find_binary
"$1") ||
return 1
1136 local _line _shebang_regex
1137 read -r -n 80 _line
<"$_bin"
1138 # If debug is set, clean unprintable chars to prevent messing up the term
1139 [[ $debug ]] && _line
=$
(echo -n "$_line" |
tr -c -d '[:print:][:space:]')
1140 _shebang_regex
='(#! *)(/[^ ]+).*'
1141 [[ $_line =~
$_shebang_regex ]] ||
return 1
1142 inst
"${BASH_REMATCH[2]}" && inst_simple
"$_bin" "$@"
1145 # same as above, but specialized for symlinks
1147 local _src
=$1 _target
=${2:-$1} _realsrc
1148 strstr
"$1" "/" ||
return 1
1149 [[ -L $1 ]] ||
return 1
1150 [[ -L $initdir/$_target ]] && return 0
1151 _realsrc
=$
(readlink
-f "$_src")
1152 if ! [[ -e $initdir/$_realsrc ]]; then
1153 if [[ -d $_realsrc ]]; then
1154 inst_dir
"$_realsrc"
1159 [[ ! -e $initdir/${_target%/*} ]] && inst_dir
"${_target%/*}"
1160 [[ -d ${_target%/*} ]] && _target=$(readlink -f ${_target%/*})/${_target##*/}
1161 ln -sfn $
(convert_abs_rel
"${_target}" "${_realsrc}") "$initdir/$_target"
1164 # attempt to install any programs specified in a udev rule
1165 inst_rule_programs
() {
1168 if grep -qE 'PROGRAM==?"[^ "]+' "$1"; then
1169 for _prog
in $
(grep -E 'PROGRAM==?"[^ "]+' "$1" |
sed -r 's/.*PROGRAM==?"([^ "]+).*/\1/'); do
1170 if [ -x /lib
/udev
/$_prog ]; then
1171 _bin
=/lib
/udev
/$_prog
1173 _bin
=$
(find_binary
"$_prog") ||
{
1174 dinfo
"Skipping program $_prog using in udev rule $(basename $1) as it cannot be found"
1179 #dinfo "Installing $_bin due to it's use in the udev rule $(basename $1)"
1180 dracut_install
"$_bin"
1185 # udev rules always get installed in the same place, so
1186 # create a function to install them to make life simpler.
1188 local _target
=/etc
/udev
/rules.d _rule _found
1190 inst_dir
"/lib/udev/rules.d"
1192 for _rule
in "$@"; do
1193 if [ "${rule#/}" = "$rule" ]; then
1194 for r
in /lib
/udev
/rules.d
/etc
/udev
/rules.d
; do
1195 if [[ -f $r/$_rule ]]; then
1197 inst_simple
"$_found"
1198 inst_rule_programs
"$_found"
1202 for r
in '' .
/ $dracutbasedir/rules.d
/; do
1203 if [[ -f ${r}$_rule ]]; then
1205 inst_simple
"$_found" "$_target/${_found##*/}"
1206 inst_rule_programs
"$_found"
1209 [[ $_found ]] || dinfo
"Skipping udev rule: $_rule"
1214 # general purpose installation function
1215 # Same args as above.
1221 2) [[ ! $initdir && -d $2 ]] && export initdir
=$2
1222 [[ $initdir = $2 ]] && set $1;;
1223 3) [[ -z $initdir ]] && export initdir
=$2
1225 *) dfatal
"inst only takes 1 or 2 or 3 arguments"
1228 for _x
in inst_symlink inst_script inst_binary inst_simple
; do
1229 $_x "$@" && return 0
1234 # install any of listed files
1236 # If first argument is '-d' and second some destination path, first accessible
1237 # source is installed into this path, otherwise it will installed in the same
1238 # path as source. If none of listed files was installed, function return 1.
1239 # On first successful installation it returns with 0 status.
1243 # inst_any -d /bin/foo /bin/bar /bin/baz
1245 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
1250 [[ $1 = '-d' ]] && to
="$2" && shift 2
1253 if [[ -e $f ]]; then
1254 [[ $to ]] && inst
"$f" "$to" && return 0
1255 inst
"$f" && return 0
1262 # dracut_install [-o ] <file> [<file> ... ]
1263 # Install <file> to the initramfs image
1264 # -o optionally install the <file> and don't fail, if it is not there
1267 if [[ $1 = '-o' ]]; then
1271 while (($# > 0)); do
1272 if ! inst
"$1" ; then
1273 if [[ $_optional = yes ]]; then
1274 dinfo
"Skipping program $1 as it cannot be found and is" \
1275 "flagged to be optional"
1277 dfatal
"Failed to install $1"
1285 # Install a single kernel module along with any firmware it may require.
1286 # $1 = full path to kernel module to install
1287 install_kmod_with_fw
() {
1288 # no need to go further if the module is already installed
1290 [[ -e "${initdir}/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" ]] \
1293 [[ -e "$initdir/.kernelmodseen/${1##*/}" ]] && return 0
1295 if [[ $omit_drivers ]]; then
1296 local _kmod
=${1##*/}
1299 if [[ "$_kmod" =~
$omit_drivers ]]; then
1300 dinfo
"Omitting driver $_kmod"
1303 if [[ "${1##*/lib/modules/$KERNEL_VER/}" =~
$omit_drivers ]]; then
1304 dinfo
"Omitting driver $_kmod"
1309 [ -d "$initdir/.kernelmodseen" ] && \
1310 > "$initdir/.kernelmodseen/${1##*/}"
1312 inst_simple
"$1" "/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" \
1315 local _modname
=${1##*/} _fwdir _found _fw
1316 _modname
=${_modname%.ko*}
1317 for _fw
in $
(modinfo
-k $KERNEL_VER -F firmware
$1 2>/dev
/null
); do
1319 for _fwdir
in $fw_dir; do
1320 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1321 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1325 if [[ $_found != yes ]]; then
1326 if ! grep -qe "\<${_modname//-/_}\>" /proc
/modules
; then
1327 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1328 "\"${_modname}.ko\""
1330 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1331 "\"${_modname}.ko\""
1338 # Do something with all the dependencies of a kernel module.
1339 # Note that kernel modules depend on themselves using the technique we use
1340 # $1 = function to call for each dependency we find
1341 # It will be passed the full path to the found kernel module
1342 # $2 = module to get dependencies for
1343 # rest of args = arguments to modprobe
1344 # _fderr specifies FD passed from surrounding scope
1345 for_each_kmod_dep
() {
1346 local _func
=$1 _kmod
=$2 _cmd _modpath _options _found
=0
1348 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1349 while read _cmd _modpath _options
; do
1350 [[ $_cmd = insmod
]] ||
continue
1351 $_func ${_modpath} ||
exit $?
1354 [[ $_found -eq 0 ]] && exit 1
1359 # filter kernel modules to install certain modules that meet specific
1361 # $1 = search only in subdirectory of /kernel/$1
1362 # $2 = function to call with module name to filter.
1363 # This function will be passed the full path to the module to test.
1364 # The behavior of this function can vary depending on whether $hostonly is set.
1365 # If it is, we will only look at modules that are already in memory.
1366 # If it is not, we will look at all kernel modules
1367 # This function returns the full filenames of modules that match $1
1368 filter_kernel_modules_by_path
() (
1369 local _modname _filtercmd
1370 if ! [[ $hostonly ]]; then
1371 _filtercmd
='find "$KERNEL_MODS/kernel/$1" "$KERNEL_MODS/extra"'
1372 _filtercmd
+=' "$KERNEL_MODS/weak-updates" -name "*.ko" -o -name "*.ko.gz"'
1373 _filtercmd
+=' -o -name "*.ko.xz"'
1374 _filtercmd
+=' 2>/dev/null'
1376 _filtercmd
='cut -d " " -f 1 </proc/modules|xargs modinfo -F filename '
1377 _filtercmd
+='-k $KERNEL_VER 2>/dev/null'
1379 for _modname
in $
(eval $_filtercmd); do
1381 *.ko
) "$2" "$_modname" && echo "$_modname";;
1382 *.ko.gz
) gzip -dc "$_modname" > $initdir/$$.ko
1383 $2 $initdir/$$.ko
&& echo "$_modname"
1384 rm -f $initdir/$$.ko
1386 *.ko.xz
) xz
-dc "$_modname" > $initdir/$$.ko
1387 $2 $initdir/$$.ko
&& echo "$_modname"
1388 rm -f $initdir/$$.ko
1393 find_kernel_modules_by_path
() (
1394 if ! [[ $hostonly ]]; then
1395 find "$KERNEL_MODS/kernel/$1" "$KERNEL_MODS/extra" "$KERNEL_MODS/weak-updates" \
1396 -name "*.ko" -o -name "*.ko.gz" -o -name "*.ko.xz" 2>/dev
/null
1398 cut
-d " " -f 1 </proc
/modules \
1399 |
xargs modinfo
-F filename
-k $KERNEL_VER 2>/dev
/null
1403 filter_kernel_modules
() {
1404 filter_kernel_modules_by_path drivers
"$1"
1407 find_kernel_modules
() {
1408 find_kernel_modules_by_path drivers
1411 # instmods [-c] <kernel module> [<kernel module> ... ]
1412 # instmods [-c] <kernel subsystem>
1413 # install kernel modules along with all their dependencies.
1414 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1416 [[ $no_kernel = yes ]] && return
1417 # called [sub]functions inherit _fderr
1420 if [[ $1 = '-c' ]]; then
1425 function inst1mod
() {
1426 local _ret
=0 _mod
="$1"
1429 if [ -f $KERNEL_MODS/modules.
${_mod#=} ]; then
1430 ( [[ "$_mpargs" ]] && echo $_mpargs
1431 cat "${KERNEL_MODS}/modules.${_mod#=}" ) \
1434 ( [[ "$_mpargs" ]] && echo $_mpargs
1435 find "$KERNEL_MODS" -path "*/${_mod#=}/*" -printf '%f\n' ) \
1439 --*) _mpargs
+=" $_mod" ;;
1440 i2o_scsi
) return ;; # Do not load this diagnostic-only module
1443 # if we are already installed, skip this module and go on
1445 [[ -f "$initdir/.kernelmodseen/${_mod%.ko}.ko" ]] && return
1447 if [[ $omit_drivers ]] && [[ "$1" =~
$omit_drivers ]]; then
1448 dinfo
"Omitting driver ${_mod##$KERNEL_MODS}"
1451 # If we are building a host-specific initramfs and this
1452 # module is not already loaded, move on to the next one.
1453 [[ $hostonly ]] && ! grep -qe "\<${_mod//-/_}\>" /proc
/modules \
1454 && ! echo $add_drivers |
grep -qe "\<${_mod}\>" \
1457 # We use '-d' option in modprobe only if modules prefix path
1458 # differs from default '/'. This allows us to use Dracut with
1459 # old version of modprobe which doesn't have '-d' option.
1460 local _moddirname
=${KERNEL_MODS%%/lib/modules/*}
1461 [[ -n ${_moddirname} ]] && _moddirname
="-d ${_moddirname}/"
1463 # ok, load the module, all its dependencies, and any firmware
1465 for_each_kmod_dep install_kmod_with_fw
$_mod \
1466 --set-version $KERNEL_VER ${_moddirname} $_mpargs
1473 function instmods_1
() {
1475 if (($# == 0)); then # filenames from stdin
1477 inst1mod
"${_mod%.ko*}" ||
{
1478 if [ "$_check" = "yes" ]; then
1479 dfatal
"Failed to install $_mod"
1485 while (($# > 0)); do # filenames as arguments
1486 inst1mod
${1%.ko*} ||
{
1487 if [ "$_check" = "yes" ]; then
1488 dfatal
"Failed to install $1"
1497 local _ret _filter_not_found
='FATAL: Module .* not found.'
1499 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1500 # redirections, but that would make dracut require bash4 at least.
1501 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
1502 |
while read line
; do [[ "$line" =~
$_filter_not_found ]] && echo $line ||
echo $line >&2 ;done | derror
1508 # inst_libdir_file [-n <pattern>] <file> [<file>...]
1509 # Install a <file> located on a lib directory to the initramfs image
1510 # -n <pattern> install non-matching files
1511 inst_libdir_file
() {
1512 if [[ "$1" == "-n" ]]; then
1515 for _dir
in $libdirs; do
1517 for _f
in "$_dir"/$_i; do
1518 [[ "$_i" =~
$_pattern ]] ||
continue
1519 [[ -e "$_i" ]] && dracut_install
"$_i"
1524 for _dir
in $libdirs; do
1526 for _f
in "$_dir"/$_i; do
1527 [[ -e "$_f" ]] && dracut_install
"$_f"
1535 ln -fs ..
/usr
/bin
/systemctl
$initdir/bin
/
1536 ln -fs ..
/usr
/lib
/systemd
$initdir/lib
/
1537 inst_simple
"/usr/lib/systemd/system/haveged.service"
1540 # can be overridden in specific test
1542 umount
$TESTDIR/root
2>/dev
/null || true
1543 [[ $LOOPDEV ]] && losetup
-d $LOOPDEV || true
1548 if [ -z "$TEST_NO_QEMU" ]; then
1550 check_result_qemu ||
return 1
1552 dwarn
"can't run QEMU, skipping"
1555 if [ -z "$TEST_NO_NSPAWN" ]; then
1556 if run_nspawn
"nspawn-root"; then
1557 check_result_nspawn
"nspawn-root" ||
return 1
1559 dwarn
"can't run systemd-nspawn, skipping"
1562 if [[ "$RUN_IN_UNPRIVILEGED_CONTAINER" = "yes" ]]; then
1563 if NSPAWN_ARGUMENTS
="-U --private-network $NSPAWN_ARGUMENTS" run_nspawn
"unprivileged-nspawn-root"; then
1564 check_result_nspawn
"unprivileged-nspawn-root" ||
return 1
1566 dwarn
"can't run systemd-nspawn, skipping"
1574 if [[ $UID != "0" ]]; then
1575 echo "TEST: $TEST_DESCRIPTION [SKIPPED]: not root" >&2
1580 [[ $libdir ]] ||
for libdir
in /lib64
/lib
; do
1581 [[ -d $libdir ]] && libdirs
+=" $libdir" && break
1584 [[ $usrlibdir ]] ||
for usrlibdir
in /usr
/lib64
/usr
/lib
; do
1585 [[ -d $usrlibdir ]] && libdirs
+=" $usrlibdir" && break
1588 mkdir
-p "$STATEDIR"
1593 while (($# > 0)); do
1596 echo "TEST RUN: $TEST_DESCRIPTION"
1599 if (( $ret == 0 )); then
1600 echo "TEST RUN: $TEST_DESCRIPTION [OK]"
1602 echo "TEST RUN: $TEST_DESCRIPTION [FAILED]"
1606 echo "TEST SETUP: $TEST_DESCRIPTION"
1610 echo "TEST CLEANUP: $TEST_DESCRIPTION"
1617 echo -n "TEST: $TEST_DESCRIPTION ";
1619 test_setup
&& test_run
1625 ) </dev
/null
>"$TESTLOG" 2>&1 || ret
=$?
1626 if [ $ret -eq 0 ]; then