mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-15 15:01:57 +00:00
commit
de6af06271
@ -91,6 +91,13 @@ BuildRequires: libseccomp-devel
|
|||||||
%endif
|
%endif
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
|
#
|
||||||
|
# Additional package for Tizen
|
||||||
|
#
|
||||||
|
%if %{defined tizen_version}
|
||||||
|
BuildRequires: pkgconfig(dlog)
|
||||||
|
%endif
|
||||||
|
|
||||||
%description
|
%description
|
||||||
Containers are insulated areas inside a system, which have their own namespace
|
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
|
for filesystem, network, PID, IPC, CPU and memory allocation and which can be
|
||||||
|
@ -212,7 +212,8 @@ AM_CFLAGS += -DHAVE_SELINUX
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if ENABLE_DLOG
|
if ENABLE_DLOG
|
||||||
AM_CFLAGS += -DHAVE_DLOG
|
AM_CFLAGS += -DHAVE_DLOG \
|
||||||
|
$(DLOG_CFLAGS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if USE_CONFIGPATH_LOGS
|
if USE_CONFIGPATH_LOGS
|
||||||
@ -233,7 +234,8 @@ liblxc_la_LDFLAGS = -pthread \
|
|||||||
liblxc_la_LIBADD = $(CAP_LIBS) \
|
liblxc_la_LIBADD = $(CAP_LIBS) \
|
||||||
$(GNUTLS_LIBS) \
|
$(GNUTLS_LIBS) \
|
||||||
$(SELINUX_LIBS) \
|
$(SELINUX_LIBS) \
|
||||||
$(SECCOMP_LIBS)
|
$(SECCOMP_LIBS) \
|
||||||
|
$(DLOG_LIBS)
|
||||||
|
|
||||||
bin_SCRIPTS=
|
bin_SCRIPTS=
|
||||||
|
|
||||||
@ -285,7 +287,8 @@ LDADD = liblxc.la \
|
|||||||
@CAP_LIBS@ \
|
@CAP_LIBS@ \
|
||||||
@GNUTLS_LIBS@ \
|
@GNUTLS_LIBS@ \
|
||||||
@SECCOMP_LIBS@ \
|
@SECCOMP_LIBS@ \
|
||||||
@SELINUX_LIBS@
|
@SELINUX_LIBS@ \
|
||||||
|
@DLOG_LIBS@
|
||||||
|
|
||||||
if ENABLE_TOOLS
|
if ENABLE_TOOLS
|
||||||
lxc_attach_SOURCES = tools/lxc_attach.c \
|
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_cgfs_la_LIBADD = $(AM_LIBS) \
|
||||||
$(PAM_LIBS) \
|
$(PAM_LIBS) \
|
||||||
|
$(DLOG_LIBS) \
|
||||||
-L$(top_srcdir)
|
-L$(top_srcdir)
|
||||||
|
|
||||||
pam_cgfs_la_LDFLAGS = $(AM_LDFLAGS) \
|
pam_cgfs_la_LDFLAGS = $(AM_LDFLAGS) \
|
||||||
|
100
src/lxc/log.c
100
src/lxc/log.c
@ -101,37 +101,58 @@ static int lxc_log_priority_to_syslog(int priority)
|
|||||||
return LOG_NOTICE;
|
return LOG_NOTICE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
static const char *lxc_log_get_container_name()
|
||||||
static int log_append_syslog(const struct lxc_log_appender *appender,
|
{
|
||||||
struct lxc_log_event *event)
|
#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;
|
char *msg;
|
||||||
int rc, len;
|
int rc, len;
|
||||||
va_list args;
|
va_list args;
|
||||||
const char *log_container_name = log_vmname;
|
|
||||||
|
|
||||||
#ifndef NO_LXC_CONF
|
if (!event)
|
||||||
if (current_config && !log_container_name)
|
return NULL;
|
||||||
log_container_name = current_config->name;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!syslog_enable)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
va_copy(args, *event->vap);
|
va_copy(args, *event->vap);
|
||||||
len = vsnprintf(NULL, 0, event->fmt, args) + 1;
|
len = vsnprintf(NULL, 0, event->fmt, args) + 1;
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
msg = malloc(len * sizeof(char));
|
msg = malloc(len * sizeof(char));
|
||||||
if (msg == NULL)
|
if (!msg)
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
rc = vsnprintf(msg, len, event->fmt, *event->vap);
|
rc = vsnprintf(msg, len, event->fmt, *event->vap);
|
||||||
if (rc == -1 || rc >= len) {
|
if (rc == -1 || rc >= len) {
|
||||||
free(msg);
|
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),
|
syslog(lxc_log_priority_to_syslog(event->priority),
|
||||||
"%s%s %s - %s:%s:%d - %s" ,
|
"%s%s %s - %s:%s:%d - %s" ,
|
||||||
log_container_name ? log_container_name : "",
|
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)
|
if (event->priority < LXC_LOG_LEVEL_ERROR)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
log_container_name = log_vmname;
|
log_container_name = lxc_log_get_container_name();
|
||||||
|
|
||||||
#ifndef NO_LXC_CONF
|
|
||||||
if (current_config && !log_container_name)
|
|
||||||
log_container_name = current_config->name;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
fprintf(stderr, "%s: %s%s", log_prefix,
|
fprintf(stderr, "%s: %s%s", log_prefix,
|
||||||
log_container_name ? log_container_name : "",
|
log_container_name ? log_container_name : "",
|
||||||
@ -299,18 +315,16 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
|
|||||||
int n;
|
int n;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
int fd_to_use = -1;
|
int fd_to_use = -1;
|
||||||
const char *log_container_name = log_vmname;
|
const char *log_container_name;
|
||||||
|
|
||||||
#ifndef NO_LXC_CONF
|
#ifndef NO_LXC_CONF
|
||||||
if (current_config) {
|
if (current_config)
|
||||||
if (!lxc_log_use_global_fd)
|
if (!lxc_log_use_global_fd)
|
||||||
fd_to_use = current_config->logfd;
|
fd_to_use = current_config->logfd;
|
||||||
|
|
||||||
if (!log_container_name)
|
|
||||||
log_container_name = current_config->name;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
log_container_name = lxc_log_get_container_name();
|
||||||
|
|
||||||
if (fd_to_use == -1)
|
if (fd_to_use == -1)
|
||||||
fd_to_use = lxc_log_fd;
|
fd_to_use = lxc_log_fd;
|
||||||
|
|
||||||
@ -358,33 +372,49 @@ again:
|
|||||||
static int log_append_dlog(const struct lxc_log_appender *appender,
|
static int log_append_dlog(const struct lxc_log_appender *appender,
|
||||||
struct lxc_log_event *event)
|
struct lxc_log_event *event)
|
||||||
{
|
{
|
||||||
if (event->priority < LXC_LOG_LEVEL_ERROR)
|
char *msg = lxc_log_get_va_msg(event);
|
||||||
return 0;
|
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_TRACE:
|
||||||
case LXC_LOG_LEVEL_DEBUG:
|
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;
|
break;
|
||||||
case LXC_LOG_LEVEL_INFO:
|
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;
|
break;
|
||||||
case LXC_LOG_LEVEL_NOTICE:
|
case LXC_LOG_LEVEL_NOTICE:
|
||||||
case LXC_LOG_LEVEL_WARN:
|
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;
|
break;
|
||||||
case LXC_LOG_LEVEL_ERROR:
|
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;
|
break;
|
||||||
case LXC_LOG_LEVEL_CRIT:
|
case LXC_LOG_LEVEL_CRIT:
|
||||||
case LXC_LOG_LEVEL_ALERT:
|
case LXC_LOG_LEVEL_ALERT:
|
||||||
case LXC_LOG_LEVEL_FATAL:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(msg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -425,7 +455,7 @@ static struct lxc_log_category log_root = {
|
|||||||
#if HAVE_DLOG
|
#if HAVE_DLOG
|
||||||
struct lxc_log_category lxc_log_category_lxc = {
|
struct lxc_log_category lxc_log_category_lxc = {
|
||||||
.name = "lxc",
|
.name = "lxc",
|
||||||
.priority = LXC_LOG_LEVEL_ERROR,
|
.priority = LXC_LOG_LEVEL_TRACE,
|
||||||
.appender = &log_appender_dlog,
|
.appender = &log_appender_dlog,
|
||||||
.parent = &log_root
|
.parent = &log_root
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user