2013-09-24 12:13:16

by Frederic Danis

[permalink] [raw]
Subject: [PATCH v2 1/3] build: Add skeleton for BlueZ Android

---
Makefile.am | 4 +++-
Makefile.android | 4 ++++
android/Android.mk | 5 +++++
bootstrap-configure | 3 ++-
configure.ac | 4 ++++
5 files changed, 18 insertions(+), 2 deletions(-)
create mode 100644 Makefile.android
create mode 100644 android/Android.mk

diff --git a/Makefile.am b/Makefile.am
index 4e4b1c5..51204f4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -179,6 +179,7 @@ test_scripts =

include Makefile.tools
include Makefile.obexd
+include Makefile.android

if HID2HCI
rulesdir = @UDEV_DIR@/rules.d
@@ -293,7 +294,8 @@ pkgconfig_DATA = lib/bluez.pc
endif

DISTCHECK_CONFIGURE_FLAGS = --disable-datafiles --enable-library \
- --disable-systemd --disable-udev
+ --disable-systemd --disable-udev \
+ --enable-android

DISTCLEANFILES = $(pkgconfig_DATA)

diff --git a/Makefile.android b/Makefile.android
new file mode 100644
index 0000000..5e43730
--- /dev/null
+++ b/Makefile.android
@@ -0,0 +1,4 @@
+
+if ANDROID
+EXTRA_DIST += android/Android.mk
+endif
diff --git a/android/Android.mk b/android/Android.mk
new file mode 100644
index 0000000..e810654
--- /dev/null
+++ b/android/Android.mk
@@ -0,0 +1,5 @@
+LOCAL_PATH := $(call my-dir)
+
+# Retrieve BlueZ version from configure.ac file
+BLUEZ_VERSION := $(shell grep AC_INIT $(LOCAL_PATH)/../configure.ac | tr -d ' ' | sed -e 's/.*(.*,\(.*\))/\1/')
+
diff --git a/bootstrap-configure b/bootstrap-configure
index 7a6e7d1..8bde920 100755
--- a/bootstrap-configure
+++ b/bootstrap-configure
@@ -12,4 +12,5 @@ fi
--sysconfdir=/etc \
--localstatedir=/var \
--enable-experimental \
- --disable-datafiles $*
+ --disable-datafiles \
+ --enable-android $*
diff --git a/configure.ac b/configure.ac
index 41c2935..22ab240 100644
--- a/configure.ac
+++ b/configure.ac
@@ -242,4 +242,8 @@ AC_DEFINE_UNQUOTED(CONFIGDIR, "${configdir}",
[Directory for the configuration files])
AC_SUBST(CONFIGDIR, "${configdir}")

+AC_ARG_ENABLE(android, AC_HELP_STRING([--enable-android],
+ [enable BlueZ Android]), [android=${enableval}])
+AM_CONDITIONAL(ANDROID, test "${android}" = "yes")
+
AC_OUTPUT(Makefile src/bluetoothd.8 lib/bluez.pc)
--
1.7.9.5



2013-09-30 19:26:13

by Andrei Emeltchenko

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] android: Android version of log.c

Hi,

"Frederic Danis" <[email protected]>
>
> Hello Marcel,
>
>
> On 27/09/2013 04:01, Marcel Holtmann wrote:
>>>
>>> Add logging system to BlueZ Android daemon.
>>> >Android build will use android/log.c file while autotools build will
use
>>> >src/log.c instead.
>>
>> lets just use stdout for now. Changing this later is pretty trivial and
introducing large build alternates is a bit too complicated at this point.
>
>
> I do not understand how writing code to log to stdout can be more simple
than building and linking existing code.

I agree with Frederic here. Why do we use error, warn, DBG, etc if we print
to stdout?

This actually will significantly slow log parsing since first you pay
attention to error messages. If all messages are printed with the same
priorities then we loose this ability.

Regards,
Andrei

2013-09-30 14:37:00

by Frederic Danis

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] android: Android version of log.c

Hello Marcel,

On 27/09/2013 04:01, Marcel Holtmann wrote:
>> Add logging system to BlueZ Android daemon.
>> >Android build will use android/log.c file while autotools build will use
>> >src/log.c instead.
> lets just use stdout for now. Changing this later is pretty trivial and introducing large build alternates is a bit too complicated at this point.

I do not understand how writing code to log to stdout can be more simple
than building and linking existing code.

Regards

Fred

--
Frederic Danis Open Source Technology Center
[email protected] Intel Corporation

2013-09-30 14:36:55

by Frederic Danis

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] android: Add skeleton of BlueZ Android daemon

Hello Marcel,

On 27/09/2013 04:05, Marcel Holtmann wrote:
>> Define local mapping to glib path, otherwise this has to be inside central
>> >place in the build repository.
>> >
>> >Retrieve Bluetooth version from configure.ac.
>> >---
>> >.gitignore | 2 +
>> >Makefile.android | 5 +++
> I rather keep the changes to a global Makefile separate from the android/ stuff.
>
>> >android/Android.mk | 24 ++++++++++++
>> >android/main.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>> >4 files changed, 141 insertions(+)
>> >create mode 100644 android/main.c
> It is perfectly fine to split this into two patches. Add the *.c file(s) first and in a second patch add the build changes.
>

Ok, so I will send .gitignore, Makefile.android and Android.mk in a
second patch.

Regards

Fred

--
Frederic Danis Open Source Technology Center
[email protected] Intel Corporation

2013-09-27 02:08:59

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] build: Add skeleton for BlueZ Android

Hi Fred,

> Makefile.am | 4 +++-
> Makefile.android | 4 ++++
> android/Android.mk | 5 +++++
> bootstrap-configure | 3 ++-
> configure.ac | 4 ++++
> 5 files changed, 18 insertions(+), 2 deletions(-)
> create mode 100644 Makefile.android
> create mode 100644 android/Android.mk
>
> diff --git a/Makefile.am b/Makefile.am
> index 4e4b1c5..51204f4 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -179,6 +179,7 @@ test_scripts =
>
> include Makefile.tools
> include Makefile.obexd
> +include Makefile.android
>
> if HID2HCI
> rulesdir = @UDEV_DIR@/rules.d
> @@ -293,7 +294,8 @@ pkgconfig_DATA = lib/bluez.pc
> endif
>
> DISTCHECK_CONFIGURE_FLAGS = --disable-datafiles --enable-library \
> - --disable-systemd --disable-udev
> + --disable-systemd --disable-udev \
> + --enable-android
>
> DISTCLEANFILES = $(pkgconfig_DATA)
>
> diff --git a/Makefile.android b/Makefile.android
> new file mode 100644
> index 0000000..5e43730
> --- /dev/null
> +++ b/Makefile.android
> @@ -0,0 +1,4 @@
> +
> +if ANDROID
> +EXTRA_DIST += android/Android.mk
> +endif

as I mentioned in another patch. No need for if around EXTRA_DIST.

> diff --git a/android/Android.mk b/android/Android.mk
> new file mode 100644
> index 0000000..e810654
> --- /dev/null
> +++ b/android/Android.mk
> @@ -0,0 +1,5 @@
> +LOCAL_PATH := $(call my-dir)
> +
> +# Retrieve BlueZ version from configure.ac file
> +BLUEZ_VERSION := $(shell grep AC_INIT $(LOCAL_PATH)/../configure.ac | tr -d ' ' | sed -e 's/.*(.*,\(.*\))/\1/')
> +
> diff --git a/bootstrap-configure b/bootstrap-configure
> index 7a6e7d1..8bde920 100755
> --- a/bootstrap-configure
> +++ b/bootstrap-configure
> @@ -12,4 +12,5 @@ fi
> --sysconfdir=/etc \
> --localstatedir=/var \
> --enable-experimental \
> - --disable-datafiles $*
> + --disable-datafiles \
> + --enable-android $*

Historically --disable-datafiles is always last. And I like to keep it that way. Please add it after --enable-experimental.

> diff --git a/configure.ac b/configure.ac
> index 41c2935..22ab240 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -242,4 +242,8 @@ AC_DEFINE_UNQUOTED(CONFIGDIR, "${configdir}",
> [Directory for the configuration files])
> AC_SUBST(CONFIGDIR, "${configdir}")
>
> +AC_ARG_ENABLE(android, AC_HELP_STRING([--enable-android],
> + [enable BlueZ Android]), [android=${enableval}])

I would call it BlueZ for Android, but that is minor details.

> +AM_CONDITIONAL(ANDROID, test "${android}" = "yes")

However this should be ${enable_android} like with every other configure option we have.

> +
> AC_OUTPUT(Makefile src/bluetoothd.8 lib/bluez.pc)

Regards

Marcel


2013-09-27 02:05:01

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] android: Add skeleton of BlueZ Android daemon

Hi Fred,

> Define local mapping to glib path, otherwise this has to be inside central
> place in the build repository.
>
> Retrieve Bluetooth version from configure.ac.
> ---
> .gitignore | 2 +
> Makefile.android | 5 +++

I rather keep the changes to a global Makefile separate from the android/ stuff.

> android/Android.mk | 24 ++++++++++++
> android/main.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 141 insertions(+)
> create mode 100644 android/main.c

It is perfectly fine to split this into two patches. Add the *.c file(s) first and in a second patch add the build changes.

> diff --git a/.gitignore b/.gitignore
> index 8a25a3e..3707209 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -98,3 +98,5 @@ unit/test-gobex-packet
> unit/test-gobex-transfer
> unit/test-*.log
> unit/test-*.trs
> +
> +android/bluetoothd
> diff --git a/Makefile.android b/Makefile.android
> index 5e43730..e056dce 100644
> --- a/Makefile.android
> +++ b/Makefile.android
> @@ -1,4 +1,9 @@
>
> if ANDROID
> +noinst_PROGRAMS += android/bluetoothd
> +
> +android_bluetoothd_SOURCES = android/main.c
> +android_bluetoothd_LDADD = @GLIB_LIBS@
> +
> EXTRA_DIST += android/Android.mk
> endif

You can not put the EXTRA_DIST under an if ANDROID. Make that part global.

I expect that make distcheck works no matter what is configured. Check the final tarballs if all files are actually included.

Regards

Marcel


2013-09-27 02:01:58

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] android: Android version of log.c

Hi Fred,

> Add logging system to BlueZ Android daemon.
> Android build will use android/log.c file while autotools build will use
> src/log.c instead.

lets just use stdout for now. Changing this later is pretty trivial and introducing large build alternates is a bit too complicated at this point.

Regards

Marcel


2013-09-24 12:57:24

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] build: Add skeleton for BlueZ Android

Hi Frederic,

On Tue, Sep 24, 2013 at 8:13 AM, Frederic Danis
<[email protected]> wrote:
> --- /dev/null
> +++ b/android/Android.mk
> @@ -0,0 +1,5 @@
> +LOCAL_PATH := $(call my-dir)
> +
> +# Retrieve BlueZ version from configure.ac file
> +BLUEZ_VERSION := $(shell grep AC_INIT $(LOCAL_PATH)/../configure.ac | tr -d ' ' | sed -e 's/.*(.*,\(.*\))/\1/')

It also works if you use the C preprocessor to get the version:

BLUEZ_VERSION := $(shell grep ^AC_INIT $(LOCAL_PATH)/../configure.ac |
cpp -P -D'AC_INIT(_,v)=v')


Best Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

2013-09-24 12:13:17

by Frederic Danis

[permalink] [raw]
Subject: [PATCH v2 2/3] android: Add skeleton of BlueZ Android daemon

Define local mapping to glib path, otherwise this has to be inside central
place in the build repository.

Retrieve Bluetooth version from configure.ac.
---
.gitignore | 2 +
Makefile.android | 5 +++
android/Android.mk | 24 ++++++++++++
android/main.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 141 insertions(+)
create mode 100644 android/main.c

diff --git a/.gitignore b/.gitignore
index 8a25a3e..3707209 100644
--- a/.gitignore
+++ b/.gitignore
@@ -98,3 +98,5 @@ unit/test-gobex-packet
unit/test-gobex-transfer
unit/test-*.log
unit/test-*.trs
+
+android/bluetoothd
diff --git a/Makefile.android b/Makefile.android
index 5e43730..e056dce 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -1,4 +1,9 @@

if ANDROID
+noinst_PROGRAMS += android/bluetoothd
+
+android_bluetoothd_SOURCES = android/main.c
+android_bluetoothd_LDADD = @GLIB_LIBS@
+
EXTRA_DIST += android/Android.mk
endif
diff --git a/android/Android.mk b/android/Android.mk
index e810654..06a93b3 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -3,3 +3,27 @@ LOCAL_PATH := $(call my-dir)
# Retrieve BlueZ version from configure.ac file
BLUEZ_VERSION := $(shell grep AC_INIT $(LOCAL_PATH)/../configure.ac | tr -d ' ' | sed -e 's/.*(.*,\(.*\))/\1/')

+# Specify pathmap for glib
+pathmap_INCL += glib:external/bluetooth/glib
+
+#
+# Android BlueZ daemon (bluetoothd)
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ main.c \
+
+LOCAL_C_INCLUDES := \
+ $(call include-path-for, glib) \
+ $(call include-path-for, glib)/glib \
+
+LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"
+
+LOCAL_SHARED_LIBRARIES := \
+ libglib \
+
+LOCAL_MODULE := bluetoothd
+
+include $(BUILD_EXECUTABLE)
diff --git a/android/main.c b/android/main.c
new file mode 100644
index 0000000..1dba2d4
--- /dev/null
+++ b/android/main.c
@@ -0,0 +1,110 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; 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 <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include <glib.h>
+
+#define SHUTDOWN_GRACE_SECONDS 10
+
+static GMainLoop *event_loop;
+
+static gboolean quit_eventloop(gpointer user_data)
+{
+ g_main_loop_quit(event_loop);
+
+ return FALSE;
+}
+
+static void sig_term(int sig)
+{
+ static bool __terminated = false;
+
+ if (!__terminated) {
+ g_timeout_add_seconds(SHUTDOWN_GRACE_SECONDS,
+ quit_eventloop, NULL);
+ }
+
+ __terminated = true;
+}
+
+static gboolean option_detach = TRUE;
+static gboolean option_version = FALSE;
+
+static GOptionEntry options[] = {
+ { "nodetach", 'n', G_OPTION_FLAG_REVERSE,
+ G_OPTION_ARG_NONE, &option_detach,
+ "Run with logging in foreground", NULL },
+ { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
+ "Show version information and exit", NULL },
+ { NULL }
+};
+
+int main(int argc, char *argv[])
+{
+ GOptionContext *context;
+ GError *err = NULL;
+ struct sigaction sa;
+
+ context = g_option_context_new(NULL);
+ g_option_context_add_main_entries(context, options, NULL);
+
+ if (g_option_context_parse(context, &argc, &argv, &err) == FALSE) {
+ if (err != NULL) {
+ g_printerr("%s\n", err->message);
+ g_error_free(err);
+ } else
+ g_printerr("An unknown error occurred\n");
+
+ exit(EXIT_FAILURE);
+ }
+
+ g_option_context_free(context);
+
+ if (option_version == TRUE) {
+ printf("%s\n", VERSION);
+ exit(EXIT_SUCCESS);
+ }
+
+ event_loop = g_main_loop_new(NULL, FALSE);
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = sig_term;
+ sigaction(SIGINT, &sa, NULL);
+ sigaction(SIGTERM, &sa, NULL);
+
+ g_main_loop_run(event_loop);
+
+ g_main_loop_unref(event_loop);
+
+ return EXIT_SUCCESS;
+}
--
1.7.9.5


2013-09-24 12:13:18

by Frederic Danis

[permalink] [raw]
Subject: [PATCH v2 3/3] android: Android version of log.c

Add logging system to BlueZ Android daemon.
Android build will use android/log.c file while autotools build will use
src/log.c instead.
---
Makefile.android | 4 +-
android/Android.mk | 1 +
android/log.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++
android/main.c | 34 +++++++++++
4 files changed, 209 insertions(+), 2 deletions(-)
create mode 100644 android/log.c

diff --git a/Makefile.android b/Makefile.android
index e056dce..1184e5f 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -2,8 +2,8 @@
if ANDROID
noinst_PROGRAMS += android/bluetoothd

-android_bluetoothd_SOURCES = android/main.c
+android_bluetoothd_SOURCES = android/main.c src/log.c
android_bluetoothd_LDADD = @GLIB_LIBS@

-EXTRA_DIST += android/Android.mk
+EXTRA_DIST += android/Android.mk android/log.c
endif
diff --git a/android/Android.mk b/android/Android.mk
index 06a93b3..04413de 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -14,6 +14,7 @@ include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
main.c \
+ log.c \

LOCAL_C_INCLUDES := \
$(call include-path-for, glib) \
diff --git a/android/log.c b/android/log.c
new file mode 100644
index 0000000..908f883
--- /dev/null
+++ b/android/log.c
@@ -0,0 +1,172 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; 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 <fcntl.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <sys/uio.h>
+
+#include <glib.h>
+
+#include "log.h"
+
+#define LOG_DEBUG 3
+#define LOG_INFO 4
+#define LOG_WARN 5
+#define LOG_ERR 6
+
+static const char tag[] = "BlueZ";
+static int system_fd;
+
+static void android_log(int pri, const char *fmt, va_list ap)
+{
+ char *msg;
+ struct iovec vec[3];
+
+ if (system_fd == -1)
+ return;
+
+ msg = g_strdup_vprintf(fmt, ap);
+
+ vec[0].iov_base = (unsigned char *) &pri;
+ vec[0].iov_len = 1;
+ vec[1].iov_base = (void *) tag;
+ vec[1].iov_len = strlen(tag) + 1;
+ vec[2].iov_base = (void *) msg;
+ vec[2].iov_len = strlen(msg) + 1;
+
+ writev(system_fd, vec, 3);
+
+ g_free(msg);
+}
+
+void info(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+
+ android_log(LOG_INFO, format, ap);
+
+ va_end(ap);
+}
+
+void warn(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+
+ android_log(LOG_WARN, format, ap);
+
+ va_end(ap);
+}
+
+void error(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+
+ android_log(LOG_ERR, format, ap);
+
+ va_end(ap);
+}
+
+void btd_debug(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+
+ android_log(LOG_DEBUG, format, ap);
+
+ va_end(ap);
+}
+
+extern struct btd_debug_desc __start___debug[];
+extern struct btd_debug_desc __stop___debug[];
+
+static char **enabled = NULL;
+
+static gboolean is_enabled(struct btd_debug_desc *desc)
+{
+ int i;
+
+ if (enabled == NULL)
+ return 0;
+
+ for (i = 0; enabled[i] != NULL; i++)
+ if (desc->file != NULL && g_pattern_match_simple(enabled[i],
+ desc->file) == TRUE)
+ return 1;
+
+ return 0;
+}
+
+void __btd_enable_debug(struct btd_debug_desc *start,
+ struct btd_debug_desc *stop)
+{
+ struct btd_debug_desc *desc;
+
+ if (start == NULL || stop == NULL)
+ return;
+
+ for (desc = start; desc < stop; desc++) {
+ if (is_enabled(desc))
+ desc->flags |= BTD_DEBUG_FLAG_PRINT;
+ }
+}
+
+void __btd_toggle_debug(void)
+{
+ struct btd_debug_desc *desc;
+
+ for (desc = __start___debug; desc < __stop___debug; desc++)
+ desc->flags |= BTD_DEBUG_FLAG_PRINT;
+}
+
+void __btd_log_init(const char *debug, int detach)
+{
+ if (debug != NULL)
+ enabled = g_strsplit_set(debug, ":, ", 0);
+
+ __btd_enable_debug(__start___debug, __stop___debug);
+
+ system_fd = open("/dev/log/system", O_WRONLY);
+
+ info("Bluetooth daemon %s", VERSION);
+}
+
+void __btd_log_cleanup(void)
+{
+ close(system_fd);
+ system_fd = -1;
+
+ g_strfreev(enabled);
+}
diff --git a/android/main.c b/android/main.c
index 1dba2d4..c0a56b1 100644
--- a/android/main.c
+++ b/android/main.c
@@ -34,6 +34,8 @@

#include <glib.h>

+#include "log.h"
+
#define SHUTDOWN_GRACE_SECONDS 10

static GMainLoop *event_loop;
@@ -57,10 +59,31 @@ static void sig_term(int sig)
__terminated = true;
}

+static char *option_debug = NULL;
static gboolean option_detach = TRUE;
static gboolean option_version = FALSE;

+static void free_options(void)
+{
+ g_free(option_debug);
+ option_debug = NULL;
+}
+
+static gboolean parse_debug(const char *key, const char *value,
+ gpointer user_data, GError **error)
+{
+ if (value)
+ option_debug = g_strdup(value);
+ else
+ option_debug = g_strdup("*");
+
+ return TRUE;
+}
+
static GOptionEntry options[] = {
+ { "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
+ G_OPTION_ARG_CALLBACK, parse_debug,
+ "Specify debug options to enable", "DEBUG" },
{ "nodetach", 'n', G_OPTION_FLAG_REVERSE,
G_OPTION_ARG_NONE, &option_detach,
"Run with logging in foreground", NULL },
@@ -102,9 +125,20 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);

+ __btd_log_init(option_debug, option_detach);
+
+ /* no need to keep parsed option in memory */
+ free_options();
+
+ DBG("Entering main loop");
+
g_main_loop_run(event_loop);

g_main_loop_unref(event_loop);

+ info("Exit");
+
+ __btd_log_cleanup();
+
return EXIT_SUCCESS;
}
--
1.7.9.5