Tidy up interface to dbus and ubus modules.

Consistently treat a non-NULL return from [ud]bus-init() as a fatal error:
either die() if still starting, or log an error and disable
the relevant module if dnsmasq has already started.

Also rationalise calls to set and check listeners depending on
configuration.
This commit is contained in:
Simon Kelley
2021-06-27 20:56:58 +01:00
parent 66b863c989
commit 06df5ad7d0

View File

@@ -437,8 +437,6 @@ int main (int argc, char **argv)
#ifdef HAVE_DBUS
{
char *err;
daemon->dbus = NULL;
daemon->watches = NULL;
if ((err = dbus_init()))
die(_("DBus error: %s"), err, EC_MISC);
}
@@ -450,7 +448,6 @@ int main (int argc, char **argv)
#ifdef HAVE_UBUS
{
char *err;
daemon->ubus = NULL;
if ((err = ubus_init()))
die(_("UBus error: %s"), err, EC_MISC);
}
@@ -1065,6 +1062,7 @@ int main (int argc, char **argv)
set_dns_listeners();
#ifdef HAVE_DBUS
if (option_bool(OPT_DBUS))
set_dbus_listeners();
#endif
@@ -1192,28 +1190,44 @@ int main (int argc, char **argv)
#ifdef HAVE_DBUS
/* if we didn't create a DBus connection, retry now. */
if (option_bool(OPT_DBUS) && !daemon->dbus)
if (option_bool(OPT_DBUS))
{
char *err;
if ((err = dbus_init()))
my_syslog(LOG_WARNING, _("DBus error: %s"), err);
if (!daemon->dbus)
{
char *err = dbus_init();
if (daemon->dbus)
my_syslog(LOG_INFO, _("connected to system DBus"));
else if (err)
{
my_syslog(LOG_ERR, _("DBus error: %s"), err);
reset_option_bool(OPT_DBUS); /* fatal error, stop trying. */
}
}
check_dbus_listeners();
}
#endif
#ifdef HAVE_UBUS
/* if we didn't create a UBus connection, retry now. */
if (option_bool(OPT_UBUS) && !daemon->ubus)
if (option_bool(OPT_UBUS))
{
char *err;
if ((err = ubus_init()))
my_syslog(LOG_WARNING, _("UBus error: %s"), err);
if (!daemon->ubus)
{
char *err = ubus_init();
if (daemon->ubus)
my_syslog(LOG_INFO, _("connected to system UBus"));
else if (err)
{
my_syslog(LOG_ERR, _("UBus error: %s"), err);
reset_option_bool(OPT_UBUS); /* fatal error, stop trying. */
}
}
check_ubus_listeners();
}
#endif
check_dns_listeners(now);