From a8eed52c173f90aed27a390460542fc13bb375b9 Mon Sep 17 00:00:00 2001 From: 2xsec Date: Thu, 13 Sep 2018 11:37:54 +0900 Subject: [PATCH 1/3] add compile flags for dlog Signed-off-by: 2xsec --- lxc.spec.in | 7 +++++++ src/lxc/Makefile.am | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lxc.spec.in b/lxc.spec.in index 87978feb26..61cb1456f6 100644 --- a/lxc.spec.in +++ b/lxc.spec.in @@ -91,6 +91,13 @@ BuildRequires: libseccomp-devel %endif %endif +# +# Additional package for Tizen +# +%if %{defined tizen_version} +BuildRequires: pkgconfig(dlog) +%endif + %description Containers are insulated areas inside a system, which have their own namespace for filesystem, network, PID, IPC, CPU and memory allocation and which can be diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am index 08fa8e03a3..aa879500d6 100644 --- a/src/lxc/Makefile.am +++ b/src/lxc/Makefile.am @@ -212,7 +212,8 @@ AM_CFLAGS += -DHAVE_SELINUX endif if ENABLE_DLOG -AM_CFLAGS += -DHAVE_DLOG +AM_CFLAGS += -DHAVE_DLOG \ + $(DLOG_CFLAGS) endif if USE_CONFIGPATH_LOGS @@ -233,7 +234,8 @@ liblxc_la_LDFLAGS = -pthread \ liblxc_la_LIBADD = $(CAP_LIBS) \ $(GNUTLS_LIBS) \ $(SELINUX_LIBS) \ - $(SECCOMP_LIBS) + $(SECCOMP_LIBS) \ + $(DLOG_LIBS) bin_SCRIPTS= @@ -285,7 +287,8 @@ LDADD = liblxc.la \ @CAP_LIBS@ \ @GNUTLS_LIBS@ \ @SECCOMP_LIBS@ \ - @SELINUX_LIBS@ + @SELINUX_LIBS@ \ + @DLOG_LIBS@ if ENABLE_TOOLS lxc_attach_SOURCES = tools/lxc_attach.c \ @@ -421,6 +424,7 @@ pam_cgfs_la_CFLAGS = $(AM_CFLAGS) -DNO_LXC_CONF pam_cgfs_la_LIBADD = $(AM_LIBS) \ $(PAM_LIBS) \ + $(DLOG_LIBS) \ -L$(top_srcdir) pam_cgfs_la_LDFLAGS = $(AM_LDFLAGS) \ From 8178adc6ad79ba6a98fd1cd22bb8fa51545c3a85 Mon Sep 17 00:00:00 2001 From: 2xsec Date: Fri, 14 Sep 2018 18:16:04 +0900 Subject: [PATCH 2/3] log: add common functions Signed-off-by: 2xsec --- src/lxc/log.c | 66 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/src/lxc/log.c b/src/lxc/log.c index 4f6611726a..8476a43af7 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -101,37 +101,58 @@ static int lxc_log_priority_to_syslog(int priority) return LOG_NOTICE; } -/*---------------------------------------------------------------------------*/ -static int log_append_syslog(const struct lxc_log_appender *appender, - struct lxc_log_event *event) +static const char *lxc_log_get_container_name() +{ +#ifndef NO_LXC_CONF + if (current_config && !log_vmname) + return current_config->name; +#endif + + return log_vmname; +} + +static char *lxc_log_get_va_msg(struct lxc_log_event *event) { char *msg; int rc, len; va_list args; - const char *log_container_name = log_vmname; -#ifndef NO_LXC_CONF - if (current_config && !log_container_name) - log_container_name = current_config->name; -#endif - - if (!syslog_enable) - return 0; + if (!event) + return NULL; va_copy(args, *event->vap); len = vsnprintf(NULL, 0, event->fmt, args) + 1; va_end(args); msg = malloc(len * sizeof(char)); - if (msg == NULL) - return 0; + if (!msg) + return NULL; rc = vsnprintf(msg, len, event->fmt, *event->vap); if (rc == -1 || rc >= len) { free(msg); - return 0; + return NULL; } + return msg; +} + +/*---------------------------------------------------------------------------*/ +static int log_append_syslog(const struct lxc_log_appender *appender, + struct lxc_log_event *event) +{ + char *msg; + const char *log_container_name; + + if (!syslog_enable) + return 0; + + log_container_name = lxc_log_get_container_name(); + + msg = lxc_log_get_va_msg(event); + if (!msg) + return 0; + syslog(lxc_log_priority_to_syslog(event->priority), "%s%s %s - %s:%s:%d - %s" , log_container_name ? log_container_name : "", @@ -154,12 +175,7 @@ static int log_append_stderr(const struct lxc_log_appender *appender, if (event->priority < LXC_LOG_LEVEL_ERROR) return 0; - log_container_name = log_vmname; - -#ifndef NO_LXC_CONF - if (current_config && !log_container_name) - log_container_name = current_config->name; -#endif + log_container_name = lxc_log_get_container_name(); fprintf(stderr, "%s: %s%s", log_prefix, log_container_name ? log_container_name : "", @@ -299,18 +315,16 @@ static int log_append_logfile(const struct lxc_log_appender *appender, int n; ssize_t ret; int fd_to_use = -1; - const char *log_container_name = log_vmname; + const char *log_container_name; #ifndef NO_LXC_CONF - if (current_config) { + if (current_config) if (!lxc_log_use_global_fd) fd_to_use = current_config->logfd; - - if (!log_container_name) - log_container_name = current_config->name; - } #endif + log_container_name = lxc_log_get_container_name(); + if (fd_to_use == -1) fd_to_use = lxc_log_fd; From de1c05f33993e1559aa3ab2a52fd9756173a135e Mon Sep 17 00:00:00 2001 From: 2xsec Date: Fri, 14 Sep 2018 18:28:44 +0900 Subject: [PATCH 3/3] log: add additional info of dlog Signed-off-by: 2xsec --- src/lxc/log.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/lxc/log.c b/src/lxc/log.c index 8476a43af7..df1b87761a 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -372,33 +372,49 @@ static int log_append_logfile(const struct lxc_log_appender *appender, static int log_append_dlog(const struct lxc_log_appender *appender, struct lxc_log_event *event) { - if (event->priority < LXC_LOG_LEVEL_ERROR) - return 0; + char *msg = lxc_log_get_va_msg(event); + const char *log_container_name = lxc_log_get_container_name(); - switch(event->priority) { + switch (event->priority) { case LXC_LOG_LEVEL_TRACE: case LXC_LOG_LEVEL_DEBUG: - LOG_VA(LOG_DEBUG, LOG_TAG, event->fmt, *event->vap); + print_log(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > [%s] %s", + event->locinfo->file, event->locinfo->func, event->locinfo->line, + log_container_name ? log_container_name : "-", + msg ? msg : "-"); break; case LXC_LOG_LEVEL_INFO: - LOG_VA(LOG_INFO, LOG_TAG, event->fmt, *event->vap); + print_log(DLOG_INFO, LOG_TAG, "%s: %s(%d) > [%s] %s", + event->locinfo->file, event->locinfo->func, event->locinfo->line, + log_container_name ? log_container_name : "-", + msg ? msg : "-"); break; case LXC_LOG_LEVEL_NOTICE: case LXC_LOG_LEVEL_WARN: - LOG_VA(LOG_WARN, LOG_TAG, event->fmt, *event->vap); + print_log(DLOG_WARN, LOG_TAG, "%s: %s(%d) > [%s] %s", + event->locinfo->file, event->locinfo->func, event->locinfo->line, + log_container_name ? log_container_name : "-", + msg ? msg : "-"); break; case LXC_LOG_LEVEL_ERROR: - LOG_VA(LOG_ERROR, LOG_TAG, event->fmt, *event->vap); + print_log(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > [%s] %s", + event->locinfo->file, event->locinfo->func, event->locinfo->line, + log_container_name ? log_container_name : "-", + msg ? msg : "-"); break; case LXC_LOG_LEVEL_CRIT: case LXC_LOG_LEVEL_ALERT: case LXC_LOG_LEVEL_FATAL: - LOG_VA(LOG_FATAL, LOG_TAG, event->fmt, *event->vap); + print_log(DLOG_FATAL, LOG_TAG, "%s: %s(%d) > [%s] %s", + event->locinfo->file, event->locinfo->func, event->locinfo->line, + log_container_name ? log_container_name : "-", + msg ? msg : "-"); break; default: break; } + free(msg); return 0; } #endif @@ -439,7 +455,7 @@ static struct lxc_log_category log_root = { #if HAVE_DLOG struct lxc_log_category lxc_log_category_lxc = { .name = "lxc", - .priority = LXC_LOG_LEVEL_ERROR, + .priority = LXC_LOG_LEVEL_TRACE, .appender = &log_appender_dlog, .parent = &log_root };