Add $SYSTEMD_INVOKED_AS (#42286)

This commit is contained in:
Yu Watanabe
2026-05-26 02:25:08 +09:00
committed by GitHub
5 changed files with 50 additions and 27 deletions
+12 -16
View File
@@ -248,19 +248,14 @@ manual_testcase_01_resolvectl() {
resolvectl dns hoge.foo 10.0.1.3 10.0.1.4
assert_in '10.0.1.1 10.0.1.2' "$(resolvectl dns hoge)"
assert_in '10.0.1.3 10.0.1.4' "$(resolvectl dns hoge.foo)"
if ! RESOLVCONF=$(command -v resolvconf 2>/dev/null); then
TMPDIR=$(mktemp -d -p /tmp resolvconf-tests.XXXXXX)
RESOLVCONF="$TMPDIR"/resolvconf
ln -s "$(command -v resolvectl 2>/dev/null)" "$RESOLVCONF"
fi
# DNS servers
echo nameserver 10.0.2.1 10.0.2.2 | "$RESOLVCONF" -a hoge
echo nameserver 10.0.2.3 10.0.2.4 | "$RESOLVCONF" -a hoge.foo
echo nameserver 10.0.2.1 10.0.2.2 | SYSTEMD_INVOKED_AS=resolvconf resolvectl -a hoge
echo nameserver 10.0.2.3 10.0.2.4 | SYSTEMD_INVOKED_AS=resolvconf resolvectl -a hoge.foo
assert_in '10.0.2.1 10.0.2.2' "$(resolvectl dns hoge)"
assert_in '10.0.2.3 10.0.2.4' "$(resolvectl dns hoge.foo)"
echo nameserver 10.0.3.1 10.0.3.2 | "$RESOLVCONF" -a hoge.inet.ipsec.192.168.35
echo nameserver 10.0.3.3 10.0.3.4 | "$RESOLVCONF" -a hoge.foo.dhcp
echo nameserver 10.0.3.1 10.0.3.2 | SYSTEMD_INVOKED_AS=resolvconf resolvectl -a hoge.inet.ipsec.192.168.35
echo nameserver 10.0.3.3 10.0.3.4 | SYSTEMD_INVOKED_AS=resolvconf resolvectl -a hoge.foo.dhcp
assert_in '10.0.3.1 10.0.3.2' "$(resolvectl dns hoge)"
assert_in '10.0.3.3 10.0.3.4' "$(resolvectl dns hoge.foo)"
@@ -268,36 +263,37 @@ manual_testcase_01_resolvectl() {
# without domain/search clears existing domain
resolvectl domain hoge test-domain.example.com
assert_in 'test-domain.example.com' "$(resolvectl domain hoge)"
echo nameserver 10.0.2.1 10.0.2.2 | "$RESOLVCONF" -a hoge
echo nameserver 10.0.2.1 10.0.2.2 | SYSTEMD_INVOKED_AS=resolvconf resolvectl -a hoge
assert_not_in 'test-domain.example.com' "$(resolvectl domain hoge)"
# cannot set domain without DNS servers
(! echo domain test-domain.example.com | "$RESOLVCONF" -a hoge)
(! echo domain test-domain.example.com | SYSTEMD_INVOKED_AS=resolvconf resolvectl -a hoge)
# can set domain with DNS server(s)
echo -e "nameserver 10.0.2.1 10.0.2.2\ndomain test-domain1.example.com test-domain2.example.com\nsearch test-search-domain.example.com" | "$RESOLVCONF" -a hoge
echo -e "nameserver 10.0.2.1 10.0.2.2\ndomain test-domain1.example.com test-domain2.example.com\nsearch test-search-domain.example.com" | \
SYSTEMD_INVOKED_AS=resolvconf resolvectl -a hoge
assert_in 'test-domain1.example.com' "$(resolvectl domain hoge)"
assert_in 'test-domain2.example.com' "$(resolvectl domain hoge)"
assert_in 'test-search-domain.example.com' "$(resolvectl domain hoge)"
# Tests for 'resolvconf -x'
echo nameserver 10.0.2.1 | "$RESOLVCONF" -x -a hoge
echo nameserver 10.0.2.1 | SYSTEMD_INVOKED_AS=resolvconf resolvectl -x -a hoge
assert_in '~.' "$(resolvectl domain hoge)"
resolvectl domain hoge "hoge.example.com"
assert_in 'hoge.example.com' "$(resolvectl domain hoge)"
assert_not_in '~.' "$(resolvectl domain hoge)"
echo -e "nameserver 10.0.2.1\ndomain test-domain.example.com" | "$RESOLVCONF" -x -a hoge
echo -e "nameserver 10.0.2.1\ndomain test-domain.example.com" | SYSTEMD_INVOKED_AS=resolvconf resolvectl -x -a hoge
assert_in 'test-domain.example.com' "$(resolvectl domain hoge)"
assert_in '~.' "$(resolvectl domain hoge)"
# Tests for 'resolvconf -p'
resolvectl default-route hoge yes
assert_in 'yes' "$(resolvectl default-route hoge)"
echo nameserver 10.0.3.3 10.0.3.4 | "$RESOLVCONF" -p -a hoge
echo nameserver 10.0.3.3 10.0.3.4 | SYSTEMD_INVOKED_AS=resolvconf resolvectl -p -a hoge
assert_in 'no' "$(resolvectl default-route hoge)"
# Tests for 'resolvconf -d'
resolvectl dns hoge 10.0.3.1 10.0.3.2
resolvectl domain hoge test-domain.example.com
"$RESOLVCONF" -d hoge
SYSTEMD_INVOKED_AS=resolvconf resolvectl -d hoge
assert_not_in '10.0.3.1' "$(resolvectl dns hoge)"
assert_not_in '10.0.3.2' "$(resolvectl dns hoge)"
assert_not_in 'test-domain.example.com' "$(resolvectl domain hoge)"