summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am4
-rw-r--r--client/main.c35
-rw-r--r--client/pbap.c2
-rw-r--r--client/session.c2
-rw-r--r--client/transfer.c2
-rw-r--r--plugins/bluetooth.c2
-rw-r--r--plugins/filesystem.c2
-rw-r--r--plugins/ftp.c2
-rw-r--r--plugins/nokia-backup.c2
-rw-r--r--plugins/opp.c2
-rw-r--r--plugins/pbap.c2
-rw-r--r--plugins/phonebook-dummy.c2
-rw-r--r--plugins/phonebook-ebook.c2
-rw-r--r--plugins/phonebook-tracker.c2
-rw-r--r--plugins/syncevolution.c2
-rw-r--r--plugins/usb.c2
-rw-r--r--src/log.c (renamed from src/logging.c)120
-rw-r--r--src/log.h (renamed from src/logging.h)35
-rw-r--r--src/main.c31
-rw-r--r--src/manager.c2
-rw-r--r--src/mimetype.c2
-rw-r--r--src/obex.c2
-rw-r--r--src/plugin.c2
-rw-r--r--src/server.c2
-rw-r--r--src/service.c2
-rw-r--r--src/transport.c2
26 files changed, 164 insertions, 103 deletions
diff --git a/Makefile.am b/Makefile.am
index 88e23bd..da0695e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -64,7 +64,7 @@ libexec_PROGRAMS += src/obexd
src_obexd_SOURCES = $(gdbus_sources) $(builtin_sources) \
src/main.c src/obexd.h src/plugin.h src/plugin.c \
- src/logging.h src/logging.c src/btio.h src/btio.c \
+ src/log.h src/log.c src/btio.h src/btio.c \
src/dbus.h src/manager.c src/obex.h src/obex.c \
src/obex-priv.h \
src/mimetype.h src/mimetype.c \
@@ -106,7 +106,7 @@ libexec_PROGRAMS += client/obex-client
client_obex_client_SOURCES = $(gdbus_sources) $(gwobex_sources) client/main.c \
client/session.h client/session.c \
- src/logging.h src/logging.c \
+ src/log.h src/log.c \
client/pbap.h client/pbap.c \
client/sync.h client/sync.c \
client/transfer.h client/transfer.c
diff --git a/client/main.c b/client/main.c
index 89b6c65..3bde09e 100644
--- a/client/main.c
+++ b/client/main.c
@@ -34,7 +34,7 @@
#include <glib.h>
#include <gdbus.h>
-#include "logging.h"
+#include "log.h"
#include "transfer.h"
#include "session.h"
@@ -544,12 +544,24 @@ static GDBusMethodTable client_methods[] = {
static GMainLoop *event_loop = NULL;
-static gboolean option_debug = FALSE;
+static char *option_debug = NULL;
static gboolean option_stderr = FALSE;
+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', 0, G_OPTION_ARG_NONE, &option_debug,
- "Enable debug information output" },
+ { "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
+ G_OPTION_ARG_CALLBACK, parse_debug,
+ "Enable debug information output", "DEBUG" },
{ "stderr", 's', 0, G_OPTION_ARG_NONE, &option_stderr,
"Write log information to stderr" },
{ NULL },
@@ -567,7 +579,7 @@ int main(int argc, char *argv[])
DBusConnection *conn;
DBusError derr;
GError *gerr = NULL;
- int log_option;
+ int log_option = 0;
context = g_option_context_new(NULL);
g_option_context_add_main_entries(context, options, NULL);
@@ -598,19 +610,14 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- event_loop = g_main_loop_new(NULL, FALSE);
-
- log_option = LOG_NDELAY | LOG_PID;
-
if (option_stderr == TRUE)
log_option |= LOG_PERROR;
- openlog("obex-client", log_option, LOG_DAEMON);
+ event_loop = g_main_loop_new(NULL, FALSE);
- if (option_debug == TRUE) {
- info("Enabling debug information");
- enable_debug();
- }
+ log_init("obex-client", option_debug, log_option);
+
+ DBG("Entering main loop");
memset(&sa, 0, sizeof(sa));
sa.sa_handler = sig_term;
diff --git a/client/pbap.c b/client/pbap.c
index cb3def4..8e4e025 100644
--- a/client/pbap.c
+++ b/client/pbap.c
@@ -30,7 +30,7 @@
#include <glib.h>
#include <gdbus.h>
-#include "logging.h"
+#include "log.h"
#include "transfer.h"
#include "session.h"
#include "pbap.h"
diff --git a/client/session.c b/client/session.c
index 05eb6a6..2db482b 100644
--- a/client/session.c
+++ b/client/session.c
@@ -40,7 +40,7 @@
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>
-#include "logging.h"
+#include "log.h"
#include "pbap.h"
#include "sync.h"
#include "transfer.h"
diff --git a/client/transfer.c b/client/transfer.c
index 6af8c52..dc585dc 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -35,7 +35,7 @@
#include <gdbus.h>
#include <gw-obex.h>
-#include "logging.h"
+#include "log.h"
#include "transfer.h"
#include "session.h"
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 8134e6b..ae4ca8d 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -40,7 +40,7 @@
#include "obex.h"
#include "transport.h"
#include "service.h"
-#include "logging.h"
+#include "log.h"
#include "btio.h"
#define BT_RX_MTU 32767
diff --git a/plugins/filesystem.c b/plugins/filesystem.c
index 2844329..adbf6d6 100644
--- a/plugins/filesystem.c
+++ b/plugins/filesystem.c
@@ -45,7 +45,7 @@
#include <openobex/obex_const.h>
#include "plugin.h"
-#include "logging.h"
+#include "log.h"
#include "obex.h"
#include "mimetype.h"
#include "service.h"
diff --git a/plugins/ftp.c b/plugins/ftp.c
index c2dac96..24553e5 100644
--- a/plugins/ftp.c
+++ b/plugins/ftp.c
@@ -45,7 +45,7 @@
#include <openobex/obex_const.h>
#include "plugin.h"
-#include "logging.h"
+#include "log.h"
#include "obex.h"
#include "dbus.h"
#include "mimetype.h"
diff --git a/plugins/nokia-backup.c b/plugins/nokia-backup.c
index e6504f5..2b590b6 100644
--- a/plugins/nokia-backup.c
+++ b/plugins/nokia-backup.c
@@ -47,7 +47,7 @@
#include <openobex/obex_const.h>
#include "plugin.h"
-#include "logging.h"
+#include "log.h"
#include "obex.h"
#include "mimetype.h"
#include "service.h"
diff --git a/plugins/opp.c b/plugins/opp.c
index 976db1f..cd46464 100644
--- a/plugins/opp.c
+++ b/plugins/opp.c
@@ -37,7 +37,7 @@
#include "plugin.h"
#include "obex.h"
#include "service.h"
-#include "logging.h"
+#include "log.h"
#include "dbus.h"
#define VCARD_TYPE "text/x-vcard"
diff --git a/plugins/pbap.c b/plugins/pbap.c
index 96b6452..32f5ef3 100644
--- a/plugins/pbap.c
+++ b/plugins/pbap.c
@@ -41,7 +41,7 @@
#include <openobex/obex_const.h>
#include "plugin.h"
-#include "logging.h"
+#include "log.h"
#include "obex.h"
#include "service.h"
#include "phonebook.h"
diff --git a/plugins/phonebook-dummy.c b/plugins/phonebook-dummy.c
index 6ad0266..6f3a7d4 100644
--- a/plugins/phonebook-dummy.c
+++ b/plugins/phonebook-dummy.c
@@ -41,7 +41,7 @@
#include <libical/vobject.h>
#include <libical/vcc.h>
-#include "logging.h"
+#include "log.h"
#include "phonebook.h"
typedef void (*vcard_func_t) (const char *file, VObject *vo, void *user_data);
diff --git a/plugins/phonebook-ebook.c b/plugins/phonebook-ebook.c
index 0ca1cba..2d5bec3 100644
--- a/plugins/phonebook-ebook.c
+++ b/plugins/phonebook-ebook.c
@@ -36,7 +36,7 @@
#include <libebook/e-book.h>
-#include "logging.h"
+#include "log.h"
#include "obex.h"
#include "service.h"
#include "phonebook.h"
diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index 243be51..2c73747 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -30,7 +30,7 @@
#include <openobex/obex.h>
#include <openobex/obex_const.h>
-#include "logging.h"
+#include "log.h"
#include "obex.h"
#include "service.h"
#include "mimetype.h"
diff --git a/plugins/syncevolution.c b/plugins/syncevolution.c
index 87deb17..bdc4446 100644
--- a/plugins/syncevolution.c
+++ b/plugins/syncevolution.c
@@ -41,7 +41,7 @@
#include "obex.h"
#include "service.h"
#include "mimetype.h"
-#include "logging.h"
+#include "log.h"
#include "dbus.h"
#include "btio.h"
#include "obexd.h"
diff --git a/plugins/usb.c b/plugins/usb.c
index b3fe035..779532d 100644
--- a/plugins/usb.c
+++ b/plugins/usb.c
@@ -46,7 +46,7 @@
#include "obex.h"
#include "transport.h"
#include "service.h"
-#include "logging.h"
+#include "log.h"
static GIOChannel *usb_io = NULL;
static guint usb_reconnecting = 0;
diff --git a/src/logging.c b/src/log.c
index f42770e..fe045a4 100644
--- a/src/logging.c
+++ b/src/log.c
@@ -31,14 +31,9 @@
#include <openobex/obex.h>
-#include "logging.h"
+#include <glib.h>
-static volatile int debug_enabled = 0;
-
-static inline void vinfo(const char *format, va_list ap)
-{
- vsyslog(LOG_INFO, format, ap);
-}
+#include "log.h"
void info(const char *format, ...)
{
@@ -46,7 +41,7 @@ void info(const char *format, ...)
va_start(ap, format);
- vinfo(format, ap);
+ vsyslog(LOG_INFO, format, ap);
va_end(ap);
}
@@ -66,9 +61,6 @@ void debug(const char *format, ...)
{
va_list ap;
- if (!debug_enabled)
- return;
-
va_start(ap, format);
vsyslog(LOG_DEBUG, format, ap);
@@ -76,39 +68,6 @@ void debug(const char *format, ...)
va_end(ap);
}
-void toggle_debug(void)
-{
- debug_enabled = (debug_enabled + 1) % 2;
-}
-
-void enable_debug(void)
-{
- debug_enabled = 1;
-}
-
-void disable_debug(void)
-{
- debug_enabled = 0;
-}
-
-void start_logging(const char *ident, const char *message, ...)
-{
- va_list ap;
-
- openlog(ident, LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON);
-
- va_start(ap, message);
-
- vinfo(message, ap);
-
- va_end(ap);
-}
-
-void stop_logging(void)
-{
- closelog();
-}
-
static struct {
int evt;
const char *name;
@@ -164,7 +123,7 @@ static struct {
{ OBEX_RSP_CONTINUE, "CONTINUE" },
{ OBEX_RSP_SWITCH_PRO, "SWITCH_PRO" },
{ OBEX_RSP_SUCCESS, "SUCCESS" },
- { OBEX_RSP_CREATED, "CREATED" },
+ { OBEX_RSP_CREATED, "CREATED" },
{ OBEX_RSP_ACCEPTED, "ACCEPTED" },
{ OBEX_RSP_NON_AUTHORITATIVE, "NON_AUTHORITATIVE" },
{ OBEX_RSP_NO_CONTENT, "NO_CONTENT" },
@@ -208,9 +167,6 @@ void obex_debug(int evt, int cmd, int rsp)
const char *evtstr = NULL, *cmdstr = NULL, *rspstr = NULL;
int i;
- if (!debug_enabled)
- return;
-
for (i = 0; obex_event[i].evt != 0xFF; i++) {
if (obex_event[i].evt != evt)
continue;
@@ -232,3 +188,71 @@ void obex_debug(int evt, int cmd, int rsp)
debug("%s(0x%x), %s(0x%x), %s(0x%x)", evtstr, evt, cmdstr, cmd,
rspstr, rsp);
}
+
+extern struct log_debug_desc __start___debug[];
+extern struct log_debug_desc __stop___debug[];
+
+static gchar **enabled = NULL;
+
+int debug_enabled = FALSE;
+
+static gboolean is_enabled(struct log_debug_desc *desc)
+{
+ int i;
+
+ if (enabled == NULL)
+ return 0;
+
+ for (i = 0; enabled[i] != NULL; i++) {
+ if (desc->name != NULL && g_pattern_match_simple(enabled[i],
+ desc->name) == TRUE)
+ return 1;
+ if (desc->file != NULL && g_pattern_match_simple(enabled[i],
+ desc->file) == TRUE)
+ return 1;
+ }
+
+ return 0;
+}
+
+void log_enable_debug()
+{
+ struct log_debug_desc *desc;
+
+ for (desc = __start___debug; desc < __stop___debug; desc++)
+ desc->flags |= LOG_DEBUG_FLAG_PRINT;
+}
+
+void log_init(const char *ident, const char *debug, int log_option)
+{
+ int option = log_option | LOG_NDELAY | LOG_PID;
+ struct log_debug_desc *desc;
+ const char *name = NULL, *file = NULL;
+
+ if (debug != NULL)
+ enabled = g_strsplit_set(debug, ":, ", 0);
+
+ for (desc = __start___debug; desc < __stop___debug; desc++) {
+ if (file != NULL || name != NULL) {
+ if (g_strcmp0(desc->file, file) == 0) {
+ if (desc->name == NULL)
+ desc->name = name;
+ } else
+ file = NULL;
+ }
+
+ if (is_enabled(desc))
+ desc->flags |= LOG_DEBUG_FLAG_PRINT;
+ }
+
+ openlog(ident, option, LOG_DAEMON);
+
+ syslog(LOG_INFO, "%s version %s", ident, VERSION);
+}
+
+void log_cleanup(void)
+{
+ closelog();
+
+ g_strfreev(enabled);
+}
diff --git a/src/logging.h b/src/log.h
index d876d0f..897924d 100644
--- a/src/logging.h
+++ b/src/log.h
@@ -25,11 +25,32 @@ void info(const char *format, ...) __attribute__((format(printf, 1, 2)));
void error(const char *format, ...) __attribute__((format(printf, 1, 2)));
void debug(const char *format, ...) __attribute__((format(printf, 1, 2)));
void obex_debug(int evt, int cmd, int rsp);
-void toggle_debug(void);
-void enable_debug(void);
-void disable_debug(void);
-void start_logging(const char *ident, const char *message, ...);
-void stop_logging(void);
-#define DBG(fmt, arg...) debug("%s: " fmt "\n" , __FUNCTION__ , ## arg)
-//#define DBG(fmt, arg...)
+void log_init(const char *ident, const char *debug, int log_option);
+void log_cleanup(void);
+void log_enable_debug(void);
+
+struct log_debug_desc {
+ const char *name;
+ const char *file;
+#define LOG_DEBUG_FLAG_DEFAULT (0)
+#define LOG_DEBUG_FLAG_PRINT (1 << 0)
+ unsigned int flags;
+} __attribute__((aligned(8)));
+
+/**
+ * DBG:
+ * @fmt: format string
+ * @arg...: list of arguments
+ *
+ * Simple macro around debug() which also include the function
+ * name it is called in.
+ */
+#define DBG(fmt, arg...) do { \
+ static struct log_debug_desc __log_debug_desc \
+ __attribute__((used, section("__debug"), aligned(8))) = { \
+ .file = __FILE__, .flags = LOG_DEBUG_FLAG_DEFAULT, \
+ }; \
+ if (__log_debug_desc.flags & LOG_DEBUG_FLAG_PRINT) \
+ debug("%s:%s() " fmt, __FILE__, __FUNCTION__ , ## arg); \
+} while (0)
diff --git a/src/main.c b/src/main.c
index b60fcd2..d3ca3b1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -45,7 +45,7 @@
#include <openobex/obex.h>
#include <openobex/obex_const.h>
-#include "logging.h"
+#include "log.h"
#include "obexd.h"
#include "obex.h"
#include "obex-priv.h"
@@ -66,11 +66,11 @@ static void sig_term(int sig)
static void sig_debug(int sig)
{
- toggle_debug();
+ log_enable_debug();
}
static gboolean option_detach = TRUE;
-static gboolean option_debug = FALSE;
+static char *option_debug = NULL;
static char *option_root = NULL;
static char *option_root_setup = NULL;
@@ -84,12 +84,24 @@ static gboolean option_pcsuite = FALSE;
static gboolean option_symlinks = FALSE;
static gboolean option_syncevolution = FALSE;
+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[] = {
{ "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" },
+ { "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
+ G_OPTION_ARG_CALLBACK, parse_debug,
+ "Enable debug information output", "DEBUG" },
{ "root", 'r', 0, G_OPTION_ARG_STRING, &option_root,
"Specify root folder location", "PATH" },
{ "root-setup", 'S', 0, G_OPTION_ARG_STRING, &option_root_setup,
@@ -167,7 +179,7 @@ int main(int argc, char *argv[])
GOptionContext *context;
GError *err = NULL;
struct sigaction sa;
- int log_option = LOG_NDELAY | LOG_PID;
+ int log_option = 0;
#ifdef NEED_THREADS
if (g_thread_supported() == FALSE)
@@ -204,12 +216,9 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- openlog("obexd", log_option, LOG_DAEMON);
+ log_init("obexd", option_debug, log_option);
- if (option_debug == TRUE) {
- info("Enabling debug information");
- enable_debug();
- }
+ DBG("Entering main loop");
main_loop = g_main_loop_new(NULL, FALSE);
diff --git a/src/manager.c b/src/manager.c
index c5a3fc0..d0fe936 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -42,7 +42,7 @@
#include "obex-priv.h"
#include "server.h"
#include "dbus.h"
-#include "logging.h"
+#include "log.h"
#include "btio.h"
#include "service.h"
diff --git a/src/mimetype.c b/src/mimetype.c
index da281fc..95a667b 100644
--- a/src/mimetype.c
+++ b/src/mimetype.c
@@ -32,7 +32,7 @@
#include <openobex/obex.h>
#include <openobex/obex_const.h>
-#include "logging.h"
+#include "log.h"
#include "obex.h"
#include "mimetype.h"
diff --git a/src/obex.c b/src/obex.c
index 4f1b766..200bc17 100644
--- a/src/obex.c
+++ b/src/obex.c
@@ -42,7 +42,7 @@
#include <openobex/obex.h>
-#include "logging.h"
+#include "log.h"
#include "obex.h"
#include "obex-priv.h"
#include "server.h"
diff --git a/src/plugin.c b/src/plugin.c
index 2e12ac3..a181858 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -34,7 +34,7 @@
#include "obexd.h"
#include "plugin.h"
-#include "logging.h"
+#include "log.h"
/*
* Plugins that are using libraries with threads and their own mainloop
diff --git a/src/server.c b/src/server.c
index 1f96644..f52be54 100644
--- a/src/server.c
+++ b/src/server.c
@@ -38,7 +38,7 @@
#include <openobex/obex.h>
-#include "logging.h"
+#include "log.h"
#include "obex.h"
#include "obex-priv.h"
#include "server.h"
diff --git a/src/service.c b/src/service.c
index 5afd29b..395b8f9 100644
--- a/src/service.c
+++ b/src/service.c
@@ -33,7 +33,7 @@
#include "obex.h"
#include "service.h"
-#include "logging.h"
+#include "log.h"
static GSList *drivers = NULL;
diff --git a/src/transport.c b/src/transport.c
index 6b3c9d3..80096b3 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -34,7 +34,7 @@
#include "obex.h"
#include "server.h"
#include "transport.h"
-#include "logging.h"
+#include "log.h"
static GSList *drivers = NULL;