]> andersk Git - gssapi-openssh.git/blobdiff - openssh/log.c
merged OpenSSH 3.7.1p2 to trunk
[gssapi-openssh.git] / openssh / log.c
index 860fa5e5a26838edab19c5fa3bdfb03d049eb5db..9bce2555baa9f55c50578b2943b3844941733dce 100644 (file)
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: log.c,v 1.22 2002/02/22 12:20:34 markus Exp $");
+RCSID("$OpenBSD: log.c,v 1.28 2003/05/24 09:02:22 djm Exp $");
 
 #include "log.h"
 #include "xmalloc.h"
 
 #include <syslog.h>
+#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H)
+# include <vis.h>
+#endif
 
 static LogLevel log_level = SYSLOG_LEVEL_INFO;
 static int log_on_stderr = 1;
@@ -92,6 +95,7 @@ SyslogFacility
 log_facility_number(char *name)
 {
        int i;
+
        if (name != NULL)
                for (i = 0; log_facilities[i].name; i++)
                        if (strcasecmp(log_facilities[i].name, name) == 0)
@@ -103,6 +107,7 @@ LogLevel
 log_level_number(char *name)
 {
        int i;
+
        if (name != NULL)
                for (i = 0; log_levels[i].name; i++)
                        if (strcasecmp(log_levels[i].name, name) == 0)
@@ -116,6 +121,7 @@ void
 error(const char *fmt,...)
 {
        va_list args;
+
        va_start(args, fmt);
        do_log(SYSLOG_LEVEL_ERROR, fmt, args);
        va_end(args);
@@ -124,9 +130,10 @@ error(const char *fmt,...)
 /* Log this message (information that usually should go to the log). */
 
 void
-log(const char *fmt,...)
+logit(const char *fmt,...)
 {
        va_list args;
+
        va_start(args, fmt);
        do_log(SYSLOG_LEVEL_INFO, fmt, args);
        va_end(args);
@@ -138,6 +145,7 @@ void
 verbose(const char *fmt,...)
 {
        va_list args;
+
        va_start(args, fmt);
        do_log(SYSLOG_LEVEL_VERBOSE, fmt, args);
        va_end(args);
@@ -149,6 +157,7 @@ void
 debug(const char *fmt,...)
 {
        va_list args;
+
        va_start(args, fmt);
        do_log(SYSLOG_LEVEL_DEBUG1, fmt, args);
        va_end(args);
@@ -158,6 +167,7 @@ void
 debug2(const char *fmt,...)
 {
        va_list args;
+
        va_start(args, fmt);
        do_log(SYSLOG_LEVEL_DEBUG2, fmt, args);
        va_end(args);
@@ -167,6 +177,7 @@ void
 debug3(const char *fmt,...)
 {
        va_list args;
+
        va_start(args, fmt);
        do_log(SYSLOG_LEVEL_DEBUG3, fmt, args);
        va_end(args);
@@ -215,6 +226,19 @@ fatal_remove_cleanup(void (*proc) (void *context), void *context)
            (u_long) proc, (u_long) context);
 }
 
+/* Remove all cleanups, to be called after fork() */
+void
+fatal_remove_all_cleanups(void)
+{
+       struct fatal_cleanup *cu, *next_cu;
+
+       for (cu = fatal_cleanups; cu; cu = next_cu) {
+               next_cu = cu->next;
+               xfree(cu);
+       }
+       fatal_cleanups = NULL;
+}
+
 /* Cleanup and exit */
 void
 fatal_cleanup(void)
@@ -318,6 +342,9 @@ log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
 void
 do_log(LogLevel level, const char *fmt, va_list args)
 {
+#ifdef OPENLOG_R
+       struct syslog_data sdata = SYSLOG_DATA_INIT;
+#endif
        char msgbuf[MSGBUFSIZ];
        char fmtbuf[MSGBUFSIZ];
        char *txt = NULL;
@@ -366,11 +393,19 @@ do_log(LogLevel level, const char *fmt, va_list args)
        } else {
                vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
        }
+       strnvis(fmtbuf, msgbuf, sizeof(fmtbuf), VIS_SAFE|VIS_OCTAL);
        if (log_on_stderr) {
-               fprintf(stderr, "%d: %s\r\n", getpid(), msgbuf);
+               snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf);
+               write(STDERR_FILENO, msgbuf, strlen(msgbuf));
        } else {
+#ifdef OPENLOG_R
+               openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata);
+               syslog_r(pri, &sdata, "%.500s", fmtbuf);
+               closelog_r(&sdata);
+#else
                openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility);
-               syslog(pri, "%.500s", msgbuf);
+               syslog(pri, "%.500s", fmtbuf);
                closelog();
+#endif
        }
 }
This page took 0.048161 seconds and 4 git commands to generate.