Commit 95077473 by Serge Hallyn Committed by Stéphane Graber

log.c:__lxc_log_set_file: completely close log file when overriding

Otherwise after a shortcut on error we could end up trying to write to the closed log fd. Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent ef1ba04c
...@@ -251,6 +251,16 @@ static char *build_log_path(const char *name, const char *lxcpath) ...@@ -251,6 +251,16 @@ static char *build_log_path(const char *name, const char *lxcpath)
return p; return p;
} }
extern void lxc_log_close(void)
{
if (lxc_log_fd == -1)
return;
close(lxc_log_fd);
lxc_log_fd = -1;
free(log_fname);
log_fname = NULL;
}
/* /*
* This can be called: * This can be called:
* 1. when a program calls lxc_log_init with no logfile parameter (in which * 1. when a program calls lxc_log_init with no logfile parameter (in which
...@@ -263,8 +273,7 @@ static int __lxc_log_set_file(const char *fname, int create_dirs) ...@@ -263,8 +273,7 @@ static int __lxc_log_set_file(const char *fname, int create_dirs)
{ {
if (lxc_log_fd != -1) { if (lxc_log_fd != -1) {
// we are overriding the default. // we are overriding the default.
close(lxc_log_fd); lxc_log_close();
free(log_fname);
} }
assert(fname != NULL); assert(fname != NULL);
...@@ -378,16 +387,6 @@ extern int lxc_log_init(const char *name, const char *file, ...@@ -378,16 +387,6 @@ extern int lxc_log_init(const char *name, const char *file,
return ret; return ret;
} }
extern void lxc_log_close(void)
{
if (lxc_log_fd == -1)
return;
close(lxc_log_fd);
lxc_log_fd = -1;
free(log_fname);
log_fname = NULL;
}
/* /*
* This is called when we read a lxc.loglevel entry in a lxc.conf file. This * This is called when we read a lxc.loglevel entry in a lxc.conf file. This
* happens after processing command line arguments, which override the .conf * happens after processing command line arguments, which override the .conf
......
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