Commit a16f71a1 by Serge Hallyn

Revert (by hand) "logs: introduce a thread-local 'current' lxc_config"

This is hopefully temporary - it works great for lxc itself, but seems to be upsetting golang. Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Tested-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
parent 95d5b147
...@@ -248,7 +248,6 @@ endif ...@@ -248,7 +248,6 @@ endif
init_lxc_static_LDFLAGS = -static init_lxc_static_LDFLAGS = -static
init_lxc_static_LDADD = @CAP_LIBS@ init_lxc_static_LDADD = @CAP_LIBS@
init_lxc_static_CFLAGS = $(AM_CFLAGS) -DNO_LXC_CONF
endif endif
install-exec-local: install-soPROGRAMS install-exec-local: install-soPROGRAMS
......
...@@ -178,17 +178,6 @@ struct caps_opt { ...@@ -178,17 +178,6 @@ struct caps_opt {
int value; int value;
}; };
/*
* The lxc_conf of the container currently being worked on in an
* API call
* This is used in the error calls
*/
#ifdef HAVE_TLS
__thread struct lxc_conf *current_config;
#else
struct lxc_conf *current_config;
#endif
/* Declare this here, since we don't want to reshuffle the whole file. */ /* Declare this here, since we don't want to reshuffle the whole file. */
static int in_caplist(int cap, struct lxc_list *caps); static int in_caplist(int cap, struct lxc_list *caps);
...@@ -2584,7 +2573,6 @@ struct lxc_conf *lxc_conf_init(void) ...@@ -2584,7 +2573,6 @@ struct lxc_conf *lxc_conf_init(void)
return NULL; return NULL;
} }
new->kmsg = 0; new->kmsg = 0;
new->logfd = -1;
lxc_list_init(&new->cgroup); lxc_list_init(&new->cgroup);
lxc_list_init(&new->network); lxc_list_init(&new->network);
lxc_list_init(&new->mount_list); lxc_list_init(&new->mount_list);
...@@ -4258,8 +4246,6 @@ void lxc_conf_free(struct lxc_conf *conf) ...@@ -4258,8 +4246,6 @@ void lxc_conf_free(struct lxc_conf *conf)
free(conf->rootfs.path); free(conf->rootfs.path);
free(conf->rootfs.pivot); free(conf->rootfs.pivot);
free(conf->logfile); free(conf->logfile);
if (conf->logfd != -1)
close(conf->logfd);
free(conf->utsname); free(conf->utsname);
free(conf->ttydir); free(conf->ttydir);
free(conf->fstab); free(conf->fstab);
......
...@@ -336,7 +336,6 @@ struct lxc_conf { ...@@ -336,7 +336,6 @@ struct lxc_conf {
// store the config file specified values here. // store the config file specified values here.
char *logfile; // the logfile as specifed in config char *logfile; // the logfile as specifed in config
int loglevel; // loglevel as specifed in config (if any) int loglevel; // loglevel as specifed in config (if any)
int logfd;
int inherit_ns_fd[LXC_NS_MAX]; int inherit_ns_fd[LXC_NS_MAX];
...@@ -366,12 +365,6 @@ struct lxc_conf { ...@@ -366,12 +365,6 @@ struct lxc_conf {
char *init_cmd; char *init_cmd;
}; };
#ifdef HAVE_TLS
extern __thread struct lxc_conf *current_config;
#else
extern struct lxc_conf *current_config;
#endif
int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf, int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf,
const char *lxcpath, char *argv[]); const char *lxcpath, char *argv[]);
......
...@@ -1171,15 +1171,15 @@ static int config_lsm_se_context(const char *key, const char *value, ...@@ -1171,15 +1171,15 @@ static int config_lsm_se_context(const char *key, const char *value,
} }
static int config_logfile(const char *key, const char *value, static int config_logfile(const char *key, const char *value,
struct lxc_conf *c) struct lxc_conf *lxc_conf)
{ {
int ret; int ret;
// store these values in the lxc_conf, and then try to set for // store these values in the lxc_conf, and then try to set for
// actual current logging. // actual current logging.
ret = config_path_item(&c->logfile, value); ret = config_path_item(&lxc_conf->logfile, value);
if (ret == 0) if (ret == 0)
ret = lxc_log_set_file(&c->logfd, c->logfile); ret = lxc_log_set_file(lxc_conf->logfile);
return ret; return ret;
} }
...@@ -1198,7 +1198,7 @@ static int config_loglevel(const char *key, const char *value, ...@@ -1198,7 +1198,7 @@ static int config_loglevel(const char *key, const char *value,
// store these values in the lxc_conf, and then try to set for // store these values in the lxc_conf, and then try to set for
// actual current logging. // actual current logging.
lxc_conf->loglevel = newlevel; lxc_conf->loglevel = newlevel;
return lxc_log_set_level(&lxc_conf->loglevel, newlevel); return lxc_log_set_level(newlevel);
} }
static int config_autodev(const char *key, const char *value, static int config_autodev(const char *key, const char *value,
...@@ -2381,9 +2381,9 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv, ...@@ -2381,9 +2381,9 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv,
else if (strcmp(key, "lxc.se_context") == 0) else if (strcmp(key, "lxc.se_context") == 0)
v = c->lsm_se_context; v = c->lsm_se_context;
else if (strcmp(key, "lxc.logfile") == 0) else if (strcmp(key, "lxc.logfile") == 0)
v = c->logfile; v = lxc_log_get_file();
else if (strcmp(key, "lxc.loglevel") == 0) else if (strcmp(key, "lxc.loglevel") == 0)
v = lxc_log_priority_to_string(c->loglevel); v = lxc_log_priority_to_string(lxc_log_get_level());
else if (strcmp(key, "lxc.cgroup") == 0) // all cgroup info else if (strcmp(key, "lxc.cgroup") == 0) // all cgroup info
return lxc_get_cgroup_entry(c, retv, inlen, "all"); return lxc_get_cgroup_entry(c, retv, inlen, "all");
else if (strncmp(key, "lxc.cgroup.", 11) == 0) // specific cgroup info else if (strncmp(key, "lxc.cgroup.", 11) == 0) // specific cgroup info
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include <pthread.h>
#define __USE_GNU /* for *_CLOEXEC */ #define __USE_GNU /* for *_CLOEXEC */
...@@ -41,44 +40,27 @@ ...@@ -41,44 +40,27 @@
#define LXC_LOG_PREFIX_SIZE 32 #define LXC_LOG_PREFIX_SIZE 32
#define LXC_LOG_BUFFER_SIZE 512 #define LXC_LOG_BUFFER_SIZE 512
static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; #ifdef HAVE_TLS
static void lock_mutex(pthread_mutex_t *l) __thread int lxc_log_fd = -1;
{ static __thread char log_prefix[LXC_LOG_PREFIX_SIZE] = "lxc";
int ret; static __thread char *log_fname = NULL;
/* command line values for logfile or logpriority should always override
if ((ret = pthread_mutex_lock(l)) != 0) { * values from the configuration file or defaults
fprintf(stderr, "pthread_mutex_lock returned:%d %s\n", ret, strerror(ret)); */
exit(1); static __thread int lxc_logfile_specified = 0;
} static __thread int lxc_loglevel_specified = 0;
} static __thread int lxc_quiet_specified = 0;
#else
static void unlock_mutex(pthread_mutex_t *l)
{
int ret;
if ((ret = pthread_mutex_unlock(l)) != 0) {
fprintf(stderr, "pthread_mutex_unlock returned:%d %s\n", ret, strerror(ret));
exit(1);
}
}
void log_lock(void)
{
lock_mutex(&log_mutex);
}
void log_unlock(void)
{
unlock_mutex(&log_mutex);
}
int lxc_log_fd = -1; int lxc_log_fd = -1;
int lxc_quiet_specified;
int lxc_log_use_global_fd;
static int lxc_loglevel_specified;
static char log_prefix[LXC_LOG_PREFIX_SIZE] = "lxc"; static char log_prefix[LXC_LOG_PREFIX_SIZE] = "lxc";
static char *log_fname = NULL; static char *log_fname = NULL;
static int lxc_quiet_specified = 0;
/* command line values for logfile or logpriority should always override
* values from the configuration file or defaults
*/
static int lxc_logfile_specified = 0;
static int lxc_loglevel_specified = 0;
#endif
lxc_log_define(lxc_log, lxc); lxc_log_define(lxc_log, lxc);
...@@ -103,17 +85,8 @@ static int log_append_logfile(const struct lxc_log_appender *appender, ...@@ -103,17 +85,8 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
char buffer[LXC_LOG_BUFFER_SIZE]; char buffer[LXC_LOG_BUFFER_SIZE];
int n; int n;
int ms; int ms;
int fd_to_use = -1;
#ifndef NO_LXC_CONF
if (!lxc_log_use_global_fd && current_config)
fd_to_use = current_config->logfd;
#endif
if (fd_to_use == -1) if (lxc_log_fd == -1)
fd_to_use = lxc_log_fd;
if (fd_to_use == -1)
return 0; return 0;
ms = event->timestamp.tv_usec / 1000; ms = event->timestamp.tv_usec / 1000;
...@@ -138,7 +111,7 @@ static int log_append_logfile(const struct lxc_log_appender *appender, ...@@ -138,7 +111,7 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
buffer[n] = '\n'; buffer[n] = '\n';
return write(fd_to_use, buffer, n + 1); return write(lxc_log_fd, buffer, n + 1);
} }
static struct lxc_log_appender log_appender_stderr = { static struct lxc_log_appender log_appender_stderr = {
...@@ -163,7 +136,7 @@ static struct lxc_log_category log_root = { ...@@ -163,7 +136,7 @@ static struct lxc_log_category log_root = {
struct lxc_log_category lxc_log_category_lxc = { struct lxc_log_category lxc_log_category_lxc = {
.name = "lxc", .name = "lxc",
.priority = LXC_LOG_PRIORITY_ERROR, .priority = LXC_LOG_PRIORITY_ERROR,
.appender = &log_appender_logfile, .appender = &log_appender_stderr,
.parent = &log_root .parent = &log_root
}; };
...@@ -332,11 +305,6 @@ static int _lxc_log_set_file(const char *name, const char *lxcpath, int create_d ...@@ -332,11 +305,6 @@ static int _lxc_log_set_file(const char *name, const char *lxcpath, int create_d
return ret; return ret;
} }
/*
* lxc_log_init:
* Called from lxc front-end programs (like lxc-create, lxc-start) to
* initalize the log defaults.
*/
extern int lxc_log_init(const char *name, const char *file, extern int lxc_log_init(const char *name, const char *file,
const char *priority, const char *prefix, int quiet, const char *priority, const char *prefix, int quiet,
const char *lxcpath) const char *lxcpath)
...@@ -352,12 +320,10 @@ extern int lxc_log_init(const char *name, const char *file, ...@@ -352,12 +320,10 @@ extern int lxc_log_init(const char *name, const char *file,
if (priority) if (priority)
lxc_priority = lxc_log_priority_to_int(priority); lxc_priority = lxc_log_priority_to_int(priority);
if (!lxc_loglevel_specified) { lxc_log_category_lxc.priority = lxc_priority;
lxc_log_category_lxc.priority = lxc_priority;
lxc_loglevel_specified = 1;
}
if (!lxc_quiet_specified) { if (!lxc_quiet_specified) {
lxc_log_category_lxc.appender = &log_appender_logfile;
if (!quiet) if (!quiet)
lxc_log_category_lxc.appender->next = &log_appender_stderr; lxc_log_category_lxc.appender->next = &log_appender_stderr;
} }
...@@ -369,7 +335,6 @@ extern int lxc_log_init(const char *name, const char *file, ...@@ -369,7 +335,6 @@ extern int lxc_log_init(const char *name, const char *file,
if (strcmp(file, "none") == 0) if (strcmp(file, "none") == 0)
return 0; return 0;
ret = __lxc_log_set_file(file, 1); ret = __lxc_log_set_file(file, 1);
lxc_log_use_global_fd = 1;
} else { } else {
/* if no name was specified, there nothing to do */ /* if no name was specified, there nothing to do */
if (!name) if (!name)
...@@ -420,13 +385,15 @@ extern void lxc_log_close(void) ...@@ -420,13 +385,15 @@ extern void lxc_log_close(void)
* happens after processing command line arguments, which override the .conf * happens after processing command line arguments, which override the .conf
* settings. So only set the level if previously unset. * settings. So only set the level if previously unset.
*/ */
extern int lxc_log_set_level(int *dest, int level) extern int lxc_log_set_level(int level)
{ {
if (lxc_loglevel_specified)
return 0;
if (level < 0 || level >= LXC_LOG_PRIORITY_NOTSET) { if (level < 0 || level >= LXC_LOG_PRIORITY_NOTSET) {
ERROR("invalid log priority %d", level); ERROR("invalid log priority %d", level);
return -1; return -1;
} }
*dest = level; lxc_log_category_lxc.priority = level;
return 0; return 0;
} }
...@@ -448,23 +415,11 @@ extern bool lxc_log_has_valid_level(void) ...@@ -448,23 +415,11 @@ extern bool lxc_log_has_valid_level(void)
* happens after processing command line arguments, which override the .conf * happens after processing command line arguments, which override the .conf
* settings. So only set the file if previously unset. * settings. So only set the file if previously unset.
*/ */
extern int lxc_log_set_file(int *fd, const char *fname) extern int lxc_log_set_file(const char *fname)
{ {
if (*fd != -1) { if (lxc_logfile_specified)
close(*fd); return 0;
*fd = -1; return __lxc_log_set_file(fname, 0);
}
if (build_dir(fname)) {
ERROR("failed to create dir for log file \"%s\" : %s", fname,
strerror(errno));
return -1;
}
*fd = log_open(fname);
if (*fd == -1)
return -errno;
return 0;
} }
extern const char *lxc_log_get_file(void) extern const char *lxc_log_get_file(void)
...@@ -485,6 +440,11 @@ extern const char *lxc_log_get_prefix(void) ...@@ -485,6 +440,11 @@ extern const char *lxc_log_get_prefix(void)
extern void lxc_log_options_no_override() extern void lxc_log_options_no_override()
{ {
if (lxc_log_get_file())
lxc_logfile_specified = 1;
if (lxc_log_get_level() != LXC_LOG_PRIORITY_NOTSET)
lxc_loglevel_specified = 1;
lxc_quiet_specified = 1; lxc_quiet_specified = 1;
lxc_loglevel_specified = 1;
} }
...@@ -33,8 +33,6 @@ ...@@ -33,8 +33,6 @@
#include <strings.h> #include <strings.h>
#include <stdbool.h> #include <stdbool.h>
#include "conf.h"
#ifndef O_CLOEXEC #ifndef O_CLOEXEC
#define O_CLOEXEC 02000000 #define O_CLOEXEC 02000000
#endif #endif
...@@ -106,10 +104,6 @@ struct lxc_log_category { ...@@ -106,10 +104,6 @@ struct lxc_log_category {
const struct lxc_log_category *parent; const struct lxc_log_category *parent;
}; };
#ifndef NO_LXC_CONF
extern int lxc_log_use_global_fd;
#endif
/* /*
* Returns true if the chained priority is equal to or higher than * Returns true if the chained priority is equal to or higher than
* given priority. * given priority.
...@@ -122,14 +116,7 @@ lxc_log_priority_is_enabled(const struct lxc_log_category* category, ...@@ -122,14 +116,7 @@ lxc_log_priority_is_enabled(const struct lxc_log_category* category,
category->parent) category->parent)
category = category->parent; category = category->parent;
int cmp_prio = category->priority; return priority >= category->priority;
#ifndef NO_LXC_CONF
if (!lxc_log_use_global_fd && current_config &&
current_config->loglevel != LXC_LOG_PRIORITY_NOTSET)
cmp_prio = current_config->loglevel;
#endif
return priority >= cmp_prio;
} }
/* /*
...@@ -307,14 +294,18 @@ ATTR_UNUSED static inline void LXC_##PRIORITY(struct lxc_log_locinfo* locinfo, \ ...@@ -307,14 +294,18 @@ ATTR_UNUSED static inline void LXC_##PRIORITY(struct lxc_log_locinfo* locinfo, \
ERROR("%s - " format, strerror(errno), ##__VA_ARGS__); \ ERROR("%s - " format, strerror(errno), ##__VA_ARGS__); \
} while (0) } while (0)
#ifdef HAVE_TLS
extern __thread int lxc_log_fd;
#else
extern int lxc_log_fd; extern int lxc_log_fd;
#endif
extern int lxc_log_init(const char *name, const char *file, extern int lxc_log_init(const char *name, const char *file,
const char *priority, const char *prefix, int quiet, const char *priority, const char *prefix, int quiet,
const char *lxcpath); const char *lxcpath);
extern int lxc_log_set_file(int *fd, const char *fname); extern int lxc_log_set_file(const char *fname);
extern int lxc_log_set_level(int *dest, int level); extern int lxc_log_set_level(int level);
extern void lxc_log_set_prefix(const char *prefix); extern void lxc_log_set_prefix(const char *prefix);
extern const char *lxc_log_get_file(void); extern const char *lxc_log_get_file(void);
extern int lxc_log_get_level(void); extern int lxc_log_get_level(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment