Skip to content

Commit

Permalink
Merge pull request #2611 from 2xsec/bugfix
Browse files Browse the repository at this point in the history
add compile flags for dlog
  • Loading branch information
brauner committed Sep 17, 2018
2 parents fd73418 + de1c05f commit de6af06
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 38 deletions.
7 changes: 7 additions & 0 deletions lxc.spec.in
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/lxc/Makefile.am
Expand Up @@ -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
Expand All @@ -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=

Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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) \
Expand Down
100 changes: 65 additions & 35 deletions src/lxc/log.c
Expand Up @@ -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 : "",
Expand All @@ -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 : "",
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -358,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
Expand Down Expand Up @@ -425,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
};
Expand Down

0 comments on commit de6af06

Please sign in to comment.