]> andersk Git - gssapi-openssh.git/blobdiff - openssh/log.c
Import of OpenSSH 4.7p1
[gssapi-openssh.git] / openssh / log.c
index 5d8625d15a1144ffc5c1d0a57d17ef4e6311c7cf..fae5b043f3e55701a9ca1d8a99aa9791e2513bff 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenBSD: log.c,v 1.40 2007/05/17 07:50:31 djm Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: log.c,v 1.29 2003/09/23 20:17:11 markus Exp $");
 
-#include "log.h"
-#include "xmalloc.h"
+#include <sys/types.h>
 
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <syslog.h>
+#include <unistd.h>
+#include <errno.h>
 #if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H)
 # include <vis.h>
 #endif
 
+#include "xmalloc.h"
+#include "log.h"
+
 static LogLevel log_level = SYSLOG_LEVEL_INFO;
 static int log_on_stderr = 1;
 static int log_facility = LOG_AUTH;
@@ -130,6 +138,20 @@ error(const char *fmt,...)
        va_end(args);
 }
 
+void
+sigdie(const char *fmt,...)
+{
+#ifdef DO_LOG_SAFE_IN_SIGHAND
+       va_list args;
+
+       va_start(args, fmt);
+       do_log(SYSLOG_LEVEL_FATAL, fmt, args);
+       va_end(args);
+#endif
+       _exit(1);
+}
+
+
 /* Log this message (information that usually should go to the log). */
 
 void
@@ -193,6 +215,10 @@ debug3(const char *fmt,...)
 void
 log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
 {
+#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
+       struct syslog_data sdata = SYSLOG_DATA_INIT;
+#endif
+
        argv0 = av0;
 
        switch (level) {
@@ -261,6 +287,19 @@ log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
                    (int) facility);
                exit(1);
        }
+
+       /*
+        * If an external library (eg libwrap) attempts to use syslog
+        * immediately after reexec, syslog may be pointing to the wrong
+        * facility, so we force an open/close of syslog here.
+        */
+#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
+       openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata);
+       closelog_r(&sdata);
+#else
+       openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility);
+       closelog();
+#endif
 }
 
 #define MSGBUFSIZ 1024
@@ -275,6 +314,7 @@ do_log(LogLevel level, const char *fmt, va_list args)
        char fmtbuf[MSGBUFSIZ];
        char *txt = NULL;
        int pri = LOG_INFO;
+       int saved_errno = errno;
 
        if (level > log_level)
                return;
@@ -335,4 +375,5 @@ do_log(LogLevel level, const char *fmt, va_list args)
                closelog();
 #endif
        }
+       errno = saved_errno;
 }
This page took 0.112918 seconds and 4 git commands to generate.