]> git.proxmox.com Git - mirror_lxc.git/commit - src/lxc/conf.h
logs: introduce a thread-local 'current' lxc_config (v2)
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 21 Apr 2015 14:20:32 +0000 (09:20 -0500)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Wed, 22 Apr 2015 16:54:46 +0000 (11:54 -0500)
commit858377e4d968c8a7254e22dc7167acf76ac91a48
tree72fe1cf288471abf99cb1d33b4ca47a4e0148097
parented52814c776963efdcc9dcda1ec26fc09930ef93
logs: introduce a thread-local 'current' lxc_config (v2)

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.

Changelog (2015-04-21):
. always re-set current_config to NULL at end of an API
  call, rather than storing the previous value.  We don't
  nest API calls.
. remove the log_lock stuff which wasn't used
. lxc_conf_free: if the config is current_config, set
  current_config to NULL.  (It can't be another thread's
  current_config, or we wouldn't be freeing it)
. lxc_check_inherited: don't close fd if it is the
  current_config->logfd.  Note this is only called when
  starting a container, so we have no other threads at
  this point.

Changelog (2015-04-22)
. Unset the per-container logfd on destroy
.
. Do so before we rm the containerdir.  Otherwise if the logfile is set
. to $lxcpath/$name/log, the containerdir won't be fully deleted.

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
src/lxc/start.c