From 4856c8c0507024c21b8529f35ada542620a56fc7 Mon Sep 17 00:00:00 2001 From: Yugo Nagata Date: Tue, 14 Feb 2012 15:57:56 +0900 Subject: [PATCH] Fix up hangup during md5 authentication that occurs in daemon mode and log_destination is 'syslog'. (reported in [pgpool-hackers: 25]). Before daemonizing, openlog() opens syslog connection socket and gets a file descriptor (fd). Then in daemonizing process, the fd is closed as well as others. After daemonizing, pool_passwd is opened for md5 authentication and the same fd is assigned. In md5 authentication process, syslog() is called for logging. However it fails since the used fd is not for socket but for file. So, syslog() closed the fd and reopen new socket using the same fd again. Then in trying to read pool_passwd, it fails because the using fd is not for the pool_passwd file but for syslog connection socket and then gets hangup. Fix the problem by calling closelog() to close syslog connection safely before daemonizing and calling openlog() to reopen syslog connection after daemonizing. --- main.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.c b/main.c index 888fddab8..e661058ff 100644 --- a/main.c +++ b/main.c @@ -808,10 +808,20 @@ static void daemonize(void) dup2(i, 1); dup2(i, 2); + /* close syslog connection for daemonizing */ + if (pool_config->logsyslog) { + closelog(); + } + fdlimit = sysconf(_SC_OPEN_MAX); for (i = 3; i < fdlimit; i++) close(i); + /* reopen syslog connection after daemonizing */ + if (pool_config->logsyslog) { + openlog(pool_config->syslog_ident, LOG_PID|LOG_NDELAY|LOG_NOWAIT, pool_config->syslog_facility); + } + write_pid_file(); } -- 2.39.5