mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 18:28:25 +00:00
Re-order UBus initialisation to avoid logging before logs set up.
This commit is contained in:
@@ -442,8 +442,10 @@ int main (int argc, char **argv)
|
|||||||
if (option_bool(OPT_UBUS))
|
if (option_bool(OPT_UBUS))
|
||||||
#ifdef HAVE_UBUS
|
#ifdef HAVE_UBUS
|
||||||
{
|
{
|
||||||
|
char *err;
|
||||||
daemon->ubus = NULL;
|
daemon->ubus = NULL;
|
||||||
ubus_init();
|
if ((err = ubus_init()))
|
||||||
|
die(_("UBus error: %s"), err, EC_MISC);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
die(_("UBus not available: set HAVE_UBUS in src/config.h"), NULL, EC_BADCONF);
|
die(_("UBus not available: set HAVE_UBUS in src/config.h"), NULL, EC_BADCONF);
|
||||||
@@ -1195,20 +1197,20 @@ int main (int argc, char **argv)
|
|||||||
if (daemon->dbus)
|
if (daemon->dbus)
|
||||||
my_syslog(LOG_INFO, _("connected to system DBus"));
|
my_syslog(LOG_INFO, _("connected to system DBus"));
|
||||||
}
|
}
|
||||||
check_dbus_listeners();
|
check_dbus_listeners();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_UBUS
|
#ifdef HAVE_UBUS
|
||||||
if (option_bool(OPT_UBUS))
|
/* if we didn't create a UBus connection, retry now. */
|
||||||
|
if (option_bool(OPT_UBUS) && !daemon->ubus)
|
||||||
{
|
{
|
||||||
/* if we didn't create a UBus connection, retry now. */
|
char *err;
|
||||||
if (!daemon->ubus)
|
if ((err = ubus_init()))
|
||||||
{
|
my_syslog(LOG_WARNING, _("UBus error: %s"), err);
|
||||||
ubus_init();
|
if (daemon->ubus)
|
||||||
}
|
my_syslog(LOG_INFO, _("connected to system UBus"));
|
||||||
|
}
|
||||||
check_ubus_listeners();
|
check_ubus_listeners();
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
check_dns_listeners(now);
|
check_dns_listeners(now);
|
||||||
|
|||||||
@@ -1543,7 +1543,7 @@ void emit_dbus_signal(int action, struct dhcp_lease *lease, char *hostname);
|
|||||||
|
|
||||||
/* ubus.c */
|
/* ubus.c */
|
||||||
#ifdef HAVE_UBUS
|
#ifdef HAVE_UBUS
|
||||||
void ubus_init(void);
|
char *ubus_init(void);
|
||||||
void set_ubus_listeners(void);
|
void set_ubus_listeners(void);
|
||||||
void check_ubus_listeners(void);
|
void check_ubus_listeners(void);
|
||||||
void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface);
|
void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface);
|
||||||
|
|||||||
31
src/ubus.c
31
src/ubus.c
@@ -76,42 +76,27 @@ static void ubus_disconnect_cb(struct ubus_context *ubus)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ubus_init()
|
char *ubus_init()
|
||||||
{
|
{
|
||||||
struct ubus_context *ubus = NULL;
|
struct ubus_context *ubus = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
ubus = ubus_connect(NULL);
|
if (!(ubus = ubus_connect(NULL)))
|
||||||
if (!ubus)
|
return NULL;
|
||||||
{
|
|
||||||
if (!error_logged)
|
|
||||||
{
|
|
||||||
my_syslog(LOG_ERR, _("Cannot initialize UBus: connection failed"));
|
|
||||||
error_logged = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ubus_destroy(ubus);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ubus_object.name = daemon->ubus_name;
|
ubus_object.name = daemon->ubus_name;
|
||||||
ret = ubus_add_object(ubus, &ubus_object);
|
ret = ubus_add_object(ubus, &ubus_object);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
if (!error_logged)
|
|
||||||
{
|
|
||||||
my_syslog(LOG_ERR, _("Cannot add object to UBus: %s"), ubus_strerror(ret));
|
|
||||||
error_logged = 1;
|
|
||||||
}
|
|
||||||
ubus_destroy(ubus);
|
ubus_destroy(ubus);
|
||||||
return;
|
return ubus_strerror(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
ubus->connection_lost = ubus_disconnect_cb;
|
ubus->connection_lost = ubus_disconnect_cb;
|
||||||
daemon->ubus = ubus;
|
daemon->ubus = ubus;
|
||||||
error_logged = 0;
|
error_logged = 0;
|
||||||
|
|
||||||
my_syslog(LOG_INFO, _("Connected to system UBus"));
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_ubus_listeners()
|
void set_ubus_listeners()
|
||||||
|
|||||||
Reference in New Issue
Block a user