diff --git a/man/homectl.xml b/man/homectl.xml index 184bdcf6fd..f2858166f7 100644 --- a/man/homectl.xml +++ b/man/homectl.xml @@ -846,6 +846,10 @@ Exit status On success, 0 is returned, a non-zero failure code otherwise. + + When a command is invoked with with, the exit status of the child is + propagated. Effectively, homectl will exit without error if the command is + successfully invoked and finishes successfully. diff --git a/man/systemd-tmpfiles.xml b/man/systemd-tmpfiles.xml index 5f97e37025..15bc1ea889 100644 --- a/man/systemd-tmpfiles.xml +++ b/man/systemd-tmpfiles.xml @@ -263,16 +263,18 @@ Exit status - On success, 0 is returned. If the configuration was syntactically invalid (syntax errors, - missing arguments, …), so some lines had to be ignored, but no other errors occurred, - 65 is returned (EX_DATAERR from - /usr/include/sysexits.h). If the configuration was syntactically valid, but - could not be executed (lack of permissions, creation of files in missing directories, invalid - contents when writing to /sys/ values, …), 73 is - returned (EX_CANTCREAT from /usr/include/sysexits.h). - Otherwise, 1 is returned (EXIT_FAILURE from - /usr/include/stdlib.h). - + On success, 0 is returned. If the configuration was syntactically invalid (syntax errors, missing + arguments, …), so some lines had to be ignored, but no other errors occurred, 65 is + returned (EX_DATAERR from /usr/include/sysexits.h). If the + configuration was syntactically valid, but could not be executed (lack of permissions, creation of files + in missing directories, invalid contents when writing to /sys/ values, …), + 73 is returned (EX_CANTCREAT from + /usr/include/sysexits.h). Otherwise, 1 is returned + (EXIT_FAILURE from /usr/include/stdlib.h). + + Note: when creating items, if the target already exists, but is of the wrong type or otherwise does + not match the requested state, and forced operation has not been requested with +, + a message is emitted, but the failure is otherwise ignored. diff --git a/src/home/homectl.c b/src/home/homectl.c index cf1a2d9f9b..a187a75d86 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -3362,4 +3362,4 @@ static int run(int argc, char *argv[]) { return dispatch_verb(argc, argv, verbs, NULL); } -DEFINE_MAIN_FUNCTION(run); +DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run); diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index f11b4eed7c..6b26dc8b9c 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -1656,10 +1656,9 @@ static int create_directory_or_subvolume(const char *path, mode_t mode, bool sub return log_error_errno(r, "%s does not exist and cannot be created as the file system is read-only.", path); if (k < 0) return log_error_errno(k, "Failed to check if %s exists: %m", path); - if (!k) { - log_warning("\"%s\" already exists and is not a directory.", path); - return -EEXIST; - } + if (!k) + return log_warning_errno(SYNTHETIC_ERRNO(EEXIST), + "\"%s\" already exists and is not a directory.", path); *creation = CREATION_EXISTING; } else @@ -1742,10 +1741,10 @@ static int empty_directory(Item *i, const char *path) { } if (r < 0) return log_error_errno(r, "is_dir() failed on path %s: %m", path); - if (r == 0) - return log_error_errno(SYNTHETIC_ERRNO(EEXIST), - "'%s' already exists and is not a directory.", - path); + if (r == 0) { + log_warning("\"%s\" already exists and is not a directory.", path); + return 0; + } return path_set_perms(i, path); } @@ -1804,7 +1803,7 @@ static int create_device(Item *i, mode_t file_type) { return log_error_errno(r, "Failed to create device node \"%s\": %m", i->path); creation = CREATION_FORCE; } else { - log_debug("%s is not a device node.", i->path); + log_warning("\"%s\" already exists is not a device node.", i->path); return 0; } } else @@ -2575,7 +2574,9 @@ static int patch_var_run(const char *fname, unsigned line, char **path) { /* Also log about this briefly. We do so at LOG_NOTICE level, as we fixed up the situation automatically, hence * there's no immediate need for action by the user. However, in the interest of making things less confusing * to the user, let's still inform the user that these snippets should really be updated. */ - log_syntax(NULL, LOG_NOTICE, fname, line, 0, "Line references path below legacy directory /var/run/, updating %s → %s; please update the tmpfiles.d/ drop-in file accordingly.", *path, n); + log_syntax(NULL, LOG_NOTICE, fname, line, 0, + "Line references path below legacy directory /var/run/, updating %s → %s; please update the tmpfiles.d/ drop-in file accordingly.", + *path, n); free_and_replace(*path, n); diff --git a/test/TEST-52-HONORFIRSTSHUTDOWN/test.sh b/test/TEST-52-HONORFIRSTSHUTDOWN/test.sh index a0848ef672..28b97fadb0 100755 --- a/test/TEST-52-HONORFIRSTSHUTDOWN/test.sh +++ b/test/TEST-52-HONORFIRSTSHUTDOWN/test.sh @@ -16,4 +16,4 @@ NSPAWN_TIMEOUT=20 # only found from the console during the poweroff. rm -f /tmp/honorfirstshutdown.log >/dev/null -do_test "$@" 52 > /tmp/honorfirstshutdown.log +do_test "$@" 52 >/tmp/honorfirstshutdown.log diff --git a/test/test-execute/exec-standardoutput-append.service b/test/test-execute/exec-standardoutput-append.service index 8983bb056b..2118bfc2a6 100644 --- a/test/test-execute/exec-standardoutput-append.service +++ b/test/test-execute/exec-standardoutput-append.service @@ -2,8 +2,8 @@ Description=Test for StandardOutput=append: [Service] -ExecStartPre=sh -c 'printf "hello\n" > /tmp/test-exec-standardoutput-output' -ExecStartPre=sh -c 'printf "hello\nhello\n" > /tmp/test-exec-standardoutput-expected' +ExecStartPre=sh -c 'printf "hello\n" >/tmp/test-exec-standardoutput-output' +ExecStartPre=sh -c 'printf "hello\nhello\n" >/tmp/test-exec-standardoutput-expected' StandardInput=data StandardInputText=hello StandardOutput=append:/tmp/test-exec-standardoutput-output diff --git a/test/test-execute/exec-standardoutput-file.service b/test/test-execute/exec-standardoutput-file.service index 71e2604b94..8d484a456e 100644 --- a/test/test-execute/exec-standardoutput-file.service +++ b/test/test-execute/exec-standardoutput-file.service @@ -2,8 +2,8 @@ Description=Test for StandardOutput=file: [Service] -ExecStartPre=sh -c 'printf "nooo\nhello\n" > /tmp/test-exec-standardoutput-output' -ExecStartPre=sh -c 'printf "hello\nello\n" > /tmp/test-exec-standardoutput-expected' +ExecStartPre=sh -c 'printf "nooo\nhello\n" >/tmp/test-exec-standardoutput-output' +ExecStartPre=sh -c 'printf "hello\nello\n" >/tmp/test-exec-standardoutput-expected' StandardInput=data StandardInputText=hello StandardOutput=file:/tmp/test-exec-standardoutput-output diff --git a/test/test-execute/exec-standardoutput-truncate.service b/test/test-execute/exec-standardoutput-truncate.service index 4b4bb87b75..8d6ea2769f 100644 --- a/test/test-execute/exec-standardoutput-truncate.service +++ b/test/test-execute/exec-standardoutput-truncate.service @@ -2,8 +2,8 @@ Description=Test for StandardOutput=truncate: [Service] -ExecStartPre=sh -c 'printf "hello\n" > /tmp/test-exec-standardoutput-output' -ExecStartPre=sh -c 'printf "hi\n" > /tmp/test-exec-standardoutput-expected' +ExecStartPre=sh -c 'printf "hello\n" >/tmp/test-exec-standardoutput-output' +ExecStartPre=sh -c 'printf "hi\n" >/tmp/test-exec-standardoutput-expected' StandardInput=data StandardInputText=hi StandardOutput=truncate:/tmp/test-exec-standardoutput-output diff --git a/test/test-functions b/test/test-functions index 6b94058fd3..063a6096fd 100644 --- a/test/test-functions +++ b/test/test-functions @@ -503,13 +503,13 @@ install_verity_minimal() { ln -s ../usr/lib/os-release $initdir/etc/os-release touch $initdir/etc/machine-id $initdir/etc/resolv.conf touch $initdir/opt/some_file - echo MARKER=1 >> $initdir/usr/lib/os-release - echo -e "[Service]\nExecStartPre=cat /usr/lib/os-release\nExecStart=sleep 120" > $initdir/usr/lib/systemd/system/app0.service + echo MARKER=1 >>$initdir/usr/lib/os-release + echo -e "[Service]\nExecStartPre=cat /usr/lib/os-release\nExecStart=sleep 120" >$initdir/usr/lib/systemd/system/app0.service cp $initdir/usr/lib/systemd/system/app0.service $initdir/usr/lib/systemd/system/app0-foo.service mksquashfs $initdir $oldinitdir/usr/share/minimal_0.raw veritysetup format $oldinitdir/usr/share/minimal_0.raw $oldinitdir/usr/share/minimal_0.verity | \ - grep '^Root hash:' | cut -f2 | tr -d '\n' > $oldinitdir/usr/share/minimal_0.roothash + grep '^Root hash:' | cut -f2 | tr -d '\n' >$oldinitdir/usr/share/minimal_0.roothash sed -i "s/MARKER=1/MARKER=2/g" $initdir/usr/lib/os-release rm $initdir/usr/lib/systemd/system/app0-foo.service @@ -517,7 +517,7 @@ install_verity_minimal() { mksquashfs $initdir $oldinitdir/usr/share/minimal_1.raw veritysetup format $oldinitdir/usr/share/minimal_1.raw $oldinitdir/usr/share/minimal_1.verity | \ - grep '^Root hash:' | cut -f2 | tr -d '\n' > $oldinitdir/usr/share/minimal_1.roothash + grep '^Root hash:' | cut -f2 | tr -d '\n' >$oldinitdir/usr/share/minimal_1.roothash # Rolling distros like Arch do not set VERSION_ID local version_id="" @@ -527,42 +527,42 @@ install_verity_minimal() { export initdir=$TESTDIR/app0 mkdir -p $initdir/usr/lib/extension-release.d $initdir/usr/lib/systemd/system $initdir/opt - grep "^ID=" $os_release > $initdir/usr/lib/extension-release.d/extension-release.app0 - echo "${version_id}" >> $initdir/usr/lib/extension-release.d/extension-release.app0 - cat < $initdir/usr/lib/systemd/system/app0.service + grep "^ID=" $os_release >$initdir/usr/lib/extension-release.d/extension-release.app0 + echo "${version_id}" >>$initdir/usr/lib/extension-release.d/extension-release.app0 + cat <$initdir/usr/lib/systemd/system/app0.service [Service] Type=oneshot RemainAfterExit=yes ExecStart=/opt/script0.sh EOF - cat < $initdir/opt/script0.sh + cat <$initdir/opt/script0.sh #!/bin/bash set -e test -e /usr/lib/os-release cat /usr/lib/extension-release.d/extension-release.app0 EOF chmod +x $initdir/opt/script0.sh - echo MARKER=1 > $initdir/usr/lib/systemd/system/some_file + echo MARKER=1 >$initdir/usr/lib/systemd/system/some_file mksquashfs $initdir $oldinitdir/usr/share/app0.raw export initdir=$TESTDIR/app1 mkdir -p $initdir/usr/lib/extension-release.d $initdir/usr/lib/systemd/system $initdir/opt - grep "^ID=" $os_release > $initdir/usr/lib/extension-release.d/extension-release.app1 - echo "${version_id}" >> $initdir/usr/lib/extension-release.d/extension-release.app1 - cat < $initdir/usr/lib/systemd/system/app1.service + grep "^ID=" $os_release >$initdir/usr/lib/extension-release.d/extension-release.app1 + echo "${version_id}" >>$initdir/usr/lib/extension-release.d/extension-release.app1 + cat <$initdir/usr/lib/systemd/system/app1.service [Service] Type=oneshot RemainAfterExit=yes ExecStart=/opt/script1.sh EOF - cat < $initdir/opt/script1.sh + cat <$initdir/opt/script1.sh #!/bin/bash set -e test -e /usr/lib/os-release cat /usr/lib/extension-release.d/extension-release.app1 EOF chmod +x $initdir/opt/script1.sh - echo MARKER=1 > $initdir/usr/lib/systemd/system/other_file + echo MARKER=1 >$initdir/usr/lib/systemd/system/other_file mksquashfs $initdir $oldinitdir/usr/share/app1.raw ) } @@ -700,7 +700,7 @@ if [[ "$ASAN_COMPILER" == "clang" ]]; then # Let's add the ASan DSO's path to the dynamic linker's cache. This is pretty # unnecessary for gcc & libasan, however, for clang this is crucial, as its # runtime ASan DSO is in a non-standard (library) path. - echo "${ASAN_RT_PATH%/*}" > /etc/ld.so.conf.d/asan-path-override.conf + echo "${ASAN_RT_PATH%/*}" >/etc/ld.so.conf.d/asan-path-override.conf ldconfig fi echo DefaultEnvironment=\$DEFAULT_ENVIRONMENT >>/etc/systemd/system.conf @@ -741,7 +741,7 @@ printf "[Service]\nEnvironment=ASAN_OPTIONS=leak_check_at_exit=false\n" >/etc/sy # they're uninstrumented (like dmsetup). Let's add a simple rule which sets # LD_PRELOAD to the ASan RT library to fix this. mkdir -p /etc/udev/rules.d -cat > /etc/udev/rules.d/00-set-LD_PRELOAD.rules << INNER_EOF +cat >/etc/udev/rules.d/00-set-LD_PRELOAD.rules <> $initdir/etc/systemd/system.conf + echo LogLevel=debug >>$initdir/etc/systemd/system.conf # store coredumps in journal - echo Storage=journal >> $initdir/etc/systemd/coredump.conf + echo Storage=journal >>$initdir/etc/systemd/coredump.conf } get_ldpath() { @@ -1174,12 +1174,12 @@ install_config_files() { inst_any /etc/os-release /usr/lib/os-release inst /etc/localtime # we want an empty environment - > $initdir/etc/environment - > $initdir/etc/machine-id - > $initdir/etc/resolv.conf + >$initdir/etc/environment + >$initdir/etc/machine-id + >$initdir/etc/resolv.conf # set the hostname - echo systemd-testsuite > $initdir/etc/hostname + echo systemd-testsuite >$initdir/etc/hostname # let's set up just one image with the traditional verbose output if [ ${IMAGE_NAME} != "basic" ]; then @@ -1202,9 +1202,9 @@ install_debug_tools() { # Set default TERM from vt220 to linux, so at least basic key shortcuts work local _getty_override="$initdir/etc/systemd/system/serial-getty@.service.d" mkdir -p "$_getty_override" - echo -e "[Service]\nEnvironment=TERM=linux" > "$_getty_override/default-TERM.conf" + echo -e "[Service]\nEnvironment=TERM=linux" >"$_getty_override/default-TERM.conf" - cat > "$initdir/etc/motd" << EOF + cat >"$initdir/etc/motd" < $initdir/etc/dbus-1/system.d/systemd.test.ExecStopPost.conf <$initdir/etc/dbus-1/system.d/systemd.test.ExecStopPost.conf < @@ -1987,7 +1987,7 @@ install_kmod_with_fw() { fi [ -d "$initdir/.kernelmodseen" ] && \ - > "$initdir/.kernelmodseen/${1##*/}" + >"$initdir/.kernelmodseen/${1##*/}" inst_simple "$1" "/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" \ || return $? @@ -2059,11 +2059,11 @@ filter_kernel_modules_by_path () ( for _modname in $(eval $_filtercmd); do case $_modname in *.ko) "$2" "$_modname" && echo "$_modname";; - *.ko.gz) gzip -dc "$_modname" > $initdir/$$.ko + *.ko.gz) gzip -dc "$_modname" >$initdir/$$.ko $2 $initdir/$$.ko && echo "$_modname" rm -f $initdir/$$.ko ;; - *.ko.xz) xz -dc "$_modname" > $initdir/$$.ko + *.ko.xz) xz -dc "$_modname" >$initdir/$$.ko $2 $initdir/$$.ko && echo "$_modname" rm -f $initdir/$$.ko ;; @@ -2276,7 +2276,7 @@ test_setup() { fi local hook_defined=1 - if declare -f -F test_append_files > /dev/null; then + if declare -f -F test_append_files >/dev/null; then hook_defined=$? fi diff --git a/test/testsuite-28.units/specifier-j-wants.service b/test/testsuite-28.units/specifier-j-wants.service index facf5577be..766a454d6a 100644 --- a/test/testsuite-28.units/specifier-j-wants.service +++ b/test/testsuite-28.units/specifier-j-wants.service @@ -7,4 +7,4 @@ After=testsuite-28-pre.service [Service] Type=oneshot ExecStart=test -f /tmp/test-specifier-j-%j -ExecStart=sh -c 'echo OK > /testok' +ExecStart=sh -c 'echo OK >/testok' diff --git a/test/testsuite-52.units/testsuite-52.sh b/test/testsuite-52.units/testsuite-52.sh index 9cccf1b6c1..e10bf56110 100755 --- a/test/testsuite-52.units/testsuite-52.sh +++ b/test/testsuite-52.units/testsuite-52.sh @@ -3,7 +3,7 @@ set -ex set -o pipefail if ! test -x /usr/lib/systemd/tests/testdata/units/test-honor-first-shutdown.sh ; then - echo "honor-first-shutdown script not found - FAIL" > /testok + echo "honor-first-shutdown script not found - FAIL" >/testok exit 0 fi @@ -13,6 +13,6 @@ systemd-analyze log-target console systemctl enable test-honor-first-shutdown.service systemctl start test-honor-first-shutdown.service -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-03.sh b/test/units/testsuite-03.sh index 85efeeb741..5a2dadd6b8 100755 --- a/test/units/testsuite-03.sh +++ b/test/units/testsuite-03.sh @@ -6,9 +6,9 @@ set -ex systemctl start --no-block hello-after-sleep.target -systemctl list-jobs > /root/list-jobs.txt +systemctl list-jobs >/root/list-jobs.txt while ! grep 'sleep\.service.*running' /root/list-jobs.txt; do - systemctl list-jobs > /root/list-jobs.txt + systemctl list-jobs >/root/list-jobs.txt done grep 'hello\.service.*waiting' /root/list-jobs.txt @@ -19,20 +19,20 @@ systemctl start --job-mode=ignore-dependencies hello END_SEC=$(date -u '+%s') ELAPSED=$(($END_SEC-$START_SEC)) -[ "$ELAPSED" -lt 3 ] +test "$ELAPSED" -lt 3 # sleep should still be running, hello not. -systemctl list-jobs > /root/list-jobs.txt +systemctl list-jobs >/root/list-jobs.txt grep 'sleep\.service.*running' /root/list-jobs.txt grep 'hello\.service' /root/list-jobs.txt && exit 1 systemctl stop sleep.service hello-after-sleep.target # Some basic testing that --show-transaction does something useful -! systemctl is-active systemd-importd +systemctl is-active systemd-importd && { echo 'unexpected success'; exit 1; } systemctl -T start systemd-importd systemctl is-active systemd-importd systemctl --show-transaction stop systemd-importd -! systemctl is-active systemd-importd +systemctl is-active systemd-importd && { echo 'unexpected success'; exit 1; } # Test for a crash when enqueuing a JOB_NOP when other job already exists systemctl start --no-block hello-after-sleep.target @@ -58,13 +58,13 @@ systemctl stop --job-mode=replace-irreversibly unstoppable.service systemctl start unstoppable.service # Test waiting for a started unit(s) to terminate again -cat < /run/systemd/system/wait2.service +cat </run/systemd/system/wait2.service [Unit] Description=Wait for 2 seconds [Service] ExecStart=/bin/sh -ec 'sleep 2' EOF -cat < /run/systemd/system/wait5fail.service +cat </run/systemd/system/wait5fail.service [Unit] Description=Wait for 5 seconds and fail [Service] @@ -80,7 +80,7 @@ ELAPSED=$(($END_SEC-$START_SEC)) # wait5fail fails, so systemctl should fail START_SEC=$(date -u '+%s') -! systemctl start --wait wait2.service wait5fail.service || exit 1 +systemctl start --wait wait2.service wait5fail.service && { echo 'unexpected success'; exit 1; } END_SEC=$(date -u '+%s') ELAPSED=$(($END_SEC-$START_SEC)) [[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] || exit 1 diff --git a/test/units/testsuite-04.sh b/test/units/testsuite-04.sh index 3dce73b778..a2a1292380 100755 --- a/test/units/testsuite-04.sh +++ b/test/units/testsuite-04.sh @@ -59,19 +59,19 @@ journalctl -b -o export --output-fields=MESSAGE,FOO --output-fields=PRIORITY,MES grep -q '^__CURSOR=' /output grep -q '^MESSAGE=foo$' /output grep -q '^PRIORITY=6$' /output -! grep -q '^FOO=' /output -! grep -q '^SYSLOG_FACILITY=' /output +grep '^FOO=' /output && { echo 'unexpected success'; exit 1; } +grep '^SYSLOG_FACILITY=' /output && { echo 'unexpected success'; exit 1; } # `-b all` negates earlier use of -b (-b and -m are otherwise exclusive) -journalctl -b -1 -b all -m > /dev/null +journalctl -b -1 -b all -m >/dev/null # -b always behaves like -b0 -journalctl -q -b-1 -b0 | head -1 > /expected -journalctl -q -b-1 -b | head -1 > /output +journalctl -q -b-1 -b0 | head -1 >/expected +journalctl -q -b-1 -b | head -1 >/output cmp /expected /output # ... even when another option follows (both of these should fail due to -m) -{ journalctl -ball -b0 -m 2>&1 || :; } | head -1 > /expected -{ journalctl -ball -b -m 2>&1 || :; } | head -1 > /output +{ journalctl -ball -b0 -m 2>&1 || :; } | head -1 >/expected +{ journalctl -ball -b -m 2>&1 || :; } | head -1 >/output cmp /expected /output # https://github.com/systemd/systemd/issues/13708 diff --git a/test/units/testsuite-12.sh b/test/units/testsuite-12.sh index b5888a255b..7e7b0ec25a 100755 --- a/test/units/testsuite-12.sh +++ b/test/units/testsuite-12.sh @@ -14,7 +14,7 @@ SocketGroup=adm SocketMode=0660 EOF -cat <<'EOF' > /run/systemd/system/test12@.service +cat <<'EOF' >/run/systemd/system/test12@.service [Unit] Description=Test service [Service] diff --git a/test/units/testsuite-13.sh b/test/units/testsuite-13.sh index 1844323d2f..3e66aa9d54 100755 --- a/test/units/testsuite-13.sh +++ b/test/units/testsuite-13.sh @@ -51,9 +51,9 @@ function check_norbind { local _root="/var/lib/machines/testsuite-13.norbind-path" rm -rf "$_root" mkdir -p /tmp/binddir/subdir - echo -n "outer" > /tmp/binddir/subdir/file + echo -n "outer" >/tmp/binddir/subdir/file mount -t tmpfs tmpfs /tmp/binddir/subdir - echo -n "inner" > /tmp/binddir/subdir/file + echo -n "inner" >/tmp/binddir/subdir/file /usr/lib/systemd/tests/testdata/create-busybox-container "$_root" systemd-nspawn $SUSE_OPTS--register=no -D "$_root" --bind=/tmp/binddir:/mnt:norbind /bin/sh -c 'CONTENT=$(cat /mnt/subdir/file); if [[ $CONTENT != "outer" ]]; then echo "*** unexpected content: $CONTENT"; return 1; fi' } @@ -73,7 +73,7 @@ if [ -n "${VERSION_ID:+set}" ] && [ "${VERSION_ID}" != "${container_host_version if [ -n "${BUILD_ID:+set}" ] && [ "${BUILD_ID}" != "${container_host_build_id}" ]; then exit 1; fi if [ -n "${VARIANT_ID:+set}" ] && [ "${VARIANT_ID}" != "${container_host_variant_id}" ]; then exit 1; fi cd /tmp; (cd /run/host; md5sum os-release) | md5sum -c -if echo test >> /run/host/os-release; then exit 1; fi +if echo test >>/run/host/os-release; then exit 1; fi ' local _os_release_source="/etc/os-release" @@ -82,7 +82,7 @@ if echo test >> /run/host/os-release; then exit 1; fi elif [ -L "${_os_release_source}" ] && rm /etc/os-release; then # Ensure that /etc always wins if available cp /usr/lib/os-release /etc - echo MARKER=1 >> /etc/os-release + echo MARKER=1 >>/etc/os-release fi systemd-nspawn $SUSE_OPTS--register=no -D /testsuite-13.nc-container --bind="${_os_release_source}":/tmp/os-release /bin/sh -x -e -c "$_cmd" @@ -96,7 +96,7 @@ if echo test >> /run/host/os-release; then exit 1; fi function check_machinectl_bind { local _cmd='for i in $(seq 1 20); do if test -f /tmp/marker; then exit 0; fi; sleep 0.5; done; exit 1;' - cat < /run/systemd/system/nspawn_machinectl_bind.service + cat </run/systemd/system/nspawn_machinectl_bind.service [Service] Type=notify ExecStart=systemd-nspawn $SUSE_OPTS -D /testsuite-13.nc-container --notify-ready=no /bin/sh -x -e -c "$_cmd" diff --git a/test/units/testsuite-15.sh b/test/units/testsuite-15.sh index 23a39bf090..fc392c584d 100755 --- a/test/units/testsuite-15.sh +++ b/test/units/testsuite-15.sh @@ -165,7 +165,7 @@ test_hierarchical_dropins () { echo " [Service] ExecCondition=/bin/echo $dropin - " > /usr/lib/systemd/system/$dropin/override.conf + " >/usr/lib/systemd/system/$dropin/override.conf systemctl daemon-reload check_ok a-b-c ExecCondition "/bin/echo $dropin" done diff --git a/test/units/testsuite-17.01.sh b/test/units/testsuite-17.01.sh index 573ad41079..8be27d9507 100755 --- a/test/units/testsuite-17.01.sh +++ b/test/units/testsuite-17.01.sh @@ -19,7 +19,7 @@ while : ; do sleep .5 done -cat > /run/udev/rules.d/50-testsuite.rules </run/udev/rules.d/50-testsuite.rules < /run/udev/rules.d/50-testsuite.rules </run/udev/rules.d/50-testsuite.rules < /run/udev/rules.d/50-testsuite.rules </run/udev/rules.d/50-testsuite.rules < "${test_rule}" - echo "event_timeout=30" >> /etc/udev/udev.conf - echo "timeout_signal=SIGABRT" >> /etc/udev/udev.conf + echo 'KERNEL=="lo", SUBSYSTEM=="net", PROGRAM=="/bin/sleep 60"' >"${test_rule}" + echo "event_timeout=30" >>/etc/udev/udev.conf + echo "timeout_signal=SIGABRT" >>/etc/udev/udev.conf systemctl restart systemd-udevd.service } @@ -25,7 +25,7 @@ teardown() { run_test() { since="$(date +%T)" - echo add > /sys/class/net/lo/uevent + echo add >/sys/class/net/lo/uevent for n in {1..20}; do sleep 5 diff --git a/test/units/testsuite-17.04.sh b/test/units/testsuite-17.04.sh index c799936c0a..b33d47ef6d 100755 --- a/test/units/testsuite-17.04.sh +++ b/test/units/testsuite-17.04.sh @@ -4,14 +4,11 @@ set -o pipefail mkdir -p /run/udev/rules.d/ -! test -f /run/udev/tags/added/c1:3 && - ! test -f /run/udev/tags/changed/c1:3 && - udevadm info /dev/null | grep -q -v 'E: TAGS=.*:added:.*' && - udevadm info /dev/null | grep -q -v 'E: CURRENT_TAGS=.*:added:.*' && - udevadm info /dev/null | grep -q -v 'E: TAGS=.*:changed:.*' && - udevadm info /dev/null | grep -q -v 'E: CURRENT_TAGS=.*:changed:.*' +test ! -f /run/udev/tags/added/c1:3 +test ! -f /run/udev/tags/changed/c1:3 +udevadm info /dev/null | grep -E 'E: (TAGS|CURRENT_TAGS)=.*:(added|changed):' && exit 1 -cat > /run/udev/rules.d/50-testsuite.rules </run/udev/rules.d/50-testsuite.rules < /run/udev/rules.d/50-testsuite.rules </run/udev/rules.d/50-testsuite.rules < /firstphase + echo OK >/firstphase systemd-run --wait -p SuccessAction=reboot true else - echo OK > /testok + echo OK >/testok systemd-run --wait -p FailureAction=poweroff false fi diff --git a/test/units/testsuite-19.sh b/test/units/testsuite-19.sh index 57831c267f..dea2f4ba1f 100755 --- a/test/units/testsuite-19.sh +++ b/test/units/testsuite-19.sh @@ -34,6 +34,6 @@ else echo "Skipping TEST-19-DELEGATE, as the kernel doesn't actually support cgroup v2" >&2 fi -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-20.sh b/test/units/testsuite-20.sh index d94f6b2afb..6003e4f181 100755 --- a/test/units/testsuite-20.sh +++ b/test/units/testsuite-20.sh @@ -71,7 +71,7 @@ disown sleep infinity & disown -echo \$MAINPID > /run/mainpidsh/pid +echo \$MAINPID >/run/mainpidsh/pid EOF chmod +x /tmp/test20-mainpid.sh @@ -95,7 +95,7 @@ disown sleep infinity & disown -echo \$MAINPID > /run/mainpidsh2/pid +echo \$MAINPID >/run/mainpidsh2/pid chown 1001:1001 /run/mainpidsh2/pid EOF chmod +x /tmp/test20-mainpid2.sh @@ -126,14 +126,24 @@ test -f /run/mainpidsh3/pid EOF chmod 755 /dev/shm/test20-mainpid3.sh -# This has to fail, as we shouldn't accept the dangerous PID file, and then inotify-wait on it to be corrected which we never do -! systemd-run --unit=test20-mainpidsh3.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh3 -p PIDFile=/run/mainpidsh3/pid -p DynamicUser=1 -p TimeoutStartSec=2s /dev/shm/test20-mainpid3.sh +# This has to fail, as we shouldn't accept the dangerous PID file, and then +# inotify-wait on it to be corrected which we never do. +systemd-run --unit=test20-mainpidsh3.service \ + -p StandardOutput=tty \ + -p StandardError=tty \ + -p Type=forking \ + -p RuntimeDirectory=mainpidsh3 \ + -p PIDFile=/run/mainpidsh3/pid \ + -p DynamicUser=1 \ + -p TimeoutStartSec=2s \ + /dev/shm/test20-mainpid3.sh \ + && { echo 'unexpected success'; exit 1; } # Test that this failed due to timeout, and not some other error -test `systemctl show -P Result test20-mainpidsh3.service` = timeout +test $(systemctl show -P Result test20-mainpidsh3.service) = timeout systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-22.01.sh b/test/units/testsuite-22.01.sh index d233e37fb2..b10b5aaa1a 100755 --- a/test/units/testsuite-22.01.sh +++ b/test/units/testsuite-22.01.sh @@ -10,4 +10,4 @@ rm -fr /tmp/test echo "e /tmp/test - root root 1d" | systemd-tmpfiles --create - -! test -e /tmp/test +test ! -e /tmp/test diff --git a/test/units/testsuite-22.02.sh b/test/units/testsuite-22.02.sh index d1bf1ea04b..c337cd6e05 100755 --- a/test/units/testsuite-22.02.sh +++ b/test/units/testsuite-22.02.sh @@ -63,7 +63,7 @@ e /tmp/e/1 0755 daemon daemon - - e /tmp/e/2/* 0755 daemon daemon - - EOF -! test -d /tmp/e/1 +test ! -d /tmp/e/1 test -d /tmp/e/2 test $(stat -c %U:%G:%a /tmp/e/2) = "root:root:777" @@ -80,7 +80,7 @@ chmod 777 /tmp/e/3/d* touch /tmp/e/3/f1 chmod 644 /tmp/e/3/f1 -! systemd-tmpfiles --create - </tmp/F/rw-fs/foo -! systemd-tmpfiles --create - </tmp/F/rw-fs/foo -! systemd-tmpfiles --create - < fails. -! systemd-tmpfiles --create - < /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-25.sh b/test/units/testsuite-25.sh index e3dd43add3..d4d2e0f953 100755 --- a/test/units/testsuite-25.sh +++ b/test/units/testsuite-25.sh @@ -34,8 +34,8 @@ cmp /var/tmp/testimage.raw /var/lib/machines/testimage3.raw # Test removal machinectl remove testimage -! test -f /var/lib/machines/testimage.raw -! machinectl image-status testimage +test ! -f /var/lib/machines/testimage.raw +machinectl image-status testimage && { echo 'unexpected success'; exit 1; } # Test export of clone machinectl export-raw testimage3 /var/tmp/testimage3.raw @@ -46,8 +46,8 @@ rm /var/tmp/testimage3.raw machinectl rename testimage3 testimage4 test -f /var/lib/machines/testimage4.raw machinectl image-status testimage4 -! test -f /var/lib/machines/testimage3.raw -! machinectl image-status testimage3 +test ! -f /var/lib/machines/testimage3.raw +machinectl image-status testimage3 && { echo 'unexpected success'; exit 1; } cmp /var/tmp/testimage.raw /var/lib/machines/testimage4.raw # Test export of rename @@ -57,8 +57,8 @@ rm /var/tmp/testimage4.raw # Test removal machinectl remove testimage4 -! test -f /var/lib/machines/testimage4.raw -! machinectl image-status testimage4 +test ! -f /var/lib/machines/testimage4.raw +machinectl image-status testimage4 && { echo 'unexpected success'; exit 1; } # → And now, let's test directory trees ← # @@ -67,7 +67,7 @@ mkdir /var/tmp/scratch mv /var/tmp/testimage.raw /var/tmp/scratch/ touch /var/tmp/scratch/anotherfile mkdir /var/tmp/scratch/adirectory -echo "piep" > /var/tmp/scratch/adirectory/athirdfile +echo "piep" >/var/tmp/scratch/adirectory/athirdfile # Test import-fs machinectl import-fs /var/tmp/scratch/ @@ -90,8 +90,8 @@ diff -r /var/tmp/scratch/ /var/lib/machines/scratch2 # Test removal machinectl remove scratch -! test -f /var/lib/machines/scratch -! machinectl image-status scratch +test ! -f /var/lib/machines/scratch +machinectl image-status scratchi && { echo 'unexpected success'; exit 1; } # Test clone machinectl clone scratch2 scratch3 @@ -103,21 +103,21 @@ diff -r /var/tmp/scratch/ /var/lib/machines/scratch3 # Test removal machinectl remove scratch2 -! test -f /var/lib/machines/scratch2 -! machinectl image-status scratch2 +test ! -f /var/lib/machines/scratch2 +machinectl image-status scratch2 && { echo 'unexpected success'; exit 1; } # Test rename machinectl rename scratch3 scratch4 test -d /var/lib/machines/scratch4 machinectl image-status scratch4 -! test -f /var/lib/machines/scratch3 -! machinectl image-status scratch3 +test ! -f /var/lib/machines/scratch3 +machinectl image-status scratch3 && { echo 'unexpected success'; exit 1; } diff -r /var/tmp/scratch/ /var/lib/machines/scratch4 # Test removal machinectl remove scratch4 -! test -f /var/lib/machines/scratch4 -! machinectl image-status scratch4 +test ! -f /var/lib/machines/scratch4 +machinectl image-status scratch4 && { echo 'unexpected success'; exit 1; } # Test import-tar hyphen/stdin pipe behavior cat /var/tmp/scratch.tar.gz | machinectl import-tar - scratch5 @@ -135,9 +135,9 @@ rm -rf /var/tmp/scratch # Test removal machinectl remove scratch5 -! test -f /var/lib/machines/scratch5 -! machinectl image-status scratch5 +test ! -f /var/lib/machines/scratch5 +machinectl image-status scratch5 && { echo 'unexpected success'; exit 1; } -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-26.sh b/test/units/testsuite-26.sh index 89c0937c8d..9c1abc5916 100755 --- a/test/units/testsuite-26.sh +++ b/test/units/testsuite-26.sh @@ -22,10 +22,10 @@ systemctl show-environment | grep -q '^FOO=BAR$' systemctl unset-environment FOO PATH # Check that one is gone and the other reverted to the built-in -! (systemctl show-environment | grep -q '^FOO=$') -! (systemctl show-environment | grep -q '^PATH=.*testaddition$') +systemctl show-environment | grep '^FOO=$' && exit 1 +systemctl show-environment | grep '^PATH=.*testaddition$' && exit 1 systemctl show-environment | grep -q '^PATH=' -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-29.sh b/test/units/testsuite-29.sh index 2e55c275bf..4e91aa7336 100755 --- a/test/units/testsuite-29.sh +++ b/test/units/testsuite-29.sh @@ -93,6 +93,6 @@ umount /tmp/overlay umount /tmp/rootdir umount /tmp/app1 -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-30.sh b/test/units/testsuite-30.sh index a507ffcd7b..cb3b46d2cb 100755 --- a/test/units/testsuite-30.sh +++ b/test/units/testsuite-30.sh @@ -13,19 +13,19 @@ timedatectl set-time 1980-10-15 systemd-run --on-timezone-change touch /tmp/timezone-changed systemd-run --on-clock-change touch /tmp/clock-changed -! test -f /tmp/timezone-changed -! test -f /tmp/clock-changed +test ! -f /tmp/timezone-changed +test ! -f /tmp/clock-changed timedatectl set-timezone Europe/Kiev -while ! test -f /tmp/timezone-changed ; do sleep .5 ; done +while test ! -f /tmp/timezone-changed ; do sleep .5 ; done timedatectl set-time 2018-1-1 -while ! test -f /tmp/clock-changed ; do sleep .5 ; done +while test ! -f /tmp/clock-changed ; do sleep .5 ; done systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-31.sh b/test/units/testsuite-31.sh index fcff82d804..42873bfd83 100755 --- a/test/units/testsuite-31.sh +++ b/test/units/testsuite-31.sh @@ -6,5 +6,5 @@ if journalctl -b -t systemd --grep '\.device: Changed plugged -> dead'; then exit 1 fi -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-33.sh b/test/units/testsuite-33.sh index 0a6ee57b99..929c76062b 100755 --- a/test/units/testsuite-33.sh +++ b/test/units/testsuite-33.sh @@ -4,7 +4,7 @@ set -ex set -o pipefail -cat > /etc/systemd/system/testservice.service </etc/systemd/system/testservice.service < /etc/systemd/system/testservice.service </etc/systemd/system/testservice.service < /etc/systemd/system/tmp-hoge.mount </etc/systemd/system/tmp-hoge.mount < /etc/systemd/system/testservice.socket </etc/systemd/system/testservice.socket < /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-34.sh b/test/units/testsuite-34.sh index 6d9488688a..ca54a01f40 100755 --- a/test/units/testsuite-34.sh +++ b/test/units/testsuite-34.sh @@ -9,38 +9,41 @@ systemd-analyze log-target console systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz touch /var/lib/zzz/test systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test -! systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing +systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing \ + && { echo 'unexpected success'; exit 1; } test -d /var/lib/zzz -! test -L /var/lib/zzz -! test -e /var/lib/private/zzz +test ! -L /var/lib/zzz +test ! -e /var/lib/private/zzz test -f /var/lib/zzz/test -! test -f /var/lib/zzz/test-missing +test ! -f /var/lib/zzz/test-missing # Convert to DynamicUser=1 systemd-run --wait -p DynamicUser=1 -p StateDirectory=zzz test -f /var/lib/zzz/test -! systemd-run --wait -p DynamicUser=1 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing +systemd-run --wait -p DynamicUser=1 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing \ + && { echo 'unexpected success'; exit 1; } test -L /var/lib/zzz test -d /var/lib/private/zzz test -f /var/lib/zzz/test -! test -f /var/lib/zzz/test-missing +test ! -f /var/lib/zzz/test-missing # Convert back systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test -! systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing +systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing \ + && { echo 'unexpected success'; exit 1; } test -d /var/lib/zzz -! test -L /var/lib/zzz -! test -e /var/lib/private/zzz +test ! -L /var/lib/zzz +test ! -e /var/lib/private/zzz test -f /var/lib/zzz/test -! test -f /var/lib/zzz/test-missing +test ! -f /var/lib/zzz/test-missing systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-36.sh b/test/units/testsuite-36.sh index f5579ce825..3decf4b3f3 100755 --- a/test/units/testsuite-36.sh +++ b/test/units/testsuite-36.sh @@ -55,7 +55,7 @@ stopJournalctl() { # the --sync wait until the synchronization is complete echo "Force journald to write all queued messages" journalctl --sync - journalctl -u $unit --cursor-file="$journalCursorFile" > "$journalLog" + journalctl -u $unit --cursor-file="$journalCursorFile" >"$journalLog" } checkNUMA() { @@ -64,21 +64,21 @@ checkNUMA() { } writePID1NUMAPolicy() { - echo [Manager] > $confDir/numa.conf - echo NUMAPolicy=$1 >> $confDir/numa.conf - echo NUMAMask=$2>> $confDir/numa.conf + echo [Manager] >$confDir/numa.conf + echo NUMAPolicy=$1 >>$confDir/numa.conf + echo NUMAMask=$2 >>$confDir/numa.conf } writeTestUnit() { mkdir -p $testUnitFile.d/ - echo [Service] > $testUnitFile - echo ExecStart=/bin/sleep 3600 >> $testUnitFile + echo [Service] >$testUnitFile + echo ExecStart=/bin/sleep 3600 >>$testUnitFile } writeTestUnitNUMAPolicy() { - echo [Service] > $testUnitNUMAConf - echo NUMAPolicy=$1 >> $testUnitNUMAConf - echo NUMAMask=$2>> $testUnitNUMAConf + echo [Service] >$testUnitNUMAConf + echo NUMAPolicy=$1 >>$testUnitNUMAConf + echo NUMAMask=$2 >>$testUnitNUMAConf systemctl daemon-reload } @@ -115,13 +115,13 @@ pid1StopUnit() { systemctlCheckNUMAProperties() { local LOGFILE="$(mktemp)" - systemctl show -p NUMAPolicy $1 > "$LOGFILE" + systemctl show -p NUMAPolicy $1 >"$LOGFILE" grep "NUMAPolicy=$2" "$LOGFILE" - > "$LOGFILE" + >"$LOGFILE" if [ -n "$3" ]; then - systemctl show -p NUMAMask $1 > "$LOGFILE" + systemctl show -p NUMAMask $1 >"$LOGFILE" grep "NUMAMask=$3" "$LOGFILE" fi } @@ -281,7 +281,7 @@ else echo "Unit file CPUAffinity=NUMA support" writeTestUnitNUMAPolicy "bind" "0" - echo "CPUAffinity=numa" >> $testUnitNUMAConf + echo "CPUAffinity=numa" >>$testUnitNUMAConf systemctl daemon-reload systemctl start $testUnit systemctlCheckNUMAProperties $testUnit "bind" "0" @@ -336,6 +336,6 @@ systemctl daemon-reload systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-37.sh b/test/units/testsuite-37.sh index 32a9dd8694..3ae0cb32fe 100755 --- a/test/units/testsuite-37.sh +++ b/test/units/testsuite-37.sh @@ -12,8 +12,8 @@ touch /tmp/aaa/bbb systemctl restart tmp-aaa.mount test -e /run/hoge/foo -! test -e /tmp/aaa/bbb +test ! -e /tmp/aaa/bbb -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-38.sh b/test/units/testsuite-38.sh index 18b7bd6dce..707fd8a864 100755 --- a/test/units/testsuite-38.sh +++ b/test/units/testsuite-38.sh @@ -245,7 +245,7 @@ test_preserve_state() { echo "Test that freezer state is preserved when recursive freezing is initiated from outside (e.g. by manager up the tree):" echo -n " - freeze from outside: " - echo 1 > /sys/fs/cgroup/"${slice}"/cgroup.freeze + echo 1 >/sys/fs/cgroup/"${slice}"/cgroup.freeze # Give kernel some time to freeze the slice sleep 1 @@ -259,7 +259,7 @@ test_preserve_state() { echo "[ OK ]" echo -n " - thaw from outside: " - echo 0 > /sys/fs/cgroup/"${slice}"/cgroup.freeze + echo 0 >/sys/fs/cgroup/"${slice}"/cgroup.freeze sleep 1 check_freezer_state "${unit}" "running" @@ -271,8 +271,8 @@ test_preserve_state() { echo -n " - thaw from outside while inner service is frozen: " systemctl freeze "$unit" check_freezer_state "${unit}" "frozen" - echo 1 > /sys/fs/cgroup/"${slice}"/cgroup.freeze - echo 0 > /sys/fs/cgroup/"${slice}"/cgroup.freeze + echo 1 >/sys/fs/cgroup/"${slice}"/cgroup.freeze + echo 0 >/sys/fs/cgroup/"${slice}"/cgroup.freeze check_freezer_state "${slice}" "running" check_freezer_state "${unit}" "frozen" echo "[ OK ]" @@ -293,5 +293,5 @@ test -e /sys/fs/cgroup/system.slice/cgroup.freeze && { test_preserve_state } -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-39.sh b/test/units/testsuite-39.sh index eb7363fa6a..5c0680878f 100755 --- a/test/units/testsuite-39.sh +++ b/test/units/testsuite-39.sh @@ -11,7 +11,7 @@ SERVICE_PATH="$(mktemp /etc/systemd/system/execreloadXXX.service)" SERVICE_NAME="${SERVICE_PATH##*/}" echo "[#1] Failing ExecReload= should not kill the service" -cat > "$SERVICE_PATH" << EOF +cat >"$SERVICE_PATH" < "$SERVICE_PATH" << EOF +cat >"$SERVICE_PATH" < "$SERVICE_PATH" << EOF +cat >"$SERVICE_PATH" < /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-40.sh b/test/units/testsuite-40.sh index 957d22031a..7593401369 100755 --- a/test/units/testsuite-40.sh +++ b/test/units/testsuite-40.sh @@ -41,6 +41,6 @@ done systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-41.sh b/test/units/testsuite-41.sh index 81fa1716f1..0a43f8ba57 100755 --- a/test/units/testsuite-41.sh +++ b/test/units/testsuite-41.sh @@ -9,7 +9,8 @@ systemd-analyze log-level debug systemd-analyze log-target console # test one: Restart=on-failure should restart the service -! systemd-run --unit=one -p Type=oneshot -p Restart=on-failure /bin/bash -c "exit 1" +systemd-run --unit=one -p Type=oneshot -p Restart=on-failure /bin/bash -c "exit 1" \ + && { echo 'unexpected success'; exit 1; } for ((secs=0; secs<$MAX_SECS; secs++)); do [[ "$(systemctl show one.service -P NRestarts)" -le 0 ]] || break @@ -25,7 +26,13 @@ TMP_FILE="/tmp/test-41-oneshot-restart-test" # test two: make sure StartLimitBurst correctly limits the number of restarts # and restarts execution of the unit from the first ExecStart= -! systemd-run --unit=two -p StartLimitIntervalSec=120 -p StartLimitBurst=3 -p Type=oneshot -p Restart=on-failure -p ExecStart="/bin/bash -c \"printf a >> $TMP_FILE\"" /bin/bash -c "exit 1" +systemd-run --unit=two \ + -p StartLimitIntervalSec=120 \ + -p StartLimitBurst=3 \ + -p Type=oneshot \ + -p Restart=on-failure \ + -p ExecStart="/bin/bash -c \"printf a >> $TMP_FILE\"" /bin/bash -c "exit 1" \ + && { echo 'unexpected success'; exit 1; } # wait for at least 3 restarts for ((secs=0; secs<$MAX_SECS; secs++)); do @@ -44,6 +51,6 @@ fi systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-42.sh b/test/units/testsuite-42.sh index 154398dd66..ca13c5dec5 100755 --- a/test/units/testsuite-42.sh +++ b/test/units/testsuite-42.sh @@ -6,16 +6,18 @@ systemd-analyze log-level debug systemd-run --unit=simple1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=simple -p ExecStopPost='/bin/touch /run/simple1' true test -f /run/simple1 -! systemd-run --unit=simple2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=simple -p ExecStopPost='/bin/touch /run/simple2' false +systemd-run --unit=simple2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=simple -p ExecStopPost='/bin/touch /run/simple2' false \ + && { echo 'unexpected success'; exit 1; } test -f /run/simple2 systemd-run --unit=exec1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=exec -p ExecStopPost='/bin/touch /run/exec1' sleep 1 test -f /run/exec1 -! systemd-run --unit=exec2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=exec -p ExecStopPost='/bin/touch /run/exec2' sh -c 'sleep 1; false' +systemd-run --unit=exec2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=exec -p ExecStopPost='/bin/touch /run/exec2' sh -c 'sleep 1; false' \ + && { echo 'unexpected success'; exit 1; } test -f /run/exec2 -cat > /tmp/forking1.sh </tmp/forking1.sh < /tmp/forking2.sh </tmp/forking2.sh < /tmp/notify1.sh </tmp/notify1.sh < /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-43.sh b/test/units/testsuite-43.sh index ec84868a21..f3c0ca4fd2 100755 --- a/test/units/testsuite-43.sh +++ b/test/units/testsuite-43.sh @@ -34,9 +34,10 @@ test -e /home/testuser/works.txt runas testuser systemd-run --wait --user --unit=test-protect-home-read-only \ -p PrivateUsers=yes -p ProtectHome=read-only \ -P bash -c ' - test -e /home/testuser/works.txt - ! touch /home/testuser/blocked.txt - ' + test -e /home/testuser/works.txt || exit 10 + touch /home/testuser/blocked.txt && exit 11 + ' \ + && { echo 'unexpected success'; exit 1; } test ! -e /home/testuser/blocked.txt # Check that tmpfs hides the whole directory @@ -57,12 +58,13 @@ runas testuser systemd-run --wait --user --unit=test-protect-home-yes \ # namespace (no CAP_SETGID in the parent namespace to write the additional # mapping of the user supplied group and thus cannot change groups to an # unmapped group ID) -! runas testuser systemd-run --wait --user --unit=test-group-fail \ +runas testuser systemd-run --wait --user --unit=test-group-fail \ -p PrivateUsers=yes -p Group=daemon \ - -P true + -P true \ + && { echo 'unexpected success'; exit 1; } systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-44.sh b/test/units/testsuite-44.sh index 97541634d0..0badb71125 100755 --- a/test/units/testsuite-44.sh +++ b/test/units/testsuite-44.sh @@ -6,14 +6,14 @@ systemd-analyze log-level debug systemd-run -p LogNamespace=foobar echo "hello world" journalctl --namespace=foobar --sync -journalctl --namespace=foobar > /tmp/hello-world -journalctl > /tmp/no-hello-world +journalctl -o cat --namespace=foobar >/tmp/hello-world +journalctl -o cat >/tmp/no-hello-world -grep "hello world" /tmp/hello-world -! grep "hello world" /tmp/no-hello-world +grep "^hello world$" /tmp/hello-world +grep "^hello world$" /tmp/no-hello-world && { echo 'unexpected success'; exit 1; } systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-46.sh b/test/units/testsuite-46.sh index 00bbdf507e..d3f0f71043 100755 --- a/test/units/testsuite-46.sh +++ b/test/units/testsuite-46.sh @@ -4,22 +4,21 @@ set -o pipefail # Check if homectl is installed, and if it isn't bail out early instead of failing if ! test -x /usr/bin/homectl ; then - echo OK > /testok + echo OK >/testok exit 0 fi inspect() { - # As updating disk-size-related attributes can take some time on - # some filesystems, let's drop these fields before comparing the - # outputs to avoid unexpected fails. To see the full outputs of both - # homectl & userdbctl (for debugging purposes) drop the fields just - # before the comparison. - homectl inspect $1 | tee /tmp/a - userdbctl user $1 | tee /tmp/b + # As updating disk-size-related attributes can take some time on some + # filesystems, let's drop these fields before comparing the outputs to + # avoid unexpected fails. To see the full outputs of both homectl & + # userdbctl (for debugging purposes) drop the fields just before the + # comparison. + homectl inspect $1 | tee /tmp/a + userdbctl user $1 | tee /tmp/b - local PATTERN='/^\s*Disk (Size|Free|Floor|Ceiling):/d' - diff <(sed -r "$PATTERN" /tmp/a) <(sed -r "$PATTERN" /tmp/b) - rm /tmp/a /tmp/b + diff -I '/^\s*Disk (Size|Free|Floor|Ceiling):/' /tmp/{a,b} + rm /tmp/{a,b} } systemd-analyze log-level debug @@ -66,16 +65,20 @@ inspect test-user PASSWORD=xEhErW0ndafV4s homectl deactivate test-user inspect test-user -! PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz +PASSWORD=xEhErW0ndafV4s homectl with test-user -- test ! -f /home/test-user/xyz +PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz \ + && { echo 'unexpected success'; exit 1; } PASSWORD=xEhErW0ndafV4s homectl with test-user -- touch /home/test-user/xyz PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz PASSWORD=xEhErW0ndafV4s homectl with test-user -- rm /home/test-user/xyz -! PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz +PASSWORD=xEhErW0ndafV4s homectl with test-user -- test ! -f /home/test-user/xyz +PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz \ + && { echo 'unexpected success'; exit 1; } homectl remove test-user systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-47-repro.sh b/test/units/testsuite-47-repro.sh index 8c34289c52..b008f52e95 100755 --- a/test/units/testsuite-47-repro.sh +++ b/test/units/testsuite-47-repro.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash sleep infinity & -echo $! > /leakedtestpid +echo $! >/leakedtestpid wait $! diff --git a/test/units/testsuite-47.sh b/test/units/testsuite-47.sh index 50034cf3d9..f8529083a2 100755 --- a/test/units/testsuite-47.sh +++ b/test/units/testsuite-47.sh @@ -20,6 +20,6 @@ ps -p "$leaked_pid" && exit 42 systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-48.sh b/test/units/testsuite-48.sh index 03231e71b1..ea84b1d723 100755 --- a/test/units/testsuite-48.sh +++ b/test/units/testsuite-48.sh @@ -3,7 +3,7 @@ # ex: ts=8 sw=4 sts=4 et filetype=sh set -ex -cat > /run/systemd/system/testservice-48.target </run/systemd/system/testservice-48.target < /run/systemd/system/testservice-48.service </run/systemd/system/testservice-48.service < /run/systemd/system/testservice-48.service </run/systemd/system/testservice-48.service < /run/systemd/system/testservice-48.target </run/systemd/system/testservice-48.target < /run/systemd/system/testservice-48.service </run/systemd/system/testservice-48.service < /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-49.sh b/test/units/testsuite-49.sh index 07bb20d99c..f92280f884 100755 --- a/test/units/testsuite-49.sh +++ b/test/units/testsuite-49.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -ex -echo "MARKER_FIXED" > /run/testservice-49-fixed +echo "MARKER_FIXED" >/run/testservice-49-fixed mkdir -p /run/inaccessible systemctl start testsuite-49-namespaced.service @@ -11,7 +11,7 @@ set +e systemctl bind --mkdir testsuite-49-namespaced.service /run/testservice-49-fixed /run/inaccessible/testfile_fixed && exit 1 set -e -echo "MARKER_RUNTIME" > /run/testservice-49-runtime +echo "MARKER_RUNTIME" >/run/testservice-49-runtime systemctl bind --mkdir testsuite-49-namespaced.service /run/testservice-49-runtime /tmp/testfile_runtime @@ -38,6 +38,6 @@ set +e systemctl is-active testsuite-49-non-namespaced.service && exit 1 set -e -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-50.sh b/test/units/testsuite-50.sh index ae4e520ee0..b3c120d9a6 100755 --- a/test/units/testsuite-50.sh +++ b/test/units/testsuite-50.sh @@ -207,7 +207,7 @@ grep -F "squashfs" ${image_dir}/result/c | grep -q -F -v "nosuid" # Adding a new mounts at runtime works if the unit is in the active state, # so use Type=notify to make sure there's no race condition in the test -cat > /run/systemd/system/testservice-50d.service </run/systemd/system/testservice-50d.service < /tmp/ts54-concat + cat '${CREDENTIALS_DIRECTORY}/passwd' '${CREDENTIALS_DIRECTORY}/shadow' '${CREDENTIALS_DIRECTORY}/dog' >/tmp/ts54-concat ( cat /etc/passwd /etc/shadow && echo -n wuff ) | cmp /tmp/ts54-concat rm /tmp/ts54-concat # Verify that the creds are immutable -! systemd-run -p LoadCredential=passwd:/etc/passwd \ +systemd-run -p LoadCredential=passwd:/etc/passwd \ -p DynamicUser=1 \ --wait \ - touch '${CREDENTIALS_DIRECTORY}/passwd' -! systemd-run -p LoadCredential=passwd:/etc/passwd \ + touch '${CREDENTIALS_DIRECTORY}/passwd' \ + && { echo 'unexpected success'; exit 1; } +systemd-run -p LoadCredential=passwd:/etc/passwd \ -p DynamicUser=1 \ --wait \ - rm '${CREDENTIALS_DIRECTORY}/passwd' + rm '${CREDENTIALS_DIRECTORY}/passwd' \ + && { echo 'unexpected success'; exit 1; } systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-55.sh b/test/units/testsuite-55.sh index f7896ada42..d73f4b1e7a 100755 --- a/test/units/testsuite-55.sh +++ b/test/units/testsuite-55.sh @@ -6,19 +6,19 @@ systemd-analyze log-level debug systemd-analyze log-target console # Loose checks to ensure the environment has the necessary features for systemd-oomd -[[ -e /proc/pressure ]] || echo "no PSI" >> /skipped +[[ -e /proc/pressure ]] || echo "no PSI" >>/skipped cgroup_type=$(stat -fc %T /sys/fs/cgroup/) if [[ "$cgroup_type" != *"cgroup2"* ]] && [[ "$cgroup_type" != *"0x63677270"* ]]; then - echo "no cgroup2" >> /skipped + echo "no cgroup2" >>/skipped fi if [ ! -f /usr/lib/systemd/systemd-oomd ] && [ ! -f /lib/systemd/systemd-oomd ]; then - echo "no oomd" >> /skipped + echo "no oomd" >>/skipped fi [[ -e /skipped ]] && exit 0 || true rm -rf /etc/systemd/system/testsuite-55-testbloat.service.d -echo "DefaultMemoryPressureDurationSec=5s" >> /etc/systemd/oomd.conf +echo "DefaultMemoryPressureDurationSec=5s" >>/etc/systemd/oomd.conf systemctl start testsuite-55-testchill.service systemctl start testsuite-55-testbloat.service @@ -47,8 +47,8 @@ if setfattr -n user.xattr_test -v 1 /sys/fs/cgroup/; then sleep 120 # wait for systemd-oomd kill cool down and elevated memory pressure to come down mkdir -p /etc/systemd/system/testsuite-55-testbloat.service.d/ - echo "[Service]" > /etc/systemd/system/testsuite-55-testbloat.service.d/override.conf - echo "ManagedOOMPreference=avoid" >> /etc/systemd/system/testsuite-55-testbloat.service.d/override.conf + echo "[Service]" >/etc/systemd/system/testsuite-55-testbloat.service.d/override.conf + echo "ManagedOOMPreference=avoid" >>/etc/systemd/system/testsuite-55-testbloat.service.d/override.conf systemctl daemon-reload systemctl start testsuite-55-testchill.service @@ -71,6 +71,6 @@ fi systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0 diff --git a/test/units/testsuite-56.sh b/test/units/testsuite-56.sh index 9de03e1dea..079da07201 100755 --- a/test/units/testsuite-56.sh +++ b/test/units/testsuite-56.sh @@ -29,11 +29,13 @@ systemd-run --wait --unit=one -p ExitType=cgroup /tmp/test56-exit-cgroup.sh systemd-run --wait --unit=two -p ExitType=cgroup -p ExecCondition=true /tmp/test56-exit-cgroup.sh # false exec condition: systemd-run should exit immediately with status code: 1 -! systemd-run --wait --unit=three -p ExitType=cgroup -p ExecCondition=false /tmp/test56-exit-cgroup.sh +systemd-run --wait --unit=three -p ExitType=cgroup -p ExecCondition=false /tmp/test56-exit-cgroup.sh \ + && { echo 'unexpected success'; exit 1; } # service should exit uncleanly (sleep 1; systemctl kill --signal 9 four) & -! systemd-run --wait --unit=four -p ExitType=cgroup /tmp/test56-exit-cgroup.sh +systemd-run --wait --unit=four -p ExitType=cgroup /tmp/test56-exit-cgroup.sh \ + && { echo 'unexpected success'; exit 1; } # Multiple level process tree, parent process exits quickly @@ -55,7 +57,8 @@ systemd-run --wait --unit=five -p ExitType=cgroup /tmp/test56-exit-cgroup-parent # service should exit uncleanly (sleep 1; systemctl kill --signal 9 six) & -! systemd-run --wait --unit=six -p ExitType=cgroup /tmp/test56-exit-cgroup-parentless.sh +systemd-run --wait --unit=six -p ExitType=cgroup /tmp/test56-exit-cgroup-parentless.sh \ + && { echo 'unexpected success'; exit 1; } # Multiple level process tree, parent process exits uncleanly but last process exits cleanly @@ -85,10 +88,11 @@ EOF chmod +x /tmp/test56-exit-cgroup-unclean.sh # service should exit uncleanly after 1 second -! systemd-run --wait --unit=eight -p ExitType=cgroup /tmp/test56-exit-cgroup-unclean.sh +systemd-run --wait --unit=eight -p ExitType=cgroup /tmp/test56-exit-cgroup-unclean.sh \ + && { echo 'unexpected success'; exit 1; } systemd-analyze log-level info -echo OK > /testok +echo OK >/testok exit 0