From: Serge Hallyn Date: Mon, 15 Feb 2016 20:18:18 +0000 (-0800) Subject: log.c:__lxc_log_set_file: completely close log file when overriding X-Git-Tag: lxc-1.0.9~91 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=950774731968d2a442d4c3da7197c147c4cab1fe;p=thirdparty%2Flxc.git 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: Serge Hallyn --- diff --git a/src/lxc/log.c b/src/lxc/log.c index 948735d56..3fd0ffceb 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -251,6 +251,16 @@ static char *build_log_path(const char *name, const char *lxcpath) 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: * 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) { if (lxc_log_fd != -1) { // we are overriding the default. - close(lxc_log_fd); - free(log_fname); + lxc_log_close(); } assert(fname != NULL); @@ -378,16 +387,6 @@ extern int lxc_log_init(const char *name, const char *file, 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 * happens after processing command line arguments, which override the .conf