Skip to content

Commit ecd3028

Browse files
committed
feat: check that org.freedesktop.resolve1 is available
and short-circuit with an error message about requiring systemd >= 229 if it is unavailable.
1 parent c94508e commit ecd3028

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

run-tests

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ export PATH="${toplevel}${PATH:+:${PATH}}"
4444
unset toplevel
4545

4646
function busctl {
47+
# Short-circuit if we got "busctl status <...>". If TEST_BUSCTL_STATUS_RC is
48+
# unset or empty, assume this is the call from the "main" function in
49+
# update-systemd-resolved, rather than an automated test checking the
50+
# behaviour of "busctl status <...>".
51+
case "${1:-}" in
52+
status)
53+
if [[ -n "${TEST_BUSCTL_STATUS_RC:-}" ]]; then
54+
busctl_called=1
55+
_log "busctl status: returning ${TEST_BUSCTL_STATUS_RC}"
56+
return "$TEST_BUSCTL_STATUS_RC"
57+
else
58+
return 0
59+
fi
60+
;;
61+
esac
62+
4763
shift 4
4864
_log "busctl called with: ${@}"
4965
# Set that busctl has been called
@@ -216,6 +232,7 @@ evaltest() {
216232
TEST_BUSCTL_DNS=""
217233
TEST_BUSCTL_DOMAINS=""
218234
TEST_BUSCTL_DNSSEC=""
235+
TEST_BUSCTL_STATUS_RC=""
219236
# Keep this random, as we will never know the ifindex up-front
220237
ip_ifindex=$((RANDOM%=64))
221238
# Clear foreign_option_*

tests/23_resolve1_dbus_presence.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
script_type="up"
2+
dev="tun23"
3+
4+
TEST_TITLE='Error if "busctl status org.freedesktop.resolve1" fails'
5+
TEST_BUSCTL_CALLED=1
6+
7+
# Mocked-up busctl function will return exit code 1 upon "busctl status <...>"
8+
TEST_BUSCTL_STATUS_RC=1
9+
EXPECT_FAILURE=1

update-systemd-resolved

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ usage() {
4444
err "${1:?${1}. }. Usage: ${SCRIPT_NAME} up|down|print-polkit-rules [<options>]."
4545
}
4646

47+
busctl_status() {
48+
busctl status "$DBUS_DEST"
49+
}
50+
4751
busctl_call() {
4852
# Preserve busctl's exit status
4953
busctl call "$DBUS_DEST" "$DBUS_NODE" "${DBUS_DEST}.Manager" "$@" || {
@@ -252,6 +256,15 @@ with_openvpn_script_handling() {
252256
return 1
253257
fi
254258

259+
busctl_status &>/dev/null || {
260+
local -i status="$?"
261+
err <<ERR
262+
systemd-resolved DBus interface (${DBUS_DEST}) is not available.
263+
$SCRIPT_NAME requires systemd version 229 or above.
264+
ERR
265+
return "$status"
266+
}
267+
255268
if ! "$func" "$link" "$if_index" "$@"; then
256269
err 'Unable to configure systemd-resolved.'
257270
print_polkit_rules_command_for_current_user | err

0 commit comments

Comments
 (0)