Skip to content

Commit

Permalink
Improve catching of D-Bus errors
Browse files Browse the repository at this point in the history
Catch all errors from systemd as well as errors indicating that
systemd-resolved is not running.
  • Loading branch information
DemiMarie committed Apr 18, 2023
1 parent 911ae30 commit 8320a24
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions network/qubes-setup-dnat-to-ns
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ def get_dns_resolved():
try:
resolve1 = bus.get_object('org.freedesktop.resolve1',
'/org/freedesktop/resolve1')
resolve1_proxy = dbus.Interface(resolve1,
dbus_interface='org.freedesktop.resolve1')
dns = resolve1.Get('org.freedesktop.resolve1.Manager',
'DNS',
dbus_interface='org.freedesktop.DBus.Properties')
except dbus.exceptions.DBusException as s:
if s.get_dbus_name() in (
error = s.get_dbus_name()
if error in (
'org.freedesktop.DBus.Error.ServiceUnknown',
'org.freedesktop.DBus.Error.NameHasNoOwner',
'org.freedesktop.DBus.Error.NoSuchUnit',
):
) or error.startswith('org.freedesktop.systemd1.'):
return get_dns_resolv_conf()
raise
resolve1_proxy = dbus.Interface(resolve1,
dbus_interface='org.freedesktop.resolve1')
dns = resolve1.Get('org.freedesktop.resolve1.Manager',
'DNS',
dbus_interface='org.freedesktop.DBus.Properties')
# Use global entries first
dns.sort(key=lambda x: x[0] != 0)
# Only keep IPv4 entries. systemd-resolved is trusted to return valid
Expand Down

0 comments on commit 8320a24

Please sign in to comment.