Unverified Commit 3f924551 by Christian Brauner Committed by Stéphane Graber

log: cleanup syslog handling

Disable and enable syslog around lxc_check_inherited(). Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent e758df85
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
#define LXC_LOG_TIME_SIZE ((INTTYPE_TO_STRLEN(uint64_t)) * 2) #define LXC_LOG_TIME_SIZE ((INTTYPE_TO_STRLEN(uint64_t)) * 2)
int lxc_log_fd = -EBADF; int lxc_log_fd = -EBADF;
static int syslog_enable = 0; static bool wants_syslog = false;
int lxc_quiet_specified; int lxc_quiet_specified;
int lxc_log_use_global_fd; int lxc_log_use_global_fd;
static int lxc_loglevel_specified; static int lxc_loglevel_specified;
...@@ -128,7 +128,7 @@ static int log_append_syslog(const struct lxc_log_appender *appender, ...@@ -128,7 +128,7 @@ static int log_append_syslog(const struct lxc_log_appender *appender,
__do_free char *msg = NULL; __do_free char *msg = NULL;
const char *log_container_name; const char *log_container_name;
if (!syslog_enable) if (!wants_syslog)
return 0; return 0;
log_container_name = lxc_log_get_container_name(); log_container_name = lxc_log_get_container_name();
...@@ -738,9 +738,14 @@ int lxc_log_syslog(int facility) ...@@ -738,9 +738,14 @@ int lxc_log_syslog(int facility)
return 0; 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;
} }
/* /*
......
...@@ -563,7 +563,8 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \ ...@@ -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_fd;
extern int lxc_log_syslog(int facility); 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_set_level(int *dest, int level);
extern int lxc_log_get_level(void); extern int lxc_log_get_level(void);
extern bool lxc_log_has_valid_level(void); extern bool lxc_log_has_valid_level(void);
......
...@@ -212,6 +212,13 @@ int lxc_check_inherited(struct lxc_conf *conf, bool closeall, ...@@ -212,6 +212,13 @@ int lxc_check_inherited(struct lxc_conf *conf, bool closeall,
if (conf && conf->close_all_fds) if (conf && conf->close_all_fds)
closeall = true; 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: restart:
dir = opendir("/proc/self/fd"); dir = opendir("/proc/self/fd");
if (!dir) if (!dir)
...@@ -272,21 +279,24 @@ restart: ...@@ -272,21 +279,24 @@ restart:
#endif #endif
if (closeall) { if (closeall) {
close(fd); if (close(fd))
SYSINFO("Closed inherited fd %d", fd);
else
INFO("Closed inherited fd %d", fd);
closedir(dir); closedir(dir);
INFO("Closed inherited fd %d", fd);
goto restart; goto restart;
} }
WARN("Inherited fd %d", fd); 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 * Only enable syslog at this point to avoid the above logging
* infinite loop. * 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; return 0;
} }
......
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