From: Christian Brauner Date: Wed, 13 May 2020 12:35:54 +0000 (+0200) Subject: log: cleanup syslog handling X-Git-Tag: lxc-5.0.0~437^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e2d6b9a8dda252b36a5af896871fb6ff0bb9fe1;p=thirdparty%2Flxc.git log: cleanup syslog handling Disable and enable syslog around lxc_check_inherited(). Signed-off-by: Christian Brauner --- diff --git a/src/lxc/log.c b/src/lxc/log.c index 1dd277d96..59644aa7a 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -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; } /* diff --git a/src/lxc/log.h b/src/lxc/log.h index 4cb0b5795..3f91d9bc5 100644 --- a/src/lxc/log.h +++ b/src/lxc/log.h @@ -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); diff --git a/src/lxc/start.c b/src/lxc/start.c index 668325d11..ba92393eb 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -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; }