summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2006-11-17 23:39:20 +0000
committerMarcel Holtmann <marcel@holtmann.org>2006-11-17 23:39:20 +0000
commitb8e61e63c24124da88e21e08668fa95fde346b4c (patch)
treedb217e8a3b7f57492bcbdc35f1b0ff6cdc319ae4 /daemon
parent258fbc778115d19957162078ff2a3504b8551211 (diff)
Create skeleton of new master daemon
Diffstat (limited to 'daemon')
-rw-r--r--daemon/Makefile.am6
-rw-r--r--daemon/main.c83
2 files changed, 86 insertions, 3 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index e880ea79..67758137 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -3,9 +3,9 @@ noinst_PROGRAMS = bluetoothd
bluetoothd_SOURCES = main.c
-bluetoothd_LDADD = @DBUS_LIBS@ @BLUEZ_LIBS@
- $(top_builddir)/hcid/libhciserver.a
- $(top_builddir)/sdpd/libsdpserver.a
+bluetoothd_LDADD = @DBUS_LIBS@ @BLUEZ_LIBS@ \
+ $(top_builddir)/hcid/libhciserver.a \
+ $(top_builddir)/sdpd/libsdpserver.a \
$(top_builddir)/common/libhelper.a
if EXPAT
diff --git a/daemon/main.c b/daemon/main.c
index 6432dd9b..a534cdb0 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -27,13 +27,96 @@
#include <stdio.h>
#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <getopt.h>
+#include <sys/stat.h>
#include <dbus/dbus.h>
+#include "glib-ectomy.h"
+#include "logging.h"
+
#include "hcid.h"
#include "sdpd.h"
+static GMainLoop *event_loop;
+
+static void sig_term(int sig)
+{
+ g_main_quit(event_loop);
+}
+
+static void sig_hup(int sig)
+{
+}
+
+static void usage(void)
+{
+ printf("bluetoothd - Bluetooth daemon ver %s\n\n", VERSION);
+ printf("Usage:\n\tbluetoothd [-n]\n");
+}
+
+static struct option main_options[] = {
+ { "help", 0, 0, 'h' },
+ { "nodaemon", 0, 0, 'n' },
+ { 0, 0, 0, 0}
+};
+
int main(int argc, char *argv[])
{
+ struct sigaction sa;
+ int opt, daemonize = 1;
+
+ while ((opt = getopt_long(argc, argv, "nh", main_options, NULL)) != -1) {
+ switch (opt) {
+ case 'n':
+ daemonize = 0;
+ break;
+
+ case 'h':
+ usage();
+ exit(0);
+
+ default:
+ usage();
+ exit(1);
+ }
+ }
+
+ if (daemonize && daemon(0, 0)) {
+ error("Daemon startup failed: %s (%d)", strerror(errno), errno);
+ exit(1);
+ }
+
+ umask(0077);
+
+ start_logging("bluetoothd", "Bluetooth daemon");
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_flags = SA_NOCLDSTOP;
+ sa.sa_handler = sig_term;
+ sigaction(SIGTERM, &sa, NULL);
+ sigaction(SIGINT, &sa, NULL);
+ sa.sa_handler = sig_hup;
+ sigaction(SIGHUP, &sa, NULL);
+
+ sa.sa_handler = SIG_IGN;
+ sigaction(SIGCHLD, &sa, NULL);
+ sigaction(SIGPIPE, &sa, NULL);
+
+ enable_debug();
+
+ event_loop = g_main_new(FALSE);
+
+ g_main_run(event_loop);
+
+ g_main_unref(event_loop);
+
+ info("Exit");
+
+ stop_logging();
+
return 0;
}