3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 04:32:37 +01:00

main: Don't init nl80211 until dbus name is owned

This commit is contained in:
Denis Kenzior 2018-09-11 20:06:00 -05:00
parent 95896c10ff
commit b181604c18
4 changed files with 71 additions and 74 deletions

View File

@ -39,13 +39,6 @@
struct l_dbus *g_dbus = 0;
static void do_debug(const char *str, void *user_data)
{
const char *prefix = user_data;
l_info("%s%s", prefix, str);
}
const char *dbus_iftype_to_string(uint32_t iftype)
{
switch (iftype) {
@ -204,58 +197,21 @@ void dbus_pending_reply(struct l_dbus_message **msg,
*msg = NULL;
}
static void request_name_callback(struct l_dbus *dbus, bool success,
bool queued, void *user_data)
{
if (!success)
l_error("Name request failed");
}
static void ready_callback(void *user_data)
{
l_dbus_name_acquire(g_dbus, "net.connman.iwd", false, false, true,
request_name_callback, NULL);
if (!l_dbus_object_manager_enable(g_dbus))
l_info("Unable to register the ObjectManager");
agent_init(g_dbus);
}
static void disconnect_callback(void *user_data)
{
l_info("D-Bus disconnected, quitting...");
iwd_shutdown();
}
struct l_dbus *dbus_get_bus(void)
{
return g_dbus;
}
bool dbus_init(bool enable_debug)
bool dbus_init(struct l_dbus *dbus)
{
g_dbus = l_dbus_new_default(L_DBUS_SYSTEM_BUS);
if (!g_dbus)
return false;
if (enable_debug)
l_dbus_set_debug(g_dbus, do_debug, "[DBUS] ", NULL);
l_dbus_set_ready_handler(g_dbus, ready_callback, g_dbus, NULL);
l_dbus_set_disconnect_handler(g_dbus, disconnect_callback, NULL, NULL);
return true;
g_dbus = dbus;
return agent_init(dbus);
}
bool dbus_exit(void)
void dbus_exit(void)
{
agent_exit(g_dbus);
l_dbus_destroy(g_dbus);
g_dbus = NULL;
return true;
}
void dbus_shutdown(void)

View File

@ -69,6 +69,6 @@ struct l_dbus_message *dbus_error_not_hidden(struct l_dbus_message *msg);
struct l_dbus_message *dbus_error_from_errno(int err,
struct l_dbus_message *msg);
bool dbus_init(bool enable_debug);
bool dbus_exit(void);
bool dbus_init(struct l_dbus *dbus);
void dbus_exit(void);
void dbus_shutdown(void);

View File

@ -26,8 +26,6 @@ struct l_genl_family;
const struct l_settings *iwd_get_config(void);
void iwd_shutdown(void);
bool netdev_init(const char *whitelist, const char *blacklist);
void netdev_exit(void);
void netdev_set_nl80211(struct l_genl_family *nl80211);

View File

@ -47,6 +47,8 @@
#include "src/backtrace.h"
struct l_genl *genl;
struct l_genl_family *nl80211;
static struct l_settings *iwd_config;
static struct l_timeout *timeout;
static const char *interfaces;
@ -64,13 +66,18 @@ static void main_loop_quit(struct l_timeout *timeout, void *user_data)
l_main_quit();
}
void iwd_shutdown(void)
static void iwd_shutdown(void)
{
if (terminating)
return;
terminating = true;
if (!nl80211) {
l_main_quit();
return;
}
dbus_shutdown();
netdev_shutdown();
@ -163,6 +170,54 @@ static void nl80211_vanished(void *user_data)
wiphy_exit();
}
static void request_name_callback(struct l_dbus *dbus, bool success,
bool queued, void *user_data)
{
if (!success) {
l_error("Name request failed");
goto fail_exit;
}
if (!l_dbus_object_manager_enable(dbus))
l_warn("Unable to register the ObjectManager");
genl = l_genl_new_default();
if (!genl) {
l_error("Failed to open generic netlink socket");
goto fail_exit;
}
if (getenv("IWD_GENL_DEBUG"))
l_genl_set_debug(genl, do_debug, "[GENL] ", NULL);
nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
if (!nl80211) {
l_error("Failed to open nl80211 interface");
goto fail_exit;
}
l_genl_family_set_watches(nl80211, nl80211_appeared, nl80211_vanished,
nl80211, NULL);
return;
fail_exit:
l_main_quit();
}
static void dbus_ready(void *user_data)
{
struct l_dbus *dbus = user_data;
l_dbus_name_acquire(dbus, "net.connman.iwd", false, false, true,
request_name_callback, NULL);
}
static void dbus_disconnected(void *user_data)
{
l_info("D-Bus disconnected, quitting...");
iwd_shutdown();
}
static void print_koption(const void *key, void *value, void *user_data)
{
l_info("\t%s", (const char *) key);
@ -297,8 +352,7 @@ int main(int argc, char *argv[])
struct l_signal *signal;
sigset_t mask;
int exit_status;
struct l_genl *genl;
struct l_genl_family *nl80211;
struct l_dbus *dbus;
char *config_path;
uint32_t eap_mtu;
@ -400,28 +454,18 @@ int main(int argc, char *argv[])
exit_status = EXIT_FAILURE;
if (!dbus_init(enable_dbus_debug)) {
dbus = l_dbus_new_default(L_DBUS_SYSTEM_BUS);
if (!dbus) {
l_error("Failed to initialize D-Bus");
goto fail_dbus;
}
genl = l_genl_new_default();
if (!genl) {
l_error("Failed to open generic netlink socket");
goto fail_genl;
}
if (enable_dbus_debug)
l_dbus_set_debug(dbus, do_debug, "[DBUS] ", NULL);
if (getenv("IWD_GENL_DEBUG"))
l_genl_set_debug(genl, do_debug, "[GENL] ", NULL);
nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
if (!nl80211) {
l_error("Failed to open nl80211 interface");
goto fail_nl80211;
}
l_genl_family_set_watches(nl80211, nl80211_appeared, nl80211_vanished,
nl80211, NULL);
l_dbus_set_ready_handler(dbus, dbus_ready, dbus, NULL);
l_dbus_set_disconnect_handler(dbus, dbus_disconnected, NULL, NULL);
dbus_init(dbus);
eap_init(eap_mtu);
eapol_init();
@ -460,10 +504,9 @@ fail_netdev:
eap_exit();
l_genl_family_unref(nl80211);
fail_nl80211:
l_genl_unref(genl);
fail_genl:
dbus_exit();
l_dbus_destroy(dbus);
fail_dbus:
l_settings_free(iwd_config);