diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.tools | 9 | ||||
-rw-r--r-- | acinclude.m4 | 6 | ||||
-rwxr-xr-x | bootstrap-configure | 1 | ||||
-rw-r--r-- | tracer/main.c | 138 |
5 files changed, 155 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index ebc648339..30bff3b75 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ sbc/sbcenc sbc/sbcinfo sbc/sbctester +tracer/hcitrace tools/avctrl tools/avinfo tools/bccmd diff --git a/Makefile.tools b/Makefile.tools index f30dde4c2..2735d681a 100644 --- a/Makefile.tools +++ b/Makefile.tools @@ -58,6 +58,15 @@ CLEANFILES += tools/lexer.c tools/parser.c tools/parser.h EXTRA_DIST += tools/rfcomm.conf +if TRACER +sbin_PROGRAMS += tracer/hcitrace + +tracer_hcitrace_SOURCES = tracer/main.c \ + src/logging.h src/logging.c +tracer_hcitrace_LDADD = lib/libbluetooth.la \ + @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ +tracer_hcitrace_DEPENDENCIES = lib/libbluetooth.la +endif if BCCMD sbin_PROGRAMS += tools/bccmd diff --git a/acinclude.m4 b/acinclude.m4 index e7d1c32d2..7ce258812 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -177,6 +177,7 @@ AC_DEFUN([AC_ARG_BLUEZ], [ serial_enable=yes network_enable=yes service_enable=yes + tracer_enable=no tools_enable=yes hidd_enable=no pand_enable=no @@ -243,6 +244,10 @@ AC_DEFUN([AC_ARG_BLUEZ], [ netlink_enable=${enableval} ]) + AC_ARG_ENABLE(tracer, AC_HELP_STRING([--enable-tracer], [install Tracing daemon]), [ + tracer_enable=${enableval} + ]) + AC_ARG_ENABLE(tools, AC_HELP_STRING([--enable-tools], [install Bluetooth utilities]), [ tools_enable=${enableval} ]) @@ -338,6 +343,7 @@ AC_DEFUN([AC_ARG_BLUEZ], [ AM_CONDITIONAL(NETWORKPLUGIN, test "${network_enable}" = "yes") AM_CONDITIONAL(SERVICEPLUGIN, test "${service_enable}" = "yes") AM_CONDITIONAL(ECHOPLUGIN, test "no" = "yes") + AM_CONDITIONAL(TRACER, test "${tracer_enable}" = "yes") AM_CONDITIONAL(HIDD, test "${hidd_enable}" = "yes") AM_CONDITIONAL(PAND, test "${pand_enable}" = "yes") AM_CONDITIONAL(DUND, test "${dund_enable}" = "yes") diff --git a/bootstrap-configure b/bootstrap-configure index 5414518bb..1a57f9eb2 100755 --- a/bootstrap-configure +++ b/bootstrap-configure @@ -17,6 +17,7 @@ fi --localstatedir=/var \ --libexecdir=/lib \ --enable-netlink \ + --enable-tracer \ --enable-tools \ --enable-bccmd \ --enable-dfutool \ diff --git a/tracer/main.c b/tracer/main.c new file mode 100644 index 000000000..db9b53bf7 --- /dev/null +++ b/tracer/main.c @@ -0,0 +1,138 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2009 Marcel Holtmann <marcel@holtmann.org> + * + * + * 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 <stdio.h> +#include <errno.h> +#include <unistd.h> +#include <stdlib.h> +#include <string.h> +#include <signal.h> +#include <sys/stat.h> + +#include <glib.h> + +#include "logging.h" + +#ifdef HAVE_CAPNG +#include <cap-ng.h> +#endif + +static GMainLoop *event_loop; + +static void sig_term(int sig) +{ + g_main_loop_quit(event_loop); +} + +static void sig_debug(int sig) +{ + toggle_debug(); +} + +static gboolean option_detach = TRUE; +static gboolean option_debug = FALSE; + +static GOptionEntry options[] = { + { "nodaemon", 'n', G_OPTION_FLAG_REVERSE, + G_OPTION_ARG_NONE, &option_detach, + "Don't run as daemon in background" }, + { "debug", 'd', 0, G_OPTION_ARG_NONE, &option_debug, + "Enable debug information output" }, + { NULL }, +}; + +int main(int argc, char *argv[]) +{ + GOptionContext *context; + GError *err = NULL; + struct sigaction sa; + +#ifdef HAVE_CAPNG + /* Drop capabilities */ + capng_clear(CAPNG_SELECT_BOTH); + capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE | CAPNG_PERMITTED, + CAP_NET_BIND_SERVICE, CAP_NET_ADMIN, + CAP_NET_RAW, CAP_IPC_LOCK, -1); + capng_apply(CAPNG_SELECT_BOTH); +#endif + + 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(1); + } + + g_option_context_free(context); + + if (option_detach == TRUE) { + if (daemon(0, 0)) { + perror("Can't start daemon"); + exit(1); + } + } + + umask(0077); + + start_logging("hcitrace", "HCI trace daemon %s", VERSION); + + 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_debug; + sigaction(SIGUSR2, &sa, NULL); + + sa.sa_handler = SIG_IGN; + sigaction(SIGPIPE, &sa, NULL); + + if (option_debug == TRUE) { + info("Enabling debug information"); + enable_debug(); + } + + event_loop = g_main_loop_new(NULL, FALSE); + + debug("Entering main loop"); + + g_main_loop_run(event_loop); + + g_main_loop_unref(event_loop); + + info("Exit"); + + stop_logging(); + + return 0; +} |