3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-29 13:59:24 +01:00

wired: Move system setup after aquiring bus name

This commit is contained in:
Marcel Holtmann 2018-09-15 21:40:32 +02:00
parent 405de7019c
commit 975e3714b8
3 changed files with 101 additions and 64 deletions

View File

@ -28,11 +28,19 @@
#include "wired/dbus.h" #include "wired/dbus.h"
static struct l_dbus *dbus; static struct l_dbus *dbus = NULL;
struct dbus_info {
char *name;
dbus_ready_func_t ready_func;
void *user_data;
};
static void request_name_callback(struct l_dbus *dbus, bool success, static void request_name_callback(struct l_dbus *dbus, bool success,
bool queued, void *user_data) bool queued, void *user_data)
{ {
struct dbus_info *info = user_data;
if (!success) { if (!success) {
l_error("Failed to request D-Bus service Name"); l_error("Failed to request D-Bus service Name");
l_main_quit(); l_main_quit();
@ -41,12 +49,17 @@ static void request_name_callback(struct l_dbus *dbus, bool success,
if (!l_dbus_object_manager_enable(dbus)) if (!l_dbus_object_manager_enable(dbus))
l_warn("Unable to register ObjectManager interface"); l_warn("Unable to register ObjectManager interface");
if (info->ready_func)
info->ready_func(info->user_data);
} }
static void dbus_ready(void *user_data) static void dbus_ready(void *user_data)
{ {
l_dbus_name_acquire(dbus, "net.connman.ead", false, false, true, struct dbus_info *info = user_data;
request_name_callback, NULL);
l_dbus_name_acquire(dbus, info->name, false, false, true,
request_name_callback, info);
} }
static void dbus_disconnected(void *user_data) static void dbus_disconnected(void *user_data)
@ -55,22 +68,59 @@ static void dbus_disconnected(void *user_data)
l_main_quit(); l_main_quit();
} }
bool dbus_init(void) static void dbus_signal_handler(uint32_t signo, void *user_data)
{ {
dbus = l_dbus_new_default(L_DBUS_SYSTEM_BUS); switch (signo) {
case SIGINT:
case SIGTERM:
l_info("Terminate");
l_main_quit();
break;
}
}
int dbus_run(enum l_dbus_bus bus, const char *name,
dbus_ready_func_t ready_func,
dbus_shutdown_func_t shutdown_func,
void *user_data,
dbus_destroy_func_t destroy)
{
struct dbus_info *info;
int exit_status;
if (dbus)
return EXIT_FAILURE;
if (!l_main_init())
return EXIT_FAILURE;
dbus = l_dbus_new_default(bus);
if (!dbus) { if (!dbus) {
l_error("Failed to initialize D-Bus"); l_error("Failed to initialize D-Bus");
return false; return EXIT_FAILURE;
} }
l_dbus_set_ready_handler(dbus, dbus_ready, dbus, NULL); info = l_new(struct dbus_info, 1);
l_dbus_set_disconnect_handler(dbus, dbus_disconnected, NULL, NULL); info->name = l_strdup(name);
info->ready_func = ready_func;
info->user_data = user_data;
return true; l_dbus_set_ready_handler(dbus, dbus_ready, info, NULL);
} l_dbus_set_disconnect_handler(dbus, dbus_disconnected, info, NULL);
exit_status = l_main_run_with_signal(dbus_signal_handler, info);
if (shutdown_func)
shutdown_func(info->user_data);
void dbus_exit(void)
{
l_dbus_destroy(dbus); l_dbus_destroy(dbus);
dbus = NULL; dbus = NULL;
if (destroy)
destroy(info->user_data);
l_free(info->name);
l_free(info);
return exit_status;
} }

View File

@ -20,5 +20,15 @@
* *
*/ */
bool dbus_init(void); enum l_dbus_bus;
void dbus_exit(void);
typedef void (*dbus_ready_func_t) (void *user_data);
typedef void (*dbus_shutdown_func_t) (void *user_data);
typedef void (*dbus_destroy_func_t) (void *user_data);
int dbus_run(enum l_dbus_bus bus, const char *name,
dbus_ready_func_t ready_func,
dbus_shutdown_func_t shutdown_func,
void *user_data,
dbus_destroy_func_t destroy);

View File

@ -35,16 +35,29 @@
#include "wired/ethdev.h" #include "wired/ethdev.h"
#include "wired/network.h" #include "wired/network.h"
static void signal_handler(struct l_signal *signal, uint32_t signo, struct main_opts {
void *user_data) const char *interfaces;
const char *nointerfaces;
};
static void dbus_ready(void *user_data)
{ {
switch (signo) { struct main_opts *opts = user_data;
case SIGINT:
case SIGTERM: l_info("System ready");
l_info("Terminate");
l_main_quit(); eap_init(0);
break; network_init();
ethdev_init(opts->interfaces, opts->nointerfaces);
} }
static void dbus_shutdown(void *user_data)
{
l_info("System shutdown");
ethdev_exit();
network_exit();
eap_exit();
} }
static void usage(void) static void usage(void)
@ -70,11 +83,7 @@ static const struct option main_options[] = {
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct l_signal *signal; struct main_opts opts;
sigset_t mask;
int exit_status;
const char *interfaces = NULL;
const char *nointerfaces = NULL;
const char *debugopt = NULL; const char *debugopt = NULL;
for (;;) { for (;;) {
@ -86,10 +95,10 @@ int main(int argc, char *argv[])
switch (opt) { switch (opt) {
case 'i': case 'i':
interfaces = optarg; opts.interfaces = optarg;
break; break;
case 'I': case 'I':
nointerfaces = optarg; opts.nointerfaces = optarg;
break; break;
case 'd': case 'd':
if (optarg) if (optarg)
@ -117,43 +126,11 @@ int main(int argc, char *argv[])
l_log_set_stderr(); l_log_set_stderr();
if (!l_main_init())
return EXIT_FAILURE;
sigemptyset(&mask);
sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGTERM);
signal = l_signal_create(&mask, signal_handler, NULL, NULL);
if (debugopt) if (debugopt)
l_debug_enable(debugopt); l_debug_enable(debugopt);
l_info("Authentication daemon version %s", VERSION); l_info("Authentication daemon version %s", VERSION);
exit_status = EXIT_FAILURE; return dbus_run(L_DBUS_SYSTEM_BUS, "net.connman.ead",
dbus_ready, dbus_shutdown, &opts, NULL);
if (!dbus_init())
goto done;
eap_init(0);
network_init();
ethdev_init(interfaces, nointerfaces);
exit_status = EXIT_SUCCESS;
l_main_run();
ethdev_exit();
network_exit();
eap_exit();
dbus_exit();
done:
l_signal_remove(signal);
l_main_exit();
return exit_status;
} }