2013-09-19 06:09:33 +02:00
|
|
|
# block SIGALRM while logging through syslog to prevent deadlocks (through
|
|
|
|
# grace_alarm_handler)
|
|
|
|
# bnc#57354
|
|
|
|
|
2016-01-21 08:28:30 +01:00
|
|
|
Index: b/log.c
|
|
|
|
===================================================================
|
|
|
|
--- a/log.c
|
|
|
|
+++ b/log.c
|
|
|
|
@@ -51,6 +51,7 @@
|
2013-09-19 06:09:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
+#include <signal.h>
|
|
|
|
|
|
|
|
static LogLevel log_level = SYSLOG_LEVEL_INFO;
|
|
|
|
static int log_on_stderr = 1;
|
2016-01-21 08:28:30 +01:00
|
|
|
@@ -388,6 +389,7 @@ do_log(LogLevel level, const char *fmt,
|
2013-09-19 06:09:33 +02:00
|
|
|
char fmtbuf[MSGBUFSIZ];
|
|
|
|
char *txt = NULL;
|
|
|
|
int pri = LOG_INFO;
|
|
|
|
+ sigset_t nset, oset;
|
|
|
|
int saved_errno = errno;
|
|
|
|
log_handler_fn *tmp_handler;
|
|
|
|
|
2016-01-21 08:28:30 +01:00
|
|
|
@@ -446,6 +448,14 @@ do_log(LogLevel level, const char *fmt,
|
2013-09-19 06:09:33 +02:00
|
|
|
snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf);
|
2014-01-31 13:18:41 +01:00
|
|
|
(void)write(log_stderr_fd, msgbuf, strlen(msgbuf));
|
2013-09-19 06:09:33 +02:00
|
|
|
} else {
|
|
|
|
+ /* Prevent a race between the grace_alarm
|
|
|
|
+ * which writes a log message and terminates
|
|
|
|
+ * and main sshd code that leads to deadlock
|
|
|
|
+ * as syslog is not async safe.
|
|
|
|
+ */
|
|
|
|
+ sigemptyset(&nset);
|
|
|
|
+ sigaddset(&nset, SIGALRM);
|
|
|
|
+ sigprocmask(SIG_BLOCK, &nset, &oset);
|
|
|
|
#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
|
|
|
|
openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata);
|
|
|
|
syslog_r(pri, &sdata, "%.500s", fmtbuf);
|
2016-01-21 08:28:30 +01:00
|
|
|
@@ -455,6 +465,7 @@ do_log(LogLevel level, const char *fmt,
|
2013-09-19 06:09:33 +02:00
|
|
|
syslog(pri, "%.500s", fmtbuf);
|
|
|
|
closelog();
|
|
|
|
#endif
|
|
|
|
+ sigprocmask(SIG_SETMASK, &oset, NULL);
|
|
|
|
}
|
|
|
|
errno = saved_errno;
|
|
|
|
}
|