summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-01-13 20:49:32 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-01-13 20:49:32 +0000
commit7ebe01c309433eb7ef6356b810e9b9b543028711 (patch)
tree22b619b2573dfd8f9d150f527ea8c5d2cc2590dd /daemon
parent55295dbb667c2d0701b1285217e7f1242ca6ae83 (diff)
Update basic daemon groundwork
Diffstat (limited to 'daemon')
-rw-r--r--daemon/main.c62
1 files changed, 50 insertions, 12 deletions
diff --git a/daemon/main.c b/daemon/main.c
index ef8ae67a..d7afaedc 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -2,7 +2,7 @@
*
* BlueZ - Bluetooth protocol stack for Linux
*
- * Copyright (C) 2004-2006 Marcel Holtmann <marcel@holtmann.org>
+ * Copyright (C) 2004-2007 Marcel Holtmann <marcel@holtmann.org>
*
*
* This program is free software; you can redistribute it and/or modify
@@ -36,45 +36,65 @@
#include <dbus/dbus.h>
#include "glib-ectomy.h"
+#include "dbus.h"
+#include "notify.h"
#include "logging.h"
#include "hcid.h"
#include "sdpd.h"
-static GMainLoop *event_loop;
+static GMainLoop *main_loop = NULL;
+
+static DBusConnection *system_bus = NULL;
static void sig_term(int sig)
{
- g_main_quit(event_loop);
+ g_main_loop_quit(main_loop);
}
static void sig_hup(int sig)
{
}
+static void sig_debug(int sig)
+{
+ toggle_debug();
+}
+
static void usage(void)
{
printf("bluetoothd - Bluetooth daemon ver %s\n\n", VERSION);
- printf("Usage:\n\tbluetoothd [-n]\n");
+
+ printf("Usage:\n\tbluetoothd [options]\n\n");
+
+ printf("Options:\n"
+ "\t--help Display help\n"
+ "\t--debug Enable debug information\n"
+ "\t--nodaemon Run daemon in foreground\n");
}
static struct option main_options[] = {
- { "help", 0, 0, 'h' },
{ "nodaemon", 0, 0, 'n' },
+ { "debug", 0, 0, 'd' },
+ { "help", 0, 0, 'h' },
{ 0, 0, 0, 0}
};
int main(int argc, char *argv[])
{
struct sigaction sa;
- int opt, daemonize = 1;
+ int opt, debug = 0, daemonize = 1;
- while ((opt = getopt_long(argc, argv, "nh", main_options, NULL)) != -1) {
+ while ((opt = getopt_long(argc, argv, "ndh", main_options, NULL)) != -1) {
switch (opt) {
case 'n':
daemonize = 0;
break;
+ case 'd':
+ debug = 1;
+ break;
+
case 'h':
usage();
exit(0);
@@ -92,7 +112,7 @@ int main(int argc, char *argv[])
umask(0077);
- start_logging("bluetoothd", "Bluetooth daemon");
+ start_logging("bluetoothd", "Bluetooth daemon ver %s", VERSION);
memset(&sa, 0, sizeof(sa));
sa.sa_flags = SA_NOCLDSTOP;
@@ -102,17 +122,35 @@ int main(int argc, char *argv[])
sa.sa_handler = sig_hup;
sigaction(SIGHUP, &sa, NULL);
+ sa.sa_handler = sig_debug;
+ sigaction(SIGUSR2, &sa, NULL);
+
sa.sa_handler = SIG_IGN;
sigaction(SIGCHLD, &sa, NULL);
sigaction(SIGPIPE, &sa, NULL);
- enable_debug();
+ if (debug) {
+ info("Enabling debug information");
+ enable_debug();
+ }
+
+ main_loop = g_main_loop_new(NULL, FALSE);
+
+ notify_init();
+
+ system_bus = init_dbus("org.bluez", NULL, NULL);
+ if (!system_bus) {
+ g_main_loop_unref(main_loop);
+ exit(1);
+ }
+
+ g_main_loop_run(main_loop);
- event_loop = g_main_loop_new(NULL, FALSE);
+ dbus_connection_unref(system_bus);
- g_main_run(event_loop);
+ notify_close();
- g_main_loop_unref(event_loop);
+ g_main_loop_unref(main_loop);
info("Exit");