]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
log.c:__lxc_log_set_file: completely close log file when overriding 821/head
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 15 Feb 2016 20:18:18 +0000 (12:18 -0800)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 15 Feb 2016 20:19:52 +0000 (12:19 -0800)
Otherwise after a shortcut on error we could end up trying to write
to the closed log fd.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/log.c

index babaebc84f27c0008a0d88e6d2d4f1fc23a8257f..55fa7f5b914e38ea1eaace1838ee0871fb1dcfdb 100644 (file)
@@ -253,6 +253,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
@@ -265,8 +275,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);
@@ -383,16 +392,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