Skip to content

Commit

Permalink
Merge branch 'debuglog' into 'master'
Browse files Browse the repository at this point in the history
Control ofono logging over D-Bus

The previous solution only allowed switching logs on/off, this one
allows to pipe the log to another process.

See merge request !67
  • Loading branch information
Slava Monich committed May 30, 2016
2 parents a88d7af + 290c3d2 commit 5e23459
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 216 deletions.
2 changes: 1 addition & 1 deletion ofono/Makefile.am
Expand Up @@ -618,7 +618,7 @@ builtin_cflags += @WSPCODEC_CFLAGS@
builtin_libadd += @WSPCODEC_LIBS@
endif

if LOGCONTROL
if DEBUGLOG
builtin_modules += debuglog
builtin_sources += plugins/debuglog.c
endif
Expand Down
14 changes: 10 additions & 4 deletions ofono/configure.ac
Expand Up @@ -252,10 +252,16 @@ if (test "${enable_pushforwarder}" != "no"); then
AC_SUBST(WSPCODEC_LIBS)
fi

AC_ARG_ENABLE(logcontrol,
AC_HELP_STRING([--enable-logcontrol], [enable log control plugin]),
[enable_logcontrol=${enableval}], [enable_logcontrol="no"])
AM_CONDITIONAL(LOGCONTROL, test "${enable_logcontrol}" != "no")
AC_ARG_ENABLE(debuglog,
AC_HELP_STRING([--enable-debuglog], [enable log control plugin]),
[enable_debuglog=${enableval}], [enable_debuglog="no"])
AM_CONDITIONAL(DEBUGLOG, test "${enable_debuglog}" != "no")
if (test "${enable_debuglog}" = "yes"); then
PKG_CHECK_MODULES(DBUSLOG, libdbuslogserver-dbus, dummy=yes,
AC_MSG_ERROR(libdbuslogserver-dbus is required))
CFLAGS="$CFLAGS $DBUSLOG_CFLAGS"
LIBS="$LIBS $DBUSLOG_LIBS"
fi

if (test "${prefix}" = "NONE"); then
dnl no prefix and no localstatedir, so default to /var
Expand Down
61 changes: 40 additions & 21 deletions ofono/drivers/ril/ril_plugin.c
Expand Up @@ -148,15 +148,24 @@ static void ril_plugin_retry_init_io(struct ril_slot *slot);

GLOG_MODULE_DEFINE("rilmodem");

static const char ril_debug_trace_name[] = "ril_trace";

static GLogModule ril_debug_trace_module = {
.name = ril_debug_trace_name,
.max_level = GLOG_LEVEL_VERBOSE,
.level = GLOG_LEVEL_VERBOSE,
.flags = GLOG_FLAG_HIDE_NAME
};

static struct ofono_debug_desc ril_debug_trace OFONO_DEBUG_ATTR = {
.name = "ril_trace",
.flags = OFONO_DEBUG_FLAG_DEFAULT,
.name = ril_debug_trace_name,
.flags = OFONO_DEBUG_FLAG_DEFAULT | OFONO_DEBUG_FLAG_HIDE_NAME,
.notify = ril_debug_trace_notify
};

static struct ofono_debug_desc ril_debug_dump OFONO_DEBUG_ATTR = {
.name = "ril_dump",
.flags = OFONO_DEBUG_FLAG_DEFAULT,
.flags = OFONO_DEBUG_FLAG_DEFAULT | OFONO_DEBUG_FLAG_HIDE_NAME,
.notify = ril_debug_dump_notify
};

Expand Down Expand Up @@ -699,12 +708,7 @@ static void ril_plugin_modem_removed(struct ril_modem *modem, void *data)
static void ril_plugin_trace(GRilIoChannel *io, GRILIO_PACKET_TYPE type,
guint id, guint code, const void *data, guint data_len, void *user_data)
{
/* Turn prefix off */
static GLogModule log_module = {
.max_level = GLOG_LEVEL_VERBOSE,
.level = GLOG_LEVEL_VERBOSE
};

static const GLogModule* log_module = &ril_debug_trace_module;
const char *prefix = io->name ? io->name : "";
const char dir = (type == GRILIO_PACKET_REQ) ? '<' : '>';
const char *scode;
Expand All @@ -717,21 +721,21 @@ static void ril_plugin_trace(GRilIoChannel *io, GRILIO_PACKET_TYPE type,
} else {
scode = ril_request_to_string(code);
}
gutil_log(&log_module, GLOG_LEVEL_VERBOSE, "%s%c [%08x] %s",
gutil_log(log_module, GLOG_LEVEL_VERBOSE, "%s%c [%08x] %s",
prefix, dir, id, scode);
break;
case GRILIO_PACKET_RESP:
gutil_log(&log_module, GLOG_LEVEL_VERBOSE, "%s%c [%08x] %s",
gutil_log(log_module, GLOG_LEVEL_VERBOSE, "%s%c [%08x] %s",
prefix, dir, id, ril_error_to_string(code));
break;
case GRILIO_PACKET_UNSOL:
gutil_log(&log_module, GLOG_LEVEL_VERBOSE, "%s%c %s",
gutil_log(log_module, GLOG_LEVEL_VERBOSE, "%s%c %s",
prefix, dir, ril_unsol_event_to_string(code));
break;
}
}

static void ril_debug_dump_update_slot(struct ril_slot *slot)
static void ril_debug_dump_update(struct ril_slot *slot)
{
if (slot->io) {
if (ril_debug_dump.flags & OFONO_DEBUG_FLAG_PRINT) {
Expand All @@ -747,7 +751,7 @@ static void ril_debug_dump_update_slot(struct ril_slot *slot)
}
}

static void ril_debug_trace_update_slot(struct ril_slot *slot)
static void ril_debug_trace_update(struct ril_slot *slot)
{
if (slot->io) {
if (ril_debug_trace.flags & OFONO_DEBUG_FLAG_PRINT) {
Expand All @@ -765,7 +769,7 @@ static void ril_debug_trace_update_slot(struct ril_slot *slot)
slot->dump_id);
slot->dump_id = 0;
}
ril_debug_dump_update_slot(slot);
ril_debug_dump_update(slot);
}
} else if (slot->trace_id) {
grilio_channel_remove_logger(slot->io, slot->trace_id);
Expand Down Expand Up @@ -965,8 +969,8 @@ static void ril_plugin_init_io(struct ril_slot *slot)
DBG("%s %s", slot->sockpath, slot->sub);
slot->io = grilio_channel_new_socket(slot->sockpath, slot->sub);
if (slot->io) {
ril_debug_trace_update_slot(slot);
ril_debug_dump_update_slot(slot);
ril_debug_trace_update(slot);
ril_debug_dump_update(slot);

if (slot->name) {
grilio_channel_set_name(slot->io, slot->name);
Expand Down Expand Up @@ -1522,19 +1526,19 @@ static void ril_plugin_enable_slot(struct ril_slot *slot)
slot->pub.enabled = TRUE;
}

struct ril_plugin_priv *ril_plugin = NULL;
static struct ril_plugin_priv *ril_plugin = NULL;

static void ril_debug_trace_notify(struct ofono_debug_desc *desc)
{
if (ril_plugin) {
ril_plugin_foreach_slot(ril_plugin, ril_debug_trace_update_slot);
ril_plugin_foreach_slot(ril_plugin, ril_debug_trace_update);
}
}

static void ril_debug_dump_notify(struct ofono_debug_desc *desc)
{
if (ril_plugin) {
ril_plugin_foreach_slot(ril_plugin, ril_debug_dump_update_slot);
ril_plugin_foreach_slot(ril_plugin, ril_debug_dump_update);
}
}

Expand All @@ -1561,7 +1565,22 @@ static int ril_plugin_init(void)
DBG("");
GASSERT(!ril_plugin);

/* ofono core calls openlog() */
/*
* Log categories (accessible via D-Bus) are generated from
* ofono_debug_desc structures, while libglibutil based log
* functions receive the log module name. Those should match
* otherwise the client receiving the log won't get the category
* information.
*/
grilio_hexdump_log.name = ril_debug_dump.name;
grilio_log.name = grilio_debug.name;

/*
* Debug log plugin hooks gutil_log_func2 while we replace
* gutil_log_func, they don't interfere with each other.
*
* Note that ofono core calls openlog(), so we don't need to.
*/
gutil_log_func = gutil_log_syslog;

ril_plugin_switch_user();
Expand Down
18 changes: 16 additions & 2 deletions ofono/include/log.h
Expand Up @@ -3,6 +3,7 @@
* oFono - Open Telephony stack for Linux
*
* Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
* Copyright (C) 2013-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand All @@ -22,6 +23,8 @@
#ifndef __OFONO_LOG_H
#define __OFONO_LOG_H

#include <stdarg.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -50,6 +53,7 @@ struct ofono_debug_desc {
const char *file;
#define OFONO_DEBUG_FLAG_DEFAULT (0)
#define OFONO_DEBUG_FLAG_PRINT (1 << 0)
#define OFONO_DEBUG_FLAG_HIDE_NAME (1 << 1)
unsigned int flags;
void (*notify)(struct ofono_debug_desc* desc);
} __attribute__((aligned(OFONO_DEBUG_ALIGN)));
Expand All @@ -67,10 +71,20 @@ struct ofono_debug_desc {
.file = __FILE__, .flags = OFONO_DEBUG_FLAG_DEFAULT, \
}; \
if (__ofono_debug_desc.flags & OFONO_DEBUG_FLAG_PRINT) \
ofono_debug("%s:%s() " fmt, \
__FILE__, __FUNCTION__ , ## arg); \
__ofono_dbg(&__ofono_debug_desc, "%s() " fmt, \
__FUNCTION__ , ## arg); \
} while (0)

void __ofono_dbg(const struct ofono_debug_desc *desc, const char *format, ...)
__attribute__((format(printf, 2, 3)));

typedef void (*ofono_log_hook_cb_t)(const struct ofono_debug_desc *desc,
int priority, const char *format, va_list va);

extern ofono_log_hook_cb_t ofono_log_hook;
extern struct ofono_debug_desc __start___debug[];
extern struct ofono_debug_desc __stop___debug[];

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 5e23459

Please sign in to comment.