1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-11 05:17:44 +03:00

Merge pull request #18885 from yuwata/udev-fix-import-program-rhbz-1935062

udev: fix importing program result
This commit is contained in:
Frantisek Sumsal 2021-03-05 14:19:21 +01:00 committed by GitHub
commit 3ee0cf339b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 492 additions and 466 deletions

View File

@ -240,27 +240,28 @@ int strv_extend_strv_concat(char ***a, char * const *b, const char *suffix) {
return 0;
}
char **strv_split_newlines(const char *s) {
char **l;
int strv_split_newlines_full(char ***ret, const char *s, ExtractFlags flags) {
_cleanup_strv_free_ char **l = NULL;
size_t n;
int r;
assert(s);
/* Special version of strv_split() that splits on newlines and
* suppresses an empty string at the end */
/* Special version of strv_split_full() that splits on newlines and
* suppresses an empty string at the end. */
l = strv_split(s, NEWLINE);
if (!l)
return NULL;
r = strv_split_full(&l, s, NEWLINE, flags);
if (r < 0)
return r;
n = strv_length(l);
if (n <= 0)
return l;
if (isempty(l[n - 1]))
if (n > 0 && isempty(l[n - 1])) {
l[n - 1] = mfree(l[n - 1]);
n--;
}
return l;
*ret = TAKE_PTR(l);
return n;
}
int strv_split_full(char ***t, const char *s, const char *separators, ExtractFlags flags) {

View File

@ -73,15 +73,21 @@ static inline bool strv_isempty(char * const *l) {
return !l || !*l;
}
char **strv_split_newlines(const char *s);
int strv_split_full(char ***t, const char *s, const char *separators, ExtractFlags flags);
static inline char **strv_split(const char *s, const char *separators) {
char **ret;
int r;
r = strv_split_full(&ret, s, separators, 0);
if (r < 0)
if (strv_split_full(&ret, s, separators, 0) < 0)
return NULL;
return ret;
}
int strv_split_newlines_full(char ***ret, const char *s, ExtractFlags flags);
static inline char **strv_split_newlines(const char *s) {
char **ret;
if (strv_split_newlines_full(&ret, s, 0) < 0)
return NULL;
return ret;

View File

@ -31,6 +31,7 @@ static void test_encode_devnode_name(void) {
assert_se(expect_encoded_as("s/ash/ng", "s\\x2fash\\x2fng"));
assert_se(expect_encoded_as("/", "\\x2f"));
assert_se(expect_encoded_as("!", "\\x21"));
assert_se(expect_encoded_as("QEMU ", "QEMU\\x20\\x20\\x20\\x20"));
}
int main(int argc, char *argv[]) {

View File

@ -118,6 +118,20 @@ static const char* const input_table_one_empty[] = {
NULL,
};
static const char* const input_table_unescape[] = {
"ID_VENDOR=QEMU",
"ID_VENDOR_ENC=QEMUx20x20x20x20",
"ID_MODEL_ENC=QEMUx20HARDDISKx20x20x20",
NULL,
};
static const char* const input_table_retain_escape[] = {
"ID_VENDOR=QEMU",
"ID_VENDOR_ENC=QEMU\\x20\\x20\\x20\\x20",
"ID_MODEL_ENC=QEMU\\x20HARDDISK\\x20\\x20\\x20",
NULL,
};
static void test_strv_find(void) {
log_info("/* %s */", __func__);
@ -453,6 +467,25 @@ static void test_strv_split_newlines(void) {
assert_se(streq(*s, input_table_multiple[i++]));
}
static void test_strv_split_newlines_full(void) {
const char str[] =
"ID_VENDOR=QEMU\n"
"ID_VENDOR_ENC=QEMU\\x20\\x20\\x20\\x20\n"
"ID_MODEL_ENC=QEMU\\x20HARDDISK\\x20\\x20\\x20\n"
"\n\n\n";
_cleanup_strv_free_ char **l = NULL;
log_info("/* %s */", __func__);
assert_se(strv_split_newlines_full(&l, str, 0) == 3);
assert_se(strv_equal(l, (char**) input_table_unescape));
l = strv_free(l);
assert_se(strv_split_newlines_full(&l, str, EXTRACT_RETAIN_ESCAPE) == 3);
assert_se(strv_equal(l, (char**) input_table_retain_escape));
}
static void test_strv_split_nulstr(void) {
_cleanup_strv_free_ char **l = NULL;
const char nulstr[] = "str0\0str1\0str2\0str3\0";
@ -1031,6 +1064,7 @@ int main(int argc, char *argv[]) {
test_strv_split_full();
test_strv_split_colon_pairs();
test_strv_split_newlines();
test_strv_split_newlines_full();
test_strv_split_nulstr();
test_strv_parse_nulstr();
test_strv_overlap();

View File

@ -573,9 +573,11 @@ static int on_spawn_io(sd_event_source *s, int fd, uint32_t revents, void *userd
_cleanup_strv_free_ char **v = NULL;
char **q;
v = strv_split_newlines(p);
if (!v)
log_oom_debug();
r = strv_split_newlines_full(&v, p, EXTRACT_RETAIN_ESCAPE);
if (r < 0)
log_device_debug(spawn->device,
"Failed to split output from '%s'(%s), ignoring: %m",
spawn->cmd, fd == spawn->fd_stdout ? "out" : "err");
STRV_FOREACH(q, v)
log_device_debug(spawn->device, "'%s'(%s) '%s'", spawn->cmd,

View File

@ -1746,9 +1746,10 @@ static int udev_rule_apply_token_to_event(
return token->op == OP_NOMATCH;
}
lines = strv_split_newlines(result);
if (!lines)
return log_oom();
r = strv_split_newlines_full(&lines, result, EXTRACT_RETAIN_ESCAPE);
if (r < 0)
log_rule_warning_errno(dev, rules, r,
"Failed to extract lines from result of command \"%s\", ignoring: %m", buf);
STRV_FOREACH(line, lines) {
char *key, *value;

View File

@ -1,9 +0,0 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="UDEV SYSTEMD_WANTS property"
TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=300
do_test "$@" 17

View File

@ -1,11 +1,11 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="UDEV ID_RENAMING property"
IMAGE_NAME="udev-id-renaming"
TEST_DESCRIPTION="UDEV"
IMAGE_NAME="udev"
TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=300
QEMU_TIMEOUT=500
test_append_files() {
(
@ -14,4 +14,4 @@ test_append_files() {
)
}
do_test "$@" 29
do_test "$@" 17

View File

@ -24,4 +24,4 @@ test_append_files() {
)
}
do_test "$@" 58
do_test "$@" 29

View File

@ -4,4 +4,4 @@ set -e
TEST_DESCRIPTION="test adding new BindPaths while unit is already running"
. $TEST_BASE_DIR/test-functions
do_test "$@" 57
do_test "$@" 49

View File

@ -1,8 +0,0 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="test udev's event-timeout and timeout-signal options"
TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
do_test "$@" 49

View File

@ -45,4 +45,4 @@ check_result_qemu() {
return $ret
}
do_test "$@" 56
do_test "$@" 55

View File

@ -1,8 +0,0 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="UDEV tags management"
TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
do_test "$@" 55

View File

@ -1 +0,0 @@
../TEST-01-BASIC/Makefile

View File

@ -1 +0,0 @@
../TEST-01-BASIC/Makefile

View File

@ -1 +0,0 @@
../TEST-01-BASIC/Makefile

72
test/units/testsuite-17.01.sh Executable file
View File

@ -0,0 +1,72 @@
#!/usr/bin/env bash
set -ex
set -o pipefail
mkdir -p /run/udev/rules.d/
rm -f /run/udev/rules.d/50-testsuite.rules
udevadm control --reload
udevadm trigger /dev/sda
while : ; do
(
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=foobar.service
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q -v sda
systemctl show -p WantedBy waldo.service | grep -q -v sda
) && break
sleep .5
done
cat > /run/udev/rules.d/50-testsuite.rules <<EOF
ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sda", ENV{SYSTEMD_WANTS}="foobar.service"
EOF
udevadm control --reload
udevadm trigger /dev/sda
while : ; do
(
udevadm info /dev/sda | grep -q SYSTEMD_WANTS=foobar.service
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q sda
systemctl show -p WantedBy waldo.service | grep -q -v sda
) && break
sleep .5
done
cat > /run/udev/rules.d/50-testsuite.rules <<EOF
ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sda", ENV{SYSTEMD_WANTS}="waldo.service"
EOF
udevadm control --reload
udevadm trigger /dev/sda
while : ; do
(
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=foobar.service
udevadm info /dev/sda | grep -q SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q -v sda
systemctl show -p WantedBy waldo.service | grep -q sda
) && break
sleep .5
done
rm /run/udev/rules.d/50-testsuite.rules
udevadm control --reload
udevadm trigger /dev/sda
while : ; do
(
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=foobar.service
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q -v sda
systemctl show -p WantedBy waldo.service | grep -q -v sda
) && break
sleep .5
done
exit 0

57
test/units/testsuite-17.02.sh Executable file
View File

@ -0,0 +1,57 @@
#!/usr/bin/env bash
set -ex
set -o pipefail
mkdir -p /run/udev/rules.d/
cat > /run/udev/rules.d/50-testsuite.rules <<EOF
ACTION=="remove", GOTO="lo_end"
SUBSYSTEM=="net", KERNEL=="lo", TAG+="systemd", ENV{SYSTEMD_ALIAS}+="/sys/subsystem/net/devices/lo"
ACTION!="change", GOTO="lo_end"
SUBSYSTEM=="net", KERNEL=="lo", ENV{ID_RENAMING}="1"
LABEL="lo_end"
EOF
udevadm control --log-priority=debug --reload --timeout=600
udevadm trigger --action=add --settle /sys/devices/virtual/net/lo
udevadm info /sys/devices/virtual/net/lo
sleep 1
STATE=$(systemctl show --property=ActiveState --value sys-devices-virtual-net-lo.device)
[[ $STATE == "active" ]] || exit 1
udevadm trigger --action=change --settle /sys/devices/virtual/net/lo
udevadm info /sys/devices/virtual/net/lo
sleep 1
STATE=$(systemctl show --property=ActiveState --value sys-devices-virtual-net-lo.device)
[[ $STATE == "inactive" ]] || exit 1
udevadm trigger --action=move --settle /sys/devices/virtual/net/lo
udevadm info /sys/devices/virtual/net/lo
sleep 1
STATE=$(systemctl show --property=ActiveState --value sys-devices-virtual-net-lo.device)
[[ $STATE == "active" ]] || exit 1
rm -f /run/udev/rules.d/50-testsuite.rules
udevadm control --reload --timeout=600
# test for issue #16967
ip link add hoge type dummy
udevadm info --wait-for-initialization=10s /sys/devices/virtual/net/hoge
sleep 1
if ! systemctl status sys-devices-virtual-net-hoge.device; then exit 1; fi
if ! systemctl status sys-subsystem-net-devices-hoge.device; then exit 1; fi
ip link set hoge name foobar
udevadm info --wait-for-initialization=10s /sys/devices/virtual/net/foobar
sleep 1
if systemctl status sys-devices-virtual-net-hoge.device; then exit 1; fi
if systemctl status sys-subsystem-net-devices-hoge.device; then exit 1; fi
if ! systemctl status sys-devices-virtual-net-foobar.device; then exit 1; fi
if ! systemctl status sys-subsystem-net-devices-foobar.device; then exit 1; fi
exit 0

45
test/units/testsuite-17.03.sh Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -ex
test_rule="/run/udev/rules.d/49-test.rules"
setup() {
mkdir -p "${test_rule%/*}"
cp -f /etc/udev/udev.conf /etc/udev/udev.conf.bckp
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
}
teardown() {
set +e
mv -f /etc/udev/udev.conf.bckp /etc/udev/udev.conf
rm -f "$test_rule"
systemctl restart systemd-udevd.service
}
run_test() {
since="$(date +%T)"
echo add > /sys/class/net/lo/uevent
for n in {1..20}; do
sleep 5
if coredumpctl --since "$since" --no-legend --no-pager | grep /bin/udevadm ; then
return 0
fi
done
return 1
}
trap teardown EXIT
setup
run_test
exit 0

64
test/units/testsuite-17.04.sh Executable file
View File

@ -0,0 +1,64 @@
#!/bin/bash
set -ex
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:.*'
cat > /run/udev/rules.d/50-testsuite.rules <<EOF
ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", TAG+="added"
ACTION=="change", SUBSYSTEM=="mem", KERNEL=="null", TAG+="changed"
EOF
udevadm control --reload
udevadm trigger -c add /dev/null
while : ; do
test -f /run/udev/tags/added/c1:3 &&
! test -f /run/udev/tags/changed/c1:3 &&
udevadm info /dev/null | grep -q 'E: TAGS=.*:added:.*' &&
udevadm info /dev/null | grep -q '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:.*' &&
break
sleep .5
done
udevadm control --reload
udevadm trigger -c change /dev/null
while : ; do
test -f /run/udev/tags/added/c1:3 &&
test -f /run/udev/tags/changed/c1:3 &&
udevadm info /dev/null | grep -q 'E: TAGS=.*:added:.*' &&
udevadm info /dev/null | grep -q -v 'E: CURRENT_TAGS=.*:added:.*' &&
udevadm info /dev/null | grep -q 'E: TAGS=.*:changed:.*' &&
udevadm info /dev/null | grep -q 'E: CURRENT_TAGS=.*:changed:.*' &&
break
sleep .5
done
udevadm control --reload
udevadm trigger -c add /dev/null
while : ; do
test -f /run/udev/tags/added/c1:3 &&
test -f /run/udev/tags/changed/c1:3 &&
udevadm info /dev/null | grep -q 'E: TAGS=.*:added:.*' &&
udevadm info /dev/null | grep -q 'E: CURRENT_TAGS=.*:added:.*' &&
udevadm info /dev/null | grep -q 'E: TAGS=.*:changed:.*' &&
udevadm info /dev/null | grep -q -v 'E: CURRENT_TAGS=.*:changed:.*' &&
break
sleep .5
done
exit 0

24
test/units/testsuite-17.05.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
set -ex
set -o pipefail
mkdir -p /run/udev/rules.d/
cat > /run/udev/rules.d/50-testsuite.rules <<EOF
SUBSYSTEM=="mem", KERNEL=="null", OPTIONS="log_level=debug"
ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", IMPORT{program}="/bin/echo -e HOGE=aa\\\\x20\\\\x20\\\\x20bb\nFOO=\\\\x20aaa\\\\x20\n\n\n"
EOF
udevadm control --reload
udevadm trigger -c add /dev/null
while : ; do
test -f /run/udev/data/c1:3 &&
udevadm info /dev/null | grep -q 'E: HOGE=aa\\x20\\x20\\x20bb' &&
udevadm info /dev/null | grep -q 'E: FOO=\\x20aaa\\x20' &&
break
sleep .5
done
exit 0

View File

@ -1,5 +1,5 @@
[Unit]
Description=TEST-17-UDEV-WANTS
Description=TEST-17-UDEV
[Service]
ExecStartPre=rm -f /failed /testok

View File

@ -1,74 +1,13 @@
#!/usr/bin/env bash
set -ex
set -o pipefail
mkdir -p /run/udev/rules.d/
set -x
set -e
rm -f /run/udev/rules.d/50-testsuite.rules
udevadm control --reload
udevadm trigger /dev/sda
>/failed
while : ; do
(
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=foobar.service
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q -v sda
systemctl show -p WantedBy waldo.service | grep -q -v sda
) && break
sleep .5
for t in ${0%.sh}.*.sh; do
echo "Running $t"; ./$t
done
cat > /run/udev/rules.d/50-testsuite.rules <<EOF
ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sda", ENV{SYSTEMD_WANTS}="foobar.service"
EOF
udevadm control --reload
udevadm trigger /dev/sda
while : ; do
(
udevadm info /dev/sda | grep -q SYSTEMD_WANTS=foobar.service
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q sda
systemctl show -p WantedBy waldo.service | grep -q -v sda
) && break
sleep .5
done
cat > /run/udev/rules.d/50-testsuite.rules <<EOF
ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sda", ENV{SYSTEMD_WANTS}="waldo.service"
EOF
udevadm control --reload
udevadm trigger /dev/sda
while : ; do
(
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=foobar.service
udevadm info /dev/sda | grep -q SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q -v sda
systemctl show -p WantedBy waldo.service | grep -q sda
) && break
sleep .5
done
rm /run/udev/rules.d/50-testsuite.rules
udevadm control --reload
udevadm trigger /dev/sda
while : ; do
(
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=foobar.service
udevadm info /dev/sda | grep -q -v SYSTEMD_WANTS=waldo.service
systemctl show -p WantedBy foobar.service | grep -q -v sda
systemctl show -p WantedBy waldo.service | grep -q -v sda
) && break
sleep .5
done
echo OK >/testok
exit 0
touch /testok
rm /failed

View File

@ -1,5 +1,5 @@
[Unit]
Description=TEST-29-UDEV-ID_RENAMING
Description=TEST-29-PORTABLE
[Service]
ExecStartPre=rm -f /failed /testok

View File

@ -1,58 +1,67 @@
#!/usr/bin/env bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
set -ex
set -o pipefail
mkdir -p /run/udev/rules.d/
export SYSTEMD_LOG_LEVEL=debug
cat > /run/udev/rules.d/50-testsuite.rules <<EOF
ACTION=="remove", GOTO="lo_end"
portablectl attach --now --runtime /usr/share/minimal_0.raw app0
SUBSYSTEM=="net", KERNEL=="lo", TAG+="systemd", ENV{SYSTEMD_ALIAS}+="/sys/subsystem/net/devices/lo"
systemctl is-active app0.service
systemctl is-active app0-foo.service
set +o pipefail
set +e
systemctl is-active app0-bar.service && exit 1
set -e
set -o pipefail
ACTION!="change", GOTO="lo_end"
portablectl reattach --now --runtime /usr/share/minimal_1.raw app0
SUBSYSTEM=="net", KERNEL=="lo", ENV{ID_RENAMING}="1"
systemctl is-active app0.service
systemctl is-active app0-bar.service
set +o pipefail
set +e
systemctl is-active app0-foo.service && exit 1
set -e
set -o pipefail
LABEL="lo_end"
EOF
portablectl list | grep -q -F "minimal_1"
udevadm control --log-priority=debug --reload --timeout=600
udevadm trigger --action=add --settle /sys/devices/virtual/net/lo
udevadm info /sys/devices/virtual/net/lo
sleep 1
STATE=$(systemctl show --property=ActiveState --value sys-devices-virtual-net-lo.device)
[[ $STATE == "active" ]] || exit 1
portablectl detach --now --runtime /usr/share/minimal_1.raw app0
udevadm trigger --action=change --settle /sys/devices/virtual/net/lo
udevadm info /sys/devices/virtual/net/lo
sleep 1
STATE=$(systemctl show --property=ActiveState --value sys-devices-virtual-net-lo.device)
[[ $STATE == "inactive" ]] || exit 1
portablectl list | grep -q -F "No images."
udevadm trigger --action=move --settle /sys/devices/virtual/net/lo
udevadm info /sys/devices/virtual/net/lo
sleep 1
STATE=$(systemctl show --property=ActiveState --value sys-devices-virtual-net-lo.device)
[[ $STATE == "active" ]] || exit 1
# portablectl also works with directory paths rather than images
rm -f /run/udev/rules.d/50-testsuite.rules
udevadm control --reload --timeout=600
unsquashfs -dest /tmp/minimal_0 /usr/share/minimal_0.raw
unsquashfs -dest /tmp/minimal_1 /usr/share/minimal_1.raw
# test for issue #16967
portablectl attach --copy=symlink --now --runtime /tmp/minimal_0 app0
ip link add hoge type dummy
udevadm info --wait-for-initialization=10s /sys/devices/virtual/net/hoge
sleep 1
if ! systemctl status sys-devices-virtual-net-hoge.device; then exit 1; fi
if ! systemctl status sys-subsystem-net-devices-hoge.device; then exit 1; fi
systemctl is-active app0.service
systemctl is-active app0-foo.service
set +o pipefail
set +e
systemctl is-active app0-bar.service && exit 1
set -e
set -o pipefail
ip link set hoge name foobar
udevadm info --wait-for-initialization=10s /sys/devices/virtual/net/foobar
sleep 1
if systemctl status sys-devices-virtual-net-hoge.device; then exit 1; fi
if systemctl status sys-subsystem-net-devices-hoge.device; then exit 1; fi
if ! systemctl status sys-devices-virtual-net-foobar.device; then exit 1; fi
if ! systemctl status sys-subsystem-net-devices-foobar.device; then exit 1; fi
portablectl reattach --now --enable --runtime /tmp/minimal_1 app0
systemctl is-active app0.service
systemctl is-active app0-bar.service
set +o pipefail
set +e
systemctl is-active app0-foo.service && exit 1
set -e
set -o pipefail
portablectl list | grep -q -F "minimal_1"
portablectl detach --now --enable --runtime /tmp/minimal_1 app0
portablectl list | grep -q -F "No images."
echo OK > /testok

View File

@ -6,7 +6,7 @@ Type=notify
RemainAfterExit=yes
MountAPIVFS=yes
PrivateTmp=yes
BindPaths=/run/testservice-57-fixed:/tmp/testfile_fixed
BindPaths=/run/testservice-49-fixed:/tmp/testfile_fixed
InaccessiblePaths=/run/inaccessible
ExecStartPre=grep -q -F MARKER_FIXED /tmp/testfile_fixed
ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER_RUNTIME /tmp/testfile_runtime; do sleep 0.1; done; test ! -f /run/inaccessible/testfile_fixed'

View File

@ -1,6 +1,7 @@
[Unit]
Description=TEST-49-UDEV-EVENT-TIMEOUT
Description=TEST-49-RUNTIME-BIND-PATHS
[Service]
ExecStartPre=rm -f /failed /testok
ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
Type=oneshot

View File

@ -1,46 +1,42 @@
#!/usr/bin/env bash
set -ex
test_rule="/run/udev/rules.d/49-test.rules"
echo "MARKER_FIXED" > /run/testservice-49-fixed
mkdir -p /run/inaccessible
setup() {
mkdir -p "${test_rule%/*}"
cp -f /etc/udev/udev.conf /etc/udev/udev.conf.bckp
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 start testsuite-49-namespaced.service
systemctl restart systemd-udevd.service
}
# Ensure that inaccessible paths aren't bypassed by the runtime setup
set +e
systemctl bind --mkdir testsuite-49-namespaced.service /run/testservice-49-fixed /run/inaccessible/testfile_fixed && exit 1
set -e
teardown() {
set +e
echo "MARKER_RUNTIME" > /run/testservice-49-runtime
mv -f /etc/udev/udev.conf.bckp /etc/udev/udev.conf
rm -f "$test_rule"
systemctl restart systemd-udevd.service
}
systemctl bind --mkdir testsuite-49-namespaced.service /run/testservice-49-runtime /tmp/testfile_runtime
run_test() {
since="$(date +%T)"
while systemctl show -P SubState testsuite-49-namespaced.service | grep -q running
do
sleep 0.1
done
echo add > /sys/class/net/lo/uevent
systemctl is-active testsuite-49-namespaced.service
for n in {1..20}; do
sleep 5
if coredumpctl --since "$since" --no-legend --no-pager | grep /bin/udevadm ; then
return 0
fi
done
# Now test that systemctl bind fails when attempted on a non-namespaced unit
systemctl start testsuite-49-non-namespaced.service
return 1
}
set +e
systemctl bind --mkdir testsuite-49-non-namespaced.service /run/testservice-49-runtime /tmp/testfile_runtime && exit 1
set -e
trap teardown EXIT
while systemctl show -P SubState testsuite-49-non-namespaced.service | grep -q running
do
sleep 0.1
done
setup
run_test
set +e
systemctl is-active testsuite-49-non-namespaced.service && exit 1
set -e
echo OK > /testok

View File

@ -5,5 +5,5 @@ Description=Create a lot of memory pressure
# A VERY small memory.high will cause the script (trying to use a lot of memory)
# to throttle and be put under heavy pressure.
MemoryHigh=1M
Slice=testsuite-56-workload.slice
ExecStart=/usr/lib/systemd/tests/testdata/units/testsuite-56-slowgrowth.sh
Slice=testsuite-55-workload.slice
ExecStart=/usr/lib/systemd/tests/testdata/units/testsuite-55-slowgrowth.sh

View File

@ -2,5 +2,5 @@
Description=No memory pressure
[Service]
Slice=testsuite-56-workload.slice
Slice=testsuite-55-workload.slice
ExecStart=sleep infinity

View File

@ -0,0 +1,7 @@
[Unit]
Description=Create some memory pressure
[Service]
MemoryHigh=2M
Slice=testsuite-55-workload.slice
ExecStart=/usr/lib/systemd/tests/testdata/units/testsuite-55-slowgrowth.sh

View File

@ -1,7 +1,7 @@
[Unit]
Description=TESTSUITE-55-UDEV-TAGS
Description=TESTSUITE-55-OOMD
[Service]
ExecStartPre=rm -f /failed /testok
ExecStartPre=rm -f /failed /skipped /testok
ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
Type=oneshot

View File

@ -1,65 +1,75 @@
#!/bin/bash
#!/usr/bin/env bash
set -ex
set -o pipefail
mkdir -p /run/udev/rules.d/
systemd-analyze log-level debug
systemd-analyze log-target console
! 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:.*'
# Loose checks to ensure the environment has the necessary features for systemd-oomd
[[ -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
fi
if [ ! -f /usr/lib/systemd/systemd-oomd ] && [ ! -f /lib/systemd/systemd-oomd ]; then
echo "no oomd" >> /skipped
fi
[[ -e /skipped ]] && exit 0 || true
cat > /run/udev/rules.d/50-testsuite.rules <<EOF
ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", TAG+="added"
ACTION=="change", SUBSYSTEM=="mem", KERNEL=="null", TAG+="changed"
EOF
rm -rf /etc/systemd/system/testsuite-55-testbloat.service.d
udevadm control --reload
udevadm trigger -c add /dev/null
echo "DefaultMemoryPressureDurationSec=5s" >> /etc/systemd/oomd.conf
while : ; do
test -f /run/udev/tags/added/c1:3 &&
! test -f /run/udev/tags/changed/c1:3 &&
udevadm info /dev/null | grep -q 'E: TAGS=.*:added:.*' &&
udevadm info /dev/null | grep -q '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:.*' &&
systemctl start testsuite-55-testchill.service
systemctl start testsuite-55-testbloat.service
# Verify systemd-oomd is monitoring the expected units
oomctl | grep "/testsuite-55-workload.slice"
oomctl | grep "1.00%"
oomctl | grep "Default Memory Pressure Duration: 5s"
# systemd-oomd watches for elevated pressure for 5 seconds before acting.
# It can take time to build up pressure so either wait 2 minutes or for the service to fail.
timeout=$(date -ud "2 minutes" +%s)
while [[ $(date -u +%s) -le $timeout ]]; do
if ! systemctl status testsuite-55-testbloat.service; then
break
sleep .5
fi
sleep 5
done
udevadm control --reload
udevadm trigger -c change /dev/null
# testbloat should be killed and testchill should be fine
if systemctl status testsuite-55-testbloat.service; then exit 42; fi
if ! systemctl status testsuite-55-testchill.service; then exit 24; fi
while : ; do
test -f /run/udev/tags/added/c1:3 &&
test -f /run/udev/tags/changed/c1:3 &&
udevadm info /dev/null | grep -q 'E: TAGS=.*:added:.*' &&
udevadm info /dev/null | grep -q -v 'E: CURRENT_TAGS=.*:added:.*' &&
udevadm info /dev/null | grep -q 'E: TAGS=.*:changed:.*' &&
udevadm info /dev/null | grep -q 'E: CURRENT_TAGS=.*:changed:.*' &&
break
# only run this portion of the test if we can set xattrs
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
sleep .5
done
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
udevadm control --reload
udevadm trigger -c add /dev/null
systemctl daemon-reload
systemctl start testsuite-55-testchill.service
systemctl start testsuite-55-testmunch.service
systemctl start testsuite-55-testbloat.service
while : ; do
test -f /run/udev/tags/added/c1:3 &&
test -f /run/udev/tags/changed/c1:3 &&
udevadm info /dev/null | grep -q 'E: TAGS=.*:added:.*' &&
udevadm info /dev/null | grep -q 'E: CURRENT_TAGS=.*:added:.*' &&
udevadm info /dev/null | grep -q 'E: TAGS=.*:changed:.*' &&
udevadm info /dev/null | grep -q -v 'E: CURRENT_TAGS=.*:changed:.*' &&
break
timeout=$(date -ud "2 minutes" +%s)
while [[ $(date -u +%s) -le $timeout ]]; do
if ! systemctl status testsuite-55-testmunch.service; then
break
fi
sleep 5
done
sleep .5
done
# testmunch should be killed since testbloat had the avoid xattr on it
if ! systemctl status testsuite-55-testbloat.service; then exit 25; fi
if systemctl status testsuite-55-testmunch.service; then exit 43; fi
if ! systemctl status testsuite-55-testchill.service; then exit 24; fi
fi
systemd-analyze log-level info
echo OK > /testok

View File

@ -1,7 +0,0 @@
[Unit]
Description=Create some memory pressure
[Service]
MemoryHigh=2M
Slice=testsuite-56-workload.slice
ExecStart=/usr/lib/systemd/tests/testdata/units/testsuite-56-slowgrowth.sh

View File

@ -1,7 +0,0 @@
[Unit]
Description=TESTSUITE-56-OOMD
[Service]
ExecStartPre=rm -f /failed /skipped /testok
ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
Type=oneshot

View File

@ -1,76 +0,0 @@
#!/usr/bin/env bash
set -ex
set -o pipefail
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
cgroup_type=$(stat -fc %T /sys/fs/cgroup/)
if [[ "$cgroup_type" != *"cgroup2"* ]] && [[ "$cgroup_type" != *"0x63677270"* ]]; then
echo "no cgroup2" >> /skipped
fi
if [ ! -f /usr/lib/systemd/systemd-oomd ] && [ ! -f /lib/systemd/systemd-oomd ]; then
echo "no oomd" >> /skipped
fi
[[ -e /skipped ]] && exit 0 || true
rm -rf /etc/systemd/system/testsuite-56-testbloat.service.d
echo "DefaultMemoryPressureDurationSec=5s" >> /etc/systemd/oomd.conf
systemctl start testsuite-56-testchill.service
systemctl start testsuite-56-testbloat.service
# Verify systemd-oomd is monitoring the expected units
oomctl | grep "/testsuite-56-workload.slice"
oomctl | grep "1.00%"
oomctl | grep "Default Memory Pressure Duration: 5s"
# systemd-oomd watches for elevated pressure for 5 seconds before acting.
# It can take time to build up pressure so either wait 2 minutes or for the service to fail.
timeout=$(date -ud "2 minutes" +%s)
while [[ $(date -u +%s) -le $timeout ]]; do
if ! systemctl status testsuite-56-testbloat.service; then
break
fi
sleep 5
done
# testbloat should be killed and testchill should be fine
if systemctl status testsuite-56-testbloat.service; then exit 42; fi
if ! systemctl status testsuite-56-testchill.service; then exit 24; fi
# only run this portion of the test if we can set xattrs
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-56-testbloat.service.d/
echo "[Service]" > /etc/systemd/system/testsuite-56-testbloat.service.d/override.conf
echo "ManagedOOMPreference=avoid" >> /etc/systemd/system/testsuite-56-testbloat.service.d/override.conf
systemctl daemon-reload
systemctl start testsuite-56-testchill.service
systemctl start testsuite-56-testmunch.service
systemctl start testsuite-56-testbloat.service
timeout=$(date -ud "2 minutes" +%s)
while [[ $(date -u +%s) -le $timeout ]]; do
if ! systemctl status testsuite-56-testmunch.service; then
break
fi
sleep 5
done
# testmunch should be killed since testbloat had the avoid xattr on it
if ! systemctl status testsuite-56-testbloat.service; then exit 25; fi
if systemctl status testsuite-56-testmunch.service; then exit 43; fi
if ! systemctl status testsuite-56-testchill.service; then exit 24; fi
fi
systemd-analyze log-level info
echo OK > /testok
exit 0

View File

@ -1,7 +0,0 @@
[Unit]
Description=TEST-57-RUNTIME-BIND-PATHS
[Service]
ExecStartPre=rm -f /failed /testok
ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
Type=oneshot

View File

@ -1,43 +0,0 @@
#!/usr/bin/env bash
set -ex
echo "MARKER_FIXED" > /run/testservice-57-fixed
mkdir -p /run/inaccessible
systemctl start testsuite-57-namespaced.service
# Ensure that inaccessible paths aren't bypassed by the runtime setup
set +e
systemctl bind --mkdir testsuite-57-namespaced.service /run/testservice-57-fixed /run/inaccessible/testfile_fixed && exit 1
set -e
echo "MARKER_RUNTIME" > /run/testservice-57-runtime
systemctl bind --mkdir testsuite-57-namespaced.service /run/testservice-57-runtime /tmp/testfile_runtime
while systemctl show -P SubState testsuite-57-namespaced.service | grep -q running
do
sleep 0.1
done
systemctl is-active testsuite-57-namespaced.service
# Now test that systemctl bind fails when attempted on a non-namespaced unit
systemctl start testsuite-57-non-namespaced.service
set +e
systemctl bind --mkdir testsuite-57-non-namespaced.service /run/testservice-57-runtime /tmp/testfile_runtime && exit 1
set -e
while systemctl show -P SubState testsuite-57-non-namespaced.service | grep -q running
do
sleep 0.1
done
set +e
systemctl is-active testsuite-57-non-namespaced.service && exit 1
set -e
echo OK > /testok
exit 0

View File

@ -1,7 +0,0 @@
[Unit]
Description=TEST-58-PORTABLE
[Service]
ExecStartPre=rm -f /failed /testok
ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
Type=oneshot

View File

@ -1,68 +0,0 @@
#!/usr/bin/env bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
set -ex
set -o pipefail
export SYSTEMD_LOG_LEVEL=debug
portablectl attach --now --runtime /usr/share/minimal_0.raw app0
systemctl is-active app0.service
systemctl is-active app0-foo.service
set +o pipefail
set +e
systemctl is-active app0-bar.service && exit 1
set -e
set -o pipefail
portablectl reattach --now --runtime /usr/share/minimal_1.raw app0
systemctl is-active app0.service
systemctl is-active app0-bar.service
set +o pipefail
set +e
systemctl is-active app0-foo.service && exit 1
set -e
set -o pipefail
portablectl list | grep -q -F "minimal_1"
portablectl detach --now --runtime /usr/share/minimal_1.raw app0
portablectl list | grep -q -F "No images."
# portablectl also works with directory paths rather than images
unsquashfs -dest /tmp/minimal_0 /usr/share/minimal_0.raw
unsquashfs -dest /tmp/minimal_1 /usr/share/minimal_1.raw
portablectl attach --copy=symlink --now --runtime /tmp/minimal_0 app0
systemctl is-active app0.service
systemctl is-active app0-foo.service
set +o pipefail
set +e
systemctl is-active app0-bar.service && exit 1
set -e
set -o pipefail
portablectl reattach --now --enable --runtime /tmp/minimal_1 app0
systemctl is-active app0.service
systemctl is-active app0-bar.service
set +o pipefail
set +e
systemctl is-active app0-foo.service && exit 1
set -e
set -o pipefail
portablectl list | grep -q -F "minimal_1"
portablectl detach --now --enable --runtime /tmp/minimal_1 app0
portablectl list | grep -q -F "No images."
echo OK > /testok
exit 0