2011-01-31 13:24:57 +01:00
|
|
|
Index: log.c
|
|
|
|
===================================================================
|
|
|
|
--- log.c.orig
|
2007-01-07 17:26:05 +01:00
|
|
|
+++ log.c
|
2007-12-06 16:29:46 +01:00
|
|
|
@@ -51,6 +51,7 @@
|
2007-01-07 17:26:05 +01:00
|
|
|
|
|
|
|
#include "xmalloc.h"
|
|
|
|
#include "log.h"
|
|
|
|
+#include <signal.h>
|
|
|
|
|
|
|
|
static LogLevel log_level = SYSLOG_LEVEL_INFO;
|
|
|
|
static int log_on_stderr = 1;
|
2011-01-31 13:24:57 +01:00
|
|
|
@@ -336,6 +337,7 @@ do_log(LogLevel level, const char *fmt,
|
2007-01-07 17:26:05 +01:00
|
|
|
char fmtbuf[MSGBUFSIZ];
|
|
|
|
char *txt = NULL;
|
|
|
|
int pri = LOG_INFO;
|
|
|
|
+ sigset_t nset, oset;
|
2007-12-06 16:29:46 +01:00
|
|
|
int saved_errno = errno;
|
2007-01-07 17:26:05 +01:00
|
|
|
|
|
|
|
if (level > log_level)
|
2011-01-31 13:24:57 +01:00
|
|
|
@@ -387,6 +389,14 @@ do_log(LogLevel level, const char *fmt,
|
2007-10-08 16:50:28 +02:00
|
|
|
snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf);
|
|
|
|
write(STDERR_FILENO, msgbuf, strlen(msgbuf));
|
|
|
|
} else {
|
|
|
|
+ /* Prevent a race between the grace_alarm
|
|
|
|
+ * which writes a log message and terminates
|
2011-01-31 13:24:57 +01:00
|
|
|
+ * and main sshd code that leads to deadlock
|
2007-10-08 16:50:28 +02:00
|
|
|
+ * as syslog is not async safe.
|
2011-01-31 13:24:57 +01:00
|
|
|
+ */
|
2007-10-08 16:50:28 +02:00
|
|
|
+ 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);
|
2011-01-31 13:24:57 +01:00
|
|
|
@@ -396,6 +406,7 @@ do_log(LogLevel level, const char *fmt,
|
2007-01-07 17:26:05 +01:00
|
|
|
syslog(pri, "%.500s", fmtbuf);
|
|
|
|
closelog();
|
|
|
|
#endif
|
2007-10-08 16:50:28 +02:00
|
|
|
+ sigprocmask(SIG_SETMASK, &oset, NULL);
|
2007-01-07 17:26:05 +01:00
|
|
|
}
|
2007-12-06 16:29:46 +01:00
|
|
|
errno = saved_errno;
|
2007-01-07 17:26:05 +01:00
|
|
|
}
|