mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-25 17:59:25 +01:00
wired: Move system setup after aquiring bus name
This commit is contained in:
parent
405de7019c
commit
975e3714b8
74
wired/dbus.c
74
wired/dbus.c
@ -28,11 +28,19 @@
|
||||
|
||||
#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,
|
||||
bool queued, void *user_data)
|
||||
{
|
||||
struct dbus_info *info = user_data;
|
||||
|
||||
if (!success) {
|
||||
l_error("Failed to request D-Bus service Name");
|
||||
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))
|
||||
l_warn("Unable to register ObjectManager interface");
|
||||
|
||||
if (info->ready_func)
|
||||
info->ready_func(info->user_data);
|
||||
}
|
||||
|
||||
static void dbus_ready(void *user_data)
|
||||
{
|
||||
l_dbus_name_acquire(dbus, "net.connman.ead", false, false, true,
|
||||
request_name_callback, NULL);
|
||||
struct dbus_info *info = user_data;
|
||||
|
||||
l_dbus_name_acquire(dbus, info->name, false, false, true,
|
||||
request_name_callback, info);
|
||||
}
|
||||
|
||||
static void dbus_disconnected(void *user_data)
|
||||
@ -55,22 +68,59 @@ static void dbus_disconnected(void *user_data)
|
||||
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) {
|
||||
l_error("Failed to initialize D-Bus");
|
||||
return false;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
l_dbus_set_ready_handler(dbus, dbus_ready, dbus, NULL);
|
||||
l_dbus_set_disconnect_handler(dbus, dbus_disconnected, NULL, NULL);
|
||||
info = l_new(struct dbus_info, 1);
|
||||
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);
|
||||
dbus = NULL;
|
||||
|
||||
if (destroy)
|
||||
destroy(info->user_data);
|
||||
|
||||
l_free(info->name);
|
||||
l_free(info);
|
||||
|
||||
return exit_status;
|
||||
}
|
||||
|
14
wired/dbus.h
14
wired/dbus.h
@ -20,5 +20,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
bool dbus_init(void);
|
||||
void dbus_exit(void);
|
||||
enum l_dbus_bus;
|
||||
|
||||
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);
|
||||
|
77
wired/main.c
77
wired/main.c
@ -35,16 +35,29 @@
|
||||
#include "wired/ethdev.h"
|
||||
#include "wired/network.h"
|
||||
|
||||
static void signal_handler(struct l_signal *signal, uint32_t signo,
|
||||
void *user_data)
|
||||
struct main_opts {
|
||||
const char *interfaces;
|
||||
const char *nointerfaces;
|
||||
};
|
||||
|
||||
static void dbus_ready(void *user_data)
|
||||
{
|
||||
switch (signo) {
|
||||
case SIGINT:
|
||||
case SIGTERM:
|
||||
l_info("Terminate");
|
||||
l_main_quit();
|
||||
break;
|
||||
}
|
||||
struct main_opts *opts = user_data;
|
||||
|
||||
l_info("System ready");
|
||||
|
||||
eap_init(0);
|
||||
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)
|
||||
@ -70,11 +83,7 @@ static const struct option main_options[] = {
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct l_signal *signal;
|
||||
sigset_t mask;
|
||||
int exit_status;
|
||||
const char *interfaces = NULL;
|
||||
const char *nointerfaces = NULL;
|
||||
struct main_opts opts;
|
||||
const char *debugopt = NULL;
|
||||
|
||||
for (;;) {
|
||||
@ -86,10 +95,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
switch (opt) {
|
||||
case 'i':
|
||||
interfaces = optarg;
|
||||
opts.interfaces = optarg;
|
||||
break;
|
||||
case 'I':
|
||||
nointerfaces = optarg;
|
||||
opts.nointerfaces = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
if (optarg)
|
||||
@ -117,43 +126,11 @@ int main(int argc, char *argv[])
|
||||
|
||||
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)
|
||||
l_debug_enable(debugopt);
|
||||
|
||||
l_info("Authentication daemon version %s", VERSION);
|
||||
|
||||
exit_status = EXIT_FAILURE;
|
||||
|
||||
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;
|
||||
return dbus_run(L_DBUS_SYSTEM_BUS, "net.connman.ead",
|
||||
dbus_ready, dbus_shutdown, &opts, NULL);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user