summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIevgen Vagin <i.vagin@samsung.com>2016-05-04 21:52:06 +0300
committerIevgen Vagin <i.vagin@samsung.com>2016-05-11 12:22:44 +0300
commited8f15d61d464b82dc793772bfb8850d885d1194 (patch)
tree7b18b876c3dba1cd7865e0bab25e9891c023890b
parenta274b00058e0375a4e326614ddbaf590a20bd0ff (diff)
downloadmurphy-ed8f15d61d464b82dc793772bfb8850d885d1194.tar.gz
murphy-ed8f15d61d464b82dc793772bfb8850d885d1194.tar.bz2
murphy-ed8f15d61d464b82dc793772bfb8850d885d1194.zip
Note: to enable plugin, it has to be loaded in configuration file (/etc/murphy/murphy.lua) by m:try_load_plugin('dlog') command; dlog support is enabled by default; use --disable-dlog configure command to build without dlog support Change-Id: I1e85f52a5ac58f24e1639e4b2945e9555b79289b Signed-off-by: Ievgen Vagin <i.vagin@samsung.com>
-rw-r--r--configure.ac30
-rw-r--r--packaging/murphy.spec2
-rw-r--r--packaging/murphyd.service2
-rw-r--r--src/Makefile.am29
-rw-r--r--src/plugins/plugin-dlog.c72
-rw-r--r--src/plugins/resource-native/libmurphy-resource/resource-log.c31
6 files changed, 161 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac
index 0327584..9afa18b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -463,6 +463,30 @@ AC_SUBST(SYSTEMD_ENABLED)
AC_SUBST(SYSTEMD_CFLAGS)
AC_SUBST(SYSTEMD_LIBS)
+# Check if dlog support should be enabled.
+AC_ARG_ENABLE(dlog,
+ [ --enable-dlog enable dlog support],
+ [enable_dlog=$enableval], [enable_dlog=auto])
+
+if test "$enable_dlog" != "no"; then
+ PKG_CHECK_MODULES(DLOG, dlog, [have_dlog=yes], [have_dlog=no])
+ if test "$have_dlog" = "no" -a "$enable_dlog" = "yes"; then
+ AC_MSG_ERROR([dlog development libraries not found.])
+ fi
+
+ enable_dlog="$have_dlog"
+else
+ AC_MSG_NOTICE([dlog support is disabled.])
+fi
+
+if test "$enable_dlog" = "yes"; then
+ AC_DEFINE([DLOG_ENABLED], 1, [Enable dlog support ?])
+fi
+AM_CONDITIONAL(DLOG_ENABLED, [test "$enable_dlog" = "yes"])
+AC_SUBST(DLOG_ENABLED)
+AC_SUBST(DLOG_CFLAGS)
+AC_SUBST(DLOG_LIBS)
+
# Set up murphy CFLAGS and LIBS.
MURPHY_CFLAGS=""
MURPHY_LIBS=""
@@ -508,7 +532,7 @@ esac
internal=""; it=""
external=""; et=""
disabled=""; dt=""
-for plugin in $all_plugins; do
+for plugin in $all_plugins; do
type=internal
for p in ${dynamic_plugins//,/ }; do
@@ -564,6 +588,7 @@ AM_CONDITIONAL(DISABLED_PLUGIN_RESOURCE_WRT, [check_if_disabled resource-wrt])
AM_CONDITIONAL(DISABLED_PLUGIN_DOMAIN_CONTROL,
[check_if_disabled domain-control])
AM_CONDITIONAL(DISABLED_PLUGIN_SYSTEMD, [check_if_disabled systemd])
+AM_CONDITIONAL(DISABLED_PLUGIN_DLOG, [check_if_disabled dlog])
AM_CONDITIONAL(BUILTIN_PLUGIN_TEST, [check_if_internal test])
AM_CONDITIONAL(BUILTIN_PLUGIN_DBUS, [check_if_internal dbus])
@@ -575,9 +600,10 @@ AM_CONDITIONAL(BUILTIN_PLUGIN_DOMAIN_CONTROL,
[check_if_internal domain-control])
AM_CONDITIONAL(BUILTIN_PLUGIN_LUA, [check_if_internal lua])
AM_CONDITIONAL(BUILTIN_PLUGIN_SYSTEMD, [check_if_internal systemd])
+AM_CONDITIONAL(BUILTIN_PLUGIN_DLOG, [check_if_internal dlog])
# Check for Check (unit test framework).
-PKG_CHECK_MODULES(CHECK,
+PKG_CHECK_MODULES(CHECK,
check >= 0.9.4,
[has_check="yes"], [has_check="no"])
AM_CONDITIONAL(HAVE_CHECK, test "x$has_check" = "xyes")
diff --git a/packaging/murphy.spec b/packaging/murphy.spec
index 285e28b..f8de76c 100644
--- a/packaging/murphy.spec
+++ b/packaging/murphy.spec
@@ -45,6 +45,7 @@ BuildRequires: bison
BuildRequires: pkgconfig(lua)
BuildRequires: pkgconfig(libsystemd-daemon)
BuildRequires: pkgconfig(libsystemd-journal)
+BuildRequires: pkgconfig(dlog)
#BuildRequires: pkgconfig(libcap)
#BuildRequires: pkgconfig(libtzplatform-config)
#%if %{with pulse}
@@ -489,4 +490,3 @@ ldconfig
%{_bindir}/test-domain-controller
%{_bindir}/murphy-console
%manifest murphy.manifest
-
diff --git a/packaging/murphyd.service b/packaging/murphyd.service
index 8b6fda2..60842b1 100644
--- a/packaging/murphyd.service
+++ b/packaging/murphyd.service
@@ -3,7 +3,7 @@ Description=Murphy Resource Policy Daemon
[Service]
Type=simple
-ExecStart=/usr/bin/murphyd -t systemd -vvv -f
+ExecStart=/usr/bin/murphyd -t dlog -vvv -f
KillSignal=SIGTERM
[Install]
diff --git a/src/Makefile.am b/src/Makefile.am
index 605de80..07be7ea 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1051,6 +1051,11 @@ libmurphy_resource_la_LDFLAGS = \
libmurphy_resource_la_LIBADD = \
libmurphy-common.la
+if DLOG_ENABLED
+libmurphy_resource_la_CFLAGS += $(DLOG_CFLAGS) -DDLOG_ENABLED
+libmurphy_resource_la_LIBADD += $(DLOG_LIBS)
+endif
+
libmurphy_resource_la_DEPENDENCIES = \
libmurphy-common.la \
linker-script.resource \
@@ -1426,6 +1431,30 @@ endif
endif
endif
+# dlog (logging) plugin
+if DLOG_ENABLED
+DLOG_PLUGIN_SOURCES = plugins/plugin-dlog.c
+DLOG_PLUGIN_CFLAGS = $(DLOG_CFLAGS)
+DLOG_PLUGIN_LIBS = $(DLOG_LIBS)
+
+if !DISABLED_PLUGIN_DLOG
+if BUILTIN_PLUGIN_DLOG
+BUILTIN_PLUGINS += $(DLOG_PLUGIN_SOURCES)
+BUILTIN_CFLAGS += $(DLOG_PLUGIN_CFLAGS)
+BUILTIN_LIBS += $(DLOG_PLUGIN_LIBS)
+else
+plugin_dlog_la_SOURCES = $(DLOG_PLUGIN_SOURCES)
+plugin_dlog_la_CFLAGS = $(DLOG_PLUGIN_CFLAGS) \
+ $(MURPHY_CFLAGS) \
+ $(AM_CFLAGS)
+plugin_dlog_la_LDFLAGS = -module -avoid-version
+plugin_dlog_la_LIBADD = $(DLOG_PLUGIN_LIBS)
+
+plugin_LTLIBRARIES += plugin-dlog.la
+endif
+endif
+endif
+
###################################
# murphy daemon
diff --git a/src/plugins/plugin-dlog.c b/src/plugins/plugin-dlog.c
new file mode 100644
index 0000000..be99417
--- /dev/null
+++ b/src/plugins/plugin-dlog.c
@@ -0,0 +1,72 @@
+#include <stdlib.h>
+#include <dlog.h>
+
+#include <murphy/common.h>
+#include <murphy/core.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "MURPHYD"
+
+/* Logger function */
+
+static void dlogger(void *data, mrp_log_level_t level, const char *file,
+ int line, const char *func, const char *format, va_list ap)
+{
+ va_list cp;
+ int prio;
+ char fbuf[1024];
+
+ MRP_UNUSED(data);
+
+ va_copy(cp, ap);
+ switch (level) {
+ case MRP_LOG_ERROR: prio = DLOG_ERROR; break;
+ case MRP_LOG_WARNING: prio = DLOG_WARN; break;
+ case MRP_LOG_INFO: prio = DLOG_INFO; break;
+ case MRP_LOG_DEBUG: prio = DLOG_DEBUG; break;
+ default: prio = DLOG_INFO;
+ }
+
+ snprintf(fbuf, sizeof(fbuf), "%s: %s(%d) > %s", file, func, line, format);
+ dlog_vprint(prio, LOG_TAG, fbuf, cp);
+
+ va_end(cp);
+}
+
+/* Plugin initialization */
+
+static int dlogger_init(mrp_plugin_t *plugin)
+{
+ MRP_UNUSED(plugin);
+
+ if (mrp_log_register_target("dlog", dlogger, NULL))
+ mrp_log_info("dlog: registered logging target.");
+ else
+ mrp_log_error("dlog: failed to register logging target.");
+
+ return TRUE;
+}
+
+/* Plugin deinitialization */
+
+static void dlogger_exit(mrp_plugin_t *plugin)
+{
+ MRP_UNUSED(plugin);
+
+ mrp_log_unregister_target("dlog");
+
+ return;
+}
+
+#define DLOGGER_DESCRIPTION "A dlog based logger for Murphy."
+#define DLOGGER_HELP "dlog logger support for Murphy."
+#define DLOGGER_VERSION MRP_VERSION_INT(0, 0, 1)
+#define DLOGGER_AUTHORS "Ievgen Vagin <i.vagin@samsung.com>"
+
+MURPHY_REGISTER_PLUGIN("dlog",
+ DLOGGER_VERSION, DLOGGER_DESCRIPTION,
+ DLOGGER_AUTHORS, DLOGGER_HELP, MRP_SINGLETON,
+ dlogger_init, dlogger_exit,
+ NULL, 0, NULL, 0, NULL, 0, NULL);
diff --git a/src/plugins/resource-native/libmurphy-resource/resource-log.c b/src/plugins/resource-native/libmurphy-resource/resource-log.c
index d5433f9..e1a0e8f 100644
--- a/src/plugins/resource-native/libmurphy-resource/resource-log.c
+++ b/src/plugins/resource-native/libmurphy-resource/resource-log.c
@@ -33,9 +33,38 @@
#include "resource-api.h"
#include "resource-private.h"
+#ifdef DLOG_ENABLED
+#include <dlog.h>
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "MURPHY_RESOURCE"
+#endif
+
static void default_logger(mrp_log_level_t level, const char *file,
int line, const char *func,
const char *format, va_list args)
+#ifdef DLOG_ENABLED
+{
+ va_list cp;
+ int prio;
+ char fbuf[1024];
+
+ va_copy(cp, args);
+ switch (level) {
+ case MRP_LOG_ERROR: prio = DLOG_ERROR; break;
+ case MRP_LOG_WARNING: prio = DLOG_WARN; break;
+ case MRP_LOG_INFO: prio = DLOG_INFO; break;
+ case MRP_LOG_DEBUG: prio = DLOG_DEBUG; break;
+ default: prio = DLOG_INFO;
+ }
+
+ snprintf(fbuf, sizeof(fbuf), "%s: %s(%d) > %s", file, func, line, format);
+ dlog_vprint(prio, LOG_TAG, fbuf, cp);
+
+ va_end(cp);
+}
+#else
{
va_list ap;
@@ -43,7 +72,7 @@ static void default_logger(mrp_log_level_t level, const char *file,
mrp_log_msgv(level, file, line, func, format, ap);
va_end(ap);
}
-
+#endif
static mrp_res_logger_t __res_logger = default_logger;