]> git.proxmox.com Git - mirror_lxc.git/commitdiff
log: cleanup syslog handling
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 13 May 2020 12:35:54 +0000 (14:35 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 13 May 2020 12:35:54 +0000 (14:35 +0200)
Disable and enable syslog around lxc_check_inherited().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/log.c
src/lxc/log.h
src/lxc/start.c

index 1dd277d964096f86ea3023bc00737c459820dc71..59644aa7a3a5af65bc16fda238f5300342e61112 100644 (file)
@@ -44,7 +44,7 @@
 #define LXC_LOG_TIME_SIZE ((INTTYPE_TO_STRLEN(uint64_t)) * 2)
 
 int lxc_log_fd = -EBADF;
-static int syslog_enable = 0;
+static bool wants_syslog = false;
 int lxc_quiet_specified;
 int lxc_log_use_global_fd;
 static int lxc_loglevel_specified;
@@ -128,7 +128,7 @@ static int log_append_syslog(const struct lxc_log_appender *appender,
        __do_free char *msg = NULL;
        const char *log_container_name;
 
-       if (!syslog_enable)
+       if (!wants_syslog)
                return 0;
 
        log_container_name = lxc_log_get_container_name();
@@ -738,9 +738,14 @@ int lxc_log_syslog(int facility)
        return 0;
 }
 
-inline void lxc_log_enable_syslog(void)
+void lxc_log_syslog_enable(void)
 {
-       syslog_enable = 1;
+       wants_syslog = true;
+}
+
+void lxc_log_syslog_disable(void)
+{
+       wants_syslog = false;
 }
 
 /*
index 4cb0b5795f8ff58bb9bb293bb701461e2c1a7769..3f91d9bc5052690b2e51abd969cd9a060b4f1a92 100644 (file)
@@ -563,7 +563,8 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo,        \
 extern int lxc_log_fd;
 
 extern int lxc_log_syslog(int facility);
-extern void lxc_log_enable_syslog(void);
+extern void lxc_log_syslog_enable(void);
+extern void lxc_log_syslog_disable(void);
 extern int lxc_log_set_level(int *dest, int level);
 extern int lxc_log_get_level(void);
 extern bool lxc_log_has_valid_level(void);
index 668325d1194fd46f82da3b134e642a1b5f72fd13..ba92393ebfb99e400c1fde1e2d1e0897ff792916 100644 (file)
@@ -212,6 +212,13 @@ int lxc_check_inherited(struct lxc_conf *conf, bool closeall,
        if (conf && conf->close_all_fds)
                closeall = true;
 
+       /*
+        * Disable syslog at this point to avoid the above logging
+        * function to open a new fd and make the check_inherited function
+        * enter an infinite loop.
+        */
+       lxc_log_syslog_disable();
+
 restart:
        dir = opendir("/proc/self/fd");
        if (!dir)
@@ -272,21 +279,24 @@ restart:
 
 #endif
                if (closeall) {
-                       close(fd);
+                       if (close(fd))
+                               SYSINFO("Closed inherited fd %d", fd);
+                       else
+                               INFO("Closed inherited fd %d", fd);
                        closedir(dir);
-                       INFO("Closed inherited fd %d", fd);
                        goto restart;
                }
                WARN("Inherited fd %d", fd);
        }
+       closedir(dir);
 
-       /* Only enable syslog at this point to avoid the above logging function
-        * to open a new fd and make the check_inherited function enter an
-        * infinite loop.
+       /*
+        * Only enable syslog at this point to avoid the above logging
+        * function to open a new fd and make the check_inherited function
+        * enter an infinite loop.
         */
-       lxc_log_enable_syslog();
+       lxc_log_syslog_enable();
 
-       closedir(dir); /* cannot fail */
        return 0;
 }