Skip to content

Commit 301efe8

Browse files
authored
Merge pull request #105 from tomeon/verify-resolve1-presence
Check that org.freedesktop.resolve1 is available
2 parents 9b79cbc + 261c947 commit 301efe8

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
### IMPROVEMENTS
66

7+
- Check that the `org.freedesktop.resolve1` endpoint is available and
8+
short-circuit with an error message if not
9+
([#105](https://github.com/jonathanio/update-systemd-resolved/pull/105)).
710
- Add a `print-polkit-rules` subcommand that generates a polkit rules
811
specification allowing the specified users and/or groups to perform the DBus
912
call necessary for `update-systemd-resolved`'s proper operation

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
@@ -63,6 +63,10 @@ usage() {
6363
err "${1:?${1}. }. Usage: ${SCRIPT_NAME} up|down|print-polkit-rules [<options>]."
6464
}
6565

66+
busctl_status() {
67+
busctl status "$DBUS_DEST"
68+
}
69+
6670
busctl_call() {
6771
# Preserve busctl's exit status
6872
busctl call "$DBUS_DEST" "$DBUS_NODE" "${DBUS_DEST}.Manager" "$@" || {
@@ -272,6 +276,15 @@ with_openvpn_script_handling() {
272276
return 1
273277
fi
274278

279+
busctl_status &>/dev/null || {
280+
local -i status="$?"
281+
err <<ERR
282+
systemd-resolved DBus interface (${DBUS_DEST}) is not available.
283+
$SCRIPT_NAME requires systemd version 229 or above.
284+
ERR
285+
return "$status"
286+
}
287+
275288
if ! "$func" "$link" "$if_index" "$@"; then
276289
err 'Unable to configure systemd-resolved.'
277290
return 1

0 commit comments

Comments
 (0)