]> git.ipfire.org Git - thirdparty/lxc.git/commit
logs: introduce a thread-local 'current' lxc_config
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Wed, 11 Mar 2015 22:10:55 +0000 (22:10 +0000)
committerStéphane Graber <stgraber@ubuntu.com>
Fri, 10 Apr 2015 15:28:30 +0000 (11:28 -0400)
commit46932d01d95581dbab1e5af9283313c4f2be6e9b
tree7750a163805132d36075f472121f37b94090d95e
parentbda67c3143755fedda8bd51d389bec325aa69607
logs: introduce a thread-local 'current' lxc_config

The logging code uses a global log_fd and log_level to direct
logging (ERROR(), etc).  While the container configuration file allows
for lxc.loglevel and lxc.logfile, those are only used at configuration
file read time to set the global variables.  This works ok in the
lxc front-end programs, but becomes a problem with threaded API users.

The simplest solution would be to not allow per-container configuration
files, but it'd be nice to avoid that.

Passing a logfd or lxc_conf into every ERROR/INFO/etc call is "possible",
but would be a huge complication as there are many functions, including
struct member functions and callbacks, which don't have that info and
would need to get it from somewhere.

So the approach I'm taking here is to say that all real container work
is done inside api calls, and therefore the API calls themselves can
set a thread-local variable indicating which log info to use.  If
unset, then use the global values.  The lxc-* programs, when called
with a '-o logfile' argument, set a global variable to indicate that
the user-specified value should be used.

In this patch:

If the lxc container configuration specifies a loglevel/logfile, only
set the lxc_config's logfd and loglevel according to those, not the
global values.

Each API call is wrapped to set/unset the current_config.  (The few
exceptions are calls which do not result in any log actions)

Update logfile appender to use the logfile specified in lxc_conf if (a)
current_config is set and (b) the lxc-* command did not override it.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/Makefile.am
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c
src/lxc/log.c
src/lxc/log.h
src/lxc/lxccontainer.c