summaryrefslogtreecommitdiff
path: root/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'log.c')
-rw-r--r--log.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/log.c b/log.c
index 45affca13..70bfcfd34 100644
--- a/log.c
+++ b/log.c
@@ -34,15 +34,12 @@
34 */ 34 */
35 35
36#include "includes.h" 36#include "includes.h"
37RCSID("$OpenBSD: log.c,v 1.28 2003/05/24 09:02:22 djm Exp $"); 37RCSID("$OpenBSD: log.c,v 1.25 2003/01/11 18:29:43 markus Exp $");
38 38
39#include "log.h" 39#include "log.h"
40#include "xmalloc.h" 40#include "xmalloc.h"
41 41
42#include <syslog.h> 42#include <syslog.h>
43#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H)
44# include <vis.h>
45#endif
46 43
47static LogLevel log_level = SYSLOG_LEVEL_INFO; 44static LogLevel log_level = SYSLOG_LEVEL_INFO;
48static int log_on_stderr = 1; 45static int log_on_stderr = 1;
@@ -131,7 +128,7 @@ error(const char *fmt,...)
131/* Log this message (information that usually should go to the log). */ 128/* Log this message (information that usually should go to the log). */
132 129
133void 130void
134logit(const char *fmt,...) 131log(const char *fmt,...)
135{ 132{
136 va_list args; 133 va_list args;
137 134
@@ -344,9 +341,6 @@ log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
344void 341void
345do_log(LogLevel level, const char *fmt, va_list args) 342do_log(LogLevel level, const char *fmt, va_list args)
346{ 343{
347#ifdef OPENLOG_R
348 struct syslog_data sdata = SYSLOG_DATA_INIT;
349#endif
350 char msgbuf[MSGBUFSIZ]; 344 char msgbuf[MSGBUFSIZ];
351 char fmtbuf[MSGBUFSIZ]; 345 char fmtbuf[MSGBUFSIZ];
352 char *txt = NULL; 346 char *txt = NULL;
@@ -395,19 +389,14 @@ do_log(LogLevel level, const char *fmt, va_list args)
395 } else { 389 } else {
396 vsnprintf(msgbuf, sizeof(msgbuf), fmt, args); 390 vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
397 } 391 }
398 strnvis(fmtbuf, msgbuf, sizeof(fmtbuf), VIS_SAFE|VIS_OCTAL); 392 /* Escape magic chars in output. */
393 strnvis(fmtbuf, msgbuf, sizeof(fmtbuf), VIS_OCTAL);
394
399 if (log_on_stderr) { 395 if (log_on_stderr) {
400 snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf); 396 fprintf(stderr, "%s\r\n", fmtbuf);
401 write(STDERR_FILENO, msgbuf, strlen(msgbuf));
402 } else { 397 } else {
403#ifdef OPENLOG_R
404 openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata);
405 syslog_r(pri, &sdata, "%.500s", fmtbuf);
406 closelog_r(&sdata);
407#else
408 openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility); 398 openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility);
409 syslog(pri, "%.500s", fmtbuf); 399 syslog(pri, "%.500s", fmtbuf);
410 closelog(); 400 closelog();
411#endif
412 } 401 }
413} 402}