diff --git a/src/main.c b/src/main.c
index 4716f53..7ab1349 100644
--- a/src/main.c
+++ b/src/main.c
#include "backtrace.h"
#include "shared/att-types.h"
+#include "shared/mainloop.h"
#include "lib/uuid.h"
#include "hcid.h"
#include "sdpd.h"
#include "dbus-common.h"
#include "agent.h"
#include "profile.h"
-#include "systemd.h"
#define BLUEZ_NAME "org.bluez"
btd_backtrace(0xffff);
}
-static GMainLoop *event_loop;
-
void btd_exit(void)
{
- g_main_loop_quit(event_loop);
+ mainloop_quit();
}
static gboolean quit_eventloop(gpointer user_data)
g_timeout_add_seconds(SHUTDOWN_GRACE_SECONDS,
quit_eventloop, NULL);
- sd_notify(0, "STATUS=Powering down");
+ mainloop_sd_notify("STATUS=Powering down");
adapter_shutdown();
}
static void disconnected_dbus(DBusConnection *conn, void *data)
{
info("Disconnected from D-Bus. Exiting.");
- g_main_loop_quit(event_loop);
+ mainloop_quit();
}
static int connect_dbus(void)
return 0;
}
-static gboolean watchdog_callback(gpointer user_data)
-{
- sd_notify(0, "WATCHDOG=1");
-
- return TRUE;
-}
-
static gboolean parse_debug(const char *key, const char *value,
gpointer user_data, GError **error)
{
uint16_t sdp_mtu = 0;
uint32_t sdp_flags = 0;
int gdbus_flags = 0;
- guint signal, watchdog;
- const char *watchdog_usec;
+ guint signal;
init_defaults();
btd_backtrace_init();
- event_loop = g_main_loop_new(NULL, FALSE);
+ mainloop_init();
signal = setup_signalfd();
G_LOG_FLAG_RECURSION,
log_handler, NULL);
- sd_notify(0, "STATUS=Starting up");
+ mainloop_sd_notify("STATUS=Starting up");
if (option_configfile)
main_conf_file_path = option_configfile;
DBG("Entering main loop");
- sd_notify(0, "STATUS=Running");
- sd_notify(0, "READY=1");
+ mainloop_sd_notify("STATUS=Running");
+ mainloop_sd_notify("READY=1");
- watchdog_usec = getenv("WATCHDOG_USEC");
- if (watchdog_usec) {
- unsigned int seconds;
+ mainloop_run();
- seconds = atoi(watchdog_usec) / (1000 * 1000);
- info("Watchdog timeout is %d seconds", seconds);
-
- watchdog = g_timeout_add_seconds_full(G_PRIORITY_HIGH,
- seconds / 2,
- watchdog_callback,
- NULL, NULL);
- } else
- watchdog = 0;
-
- g_main_loop_run(event_loop);
-
- sd_notify(0, "STATUS=Quitting");
+ mainloop_sd_notify("STATUS=Quitting");
g_source_remove(signal);
if (main_opts.mode != BT_MODE_LE)
stop_sdp_server();
- g_main_loop_unref(event_loop);
-
if (main_conf)
g_key_file_free(main_conf);
info("Exit");
- if (watchdog > 0)
- g_source_remove(watchdog);
-
__btd_log_cleanup();
return 0;