diff options
author | Colin Watson <cjwatson@debian.org> | 2003-09-23 18:08:35 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2003-09-23 18:08:35 +0000 |
commit | d59fd3e421aa81b8e5e118f3f806081df2aca879 (patch) | |
tree | 356a4e607edc979c625bb33db63c656d771478bd /log.c | |
parent | 7505658c58e96b8d270f1928a0e1fa7f3e0c266b (diff) | |
parent | 45431c9b4677608680cd071768cbf156b316a7e8 (diff) |
Merge 3.7.1p2 to the trunk. I have absolutely no idea yet whether this will
work.
Diffstat (limited to 'log.c')
-rw-r--r-- | log.c | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -34,12 +34,15 @@ | |||
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "includes.h" | 36 | #include "includes.h" |
37 | RCSID("$OpenBSD: log.c,v 1.25 2003/01/11 18:29:43 markus Exp $"); | 37 | RCSID("$OpenBSD: log.c,v 1.28 2003/05/24 09:02:22 djm 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 | ||
43 | 46 | ||
44 | static LogLevel log_level = SYSLOG_LEVEL_INFO; | 47 | static LogLevel log_level = SYSLOG_LEVEL_INFO; |
45 | static int log_on_stderr = 1; | 48 | static int log_on_stderr = 1; |
@@ -128,7 +131,7 @@ error(const char *fmt,...) | |||
128 | /* Log this message (information that usually should go to the log). */ | 131 | /* Log this message (information that usually should go to the log). */ |
129 | 132 | ||
130 | void | 133 | void |
131 | log(const char *fmt,...) | 134 | logit(const char *fmt,...) |
132 | { | 135 | { |
133 | va_list args; | 136 | va_list args; |
134 | 137 | ||
@@ -341,6 +344,9 @@ log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr) | |||
341 | void | 344 | void |
342 | do_log(LogLevel level, const char *fmt, va_list args) | 345 | do_log(LogLevel level, const char *fmt, va_list args) |
343 | { | 346 | { |
347 | #ifdef OPENLOG_R | ||
348 | struct syslog_data sdata = SYSLOG_DATA_INIT; | ||
349 | #endif | ||
344 | char msgbuf[MSGBUFSIZ]; | 350 | char msgbuf[MSGBUFSIZ]; |
345 | char fmtbuf[MSGBUFSIZ]; | 351 | char fmtbuf[MSGBUFSIZ]; |
346 | char *txt = NULL; | 352 | char *txt = NULL; |
@@ -389,14 +395,19 @@ do_log(LogLevel level, const char *fmt, va_list args) | |||
389 | } else { | 395 | } else { |
390 | vsnprintf(msgbuf, sizeof(msgbuf), fmt, args); | 396 | vsnprintf(msgbuf, sizeof(msgbuf), fmt, args); |
391 | } | 397 | } |
392 | /* Escape magic chars in output. */ | 398 | strnvis(fmtbuf, msgbuf, sizeof(fmtbuf), VIS_SAFE|VIS_OCTAL); |
393 | strnvis(fmtbuf, msgbuf, sizeof(fmtbuf), VIS_OCTAL); | ||
394 | |||
395 | if (log_on_stderr) { | 399 | if (log_on_stderr) { |
396 | fprintf(stderr, "%s\r\n", fmtbuf); | 400 | snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf); |
401 | write(STDERR_FILENO, msgbuf, strlen(msgbuf)); | ||
397 | } else { | 402 | } 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 | ||
398 | openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility); | 408 | openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility); |
399 | syslog(pri, "%.500s", fmtbuf); | 409 | syslog(pri, "%.500s", fmtbuf); |
400 | closelog(); | 410 | closelog(); |
411 | #endif | ||
401 | } | 412 | } |
402 | } | 413 | } |