commit 247b2ccc5cbb81c5c793b2f4756fd6fb5f1164ab
parent 804ce5944b28d880e0c1269abac446fe594102c2
Author: Marcel Holtmann <marcel@holtmann.org>
Date: Fri, 14 Sep 2018 23:29:46 +0200
wired: Move D-Bus setup into separate source file
Diffstat:
4 files changed, 105 insertions(+), 37 deletions(-)
diff --git a/Makefile.am b/Makefile.am
@@ -197,7 +197,8 @@ if WIRED
libexec_PROGRAMS += wired/ead
wired_ead_SOURCES = wired/main.c wired/ethdev.h wired/ethdev.c \
- wired/network.h wired/network.c $(eap_sources)
+ wired/network.h wired/network.c \
+ wired/dbus.h wired/dbus.c $(eap_sources)
wired_ead_LDADD = ell/libell-internal.la
wired_ead_DEPENDENCIES = ell/libell-internal.la
diff --git a/wired/dbus.c b/wired/dbus.c
@@ -0,0 +1,76 @@
+/*
+ *
+ * Ethernet daemon for Linux
+ *
+ * Copyright (C) 2017-2018 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <ell/ell.h>
+
+#include "wired/dbus.h"
+
+static struct l_dbus *dbus;
+
+static void request_name_callback(struct l_dbus *dbus, bool success,
+ bool queued, void *user_data)
+{
+ if (!success) {
+ l_error("Failed to request D-Bus service Name");
+ l_main_quit();
+ return;
+ }
+
+ if (!l_dbus_object_manager_enable(dbus))
+ l_warn("Unable to register ObjectManager interface");
+}
+
+static void dbus_ready(void *user_data)
+{
+ l_dbus_name_acquire(dbus, "net.connman.ead", false, false, true,
+ request_name_callback, NULL);
+}
+
+static void dbus_disconnected(void *user_data)
+{
+ l_info("D-Bus disconnected, quitting...");
+ l_main_quit();
+}
+
+bool dbus_init(void)
+{
+ dbus = l_dbus_new_default(L_DBUS_SYSTEM_BUS);
+ if (!dbus) {
+ l_error("Failed to initialize D-Bus");
+ return false;
+ }
+
+ l_dbus_set_ready_handler(dbus, dbus_ready, dbus, NULL);
+ l_dbus_set_disconnect_handler(dbus, dbus_disconnected, NULL, NULL);
+
+ return true;
+}
+
+void dbus_exit(void)
+{
+ l_dbus_destroy(dbus);
+ dbus = NULL;
+}
diff --git a/wired/dbus.h b/wired/dbus.h
@@ -0,0 +1,24 @@
+/*
+ *
+ * Ethernet daemon for Linux
+ *
+ * Copyright (C) 2017-2018 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+bool dbus_init(void);
+void dbus_exit(void);
diff --git a/wired/main.c b/wired/main.c
@@ -31,6 +31,7 @@
#include <ell/ell.h>
#include "src/eap.h"
+#include "wired/dbus.h"
#include "wired/ethdev.h"
#include "wired/network.h"
@@ -46,33 +47,6 @@ static void signal_handler(struct l_signal *signal, uint32_t signo,
}
}
-static void request_name_callback(struct l_dbus *dbus, bool success,
- bool queued, void *user_data)
-{
- if (!success) {
- l_error("Failed to request D-Bus service Name");
- l_main_quit();
- return;
- }
-
- if (!l_dbus_object_manager_enable(dbus))
- l_warn("Unable to register ObjectManager interface");
-}
-
-static void dbus_ready(void *user_data)
-{
- struct l_dbus *dbus = user_data;
-
- l_dbus_name_acquire(dbus, "net.connman.ead", false, false, true,
- request_name_callback, NULL);
-}
-
-static void dbus_disconnected(void *user_data)
-{
- l_info("D-Bus disconnected, quitting...");
- l_main_quit();
-}
-
static void usage(void)
{
printf("ead - Authentication daemon\n"
@@ -99,7 +73,6 @@ int main(int argc, char *argv[])
struct l_signal *signal;
sigset_t mask;
int exit_status;
- struct l_dbus *dbus;
const char *interfaces = NULL;
const char *nointerfaces = NULL;
const char *debugopt = NULL;
@@ -160,14 +133,8 @@ int main(int argc, char *argv[])
exit_status = EXIT_FAILURE;
- dbus = l_dbus_new_default(L_DBUS_SYSTEM_BUS);
- if (!dbus) {
- l_error("Failed to initialize D-Bus");
+ if (!dbus_init())
goto done;
- }
-
- l_dbus_set_ready_handler(dbus, dbus_ready, dbus, NULL);
- l_dbus_set_disconnect_handler(dbus, dbus_disconnected, NULL, NULL);
eap_init(0);
network_init();
@@ -181,7 +148,7 @@ int main(int argc, char *argv[])
network_exit();
eap_exit();
- l_dbus_destroy(dbus);
+ dbus_exit();
done:
l_signal_remove(signal);