log.c (181110) | log.c (181111) |
---|---|
1/* $OpenBSD: log.c,v 1.39 2006/08/18 09:13:25 deraadt Exp $ */ | 1/* $OpenBSD: log.c,v 1.41 2008/06/10 04:50:25 dtucker Exp $ */ |
2/* 3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 5 * All rights reserved 6 * 7 * As far as I am concerned, the code I have written for this software 8 * can be used freely for any purpose. Any derived versions of this 9 * software must be clearly marked as such, and if the derived work is --- 29 unchanged lines hidden (view full) --- 39#include <sys/types.h> 40 41#include <stdarg.h> 42#include <stdio.h> 43#include <stdlib.h> 44#include <string.h> 45#include <syslog.h> 46#include <unistd.h> | 2/* 3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 5 * All rights reserved 6 * 7 * As far as I am concerned, the code I have written for this software 8 * can be used freely for any purpose. Any derived versions of this 9 * software must be clearly marked as such, and if the derived work is --- 29 unchanged lines hidden (view full) --- 39#include <sys/types.h> 40 41#include <stdarg.h> 42#include <stdio.h> 43#include <stdlib.h> 44#include <string.h> 45#include <syslog.h> 46#include <unistd.h> |
47#include <errno.h> |
|
47#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) 48# include <vis.h> 49#endif 50 51#include "xmalloc.h" 52#include "log.h" 53 54static LogLevel log_level = SYSLOG_LEVEL_INFO; --- 53 unchanged lines hidden (view full) --- 108 109 if (name != NULL) 110 for (i = 0; log_facilities[i].name; i++) 111 if (strcasecmp(log_facilities[i].name, name) == 0) 112 return log_facilities[i].val; 113 return SYSLOG_FACILITY_NOT_SET; 114} 115 | 48#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) 49# include <vis.h> 50#endif 51 52#include "xmalloc.h" 53#include "log.h" 54 55static LogLevel log_level = SYSLOG_LEVEL_INFO; --- 53 unchanged lines hidden (view full) --- 109 110 if (name != NULL) 111 for (i = 0; log_facilities[i].name; i++) 112 if (strcasecmp(log_facilities[i].name, name) == 0) 113 return log_facilities[i].val; 114 return SYSLOG_FACILITY_NOT_SET; 115} 116 |
117const char * 118log_facility_name(SyslogFacility facility) 119{ 120 u_int i; 121 122 for (i = 0; log_facilities[i].name; i++) 123 if (log_facilities[i].val == facility) 124 return log_facilities[i].name; 125 return NULL; 126} 127 |
|
116LogLevel 117log_level_number(char *name) 118{ 119 int i; 120 121 if (name != NULL) 122 for (i = 0; log_levels[i].name; i++) 123 if (strcasecmp(log_levels[i].name, name) == 0) 124 return log_levels[i].val; 125 return SYSLOG_LEVEL_NOT_SET; 126} 127 | 128LogLevel 129log_level_number(char *name) 130{ 131 int i; 132 133 if (name != NULL) 134 for (i = 0; log_levels[i].name; i++) 135 if (strcasecmp(log_levels[i].name, name) == 0) 136 return log_levels[i].val; 137 return SYSLOG_LEVEL_NOT_SET; 138} 139 |
140const char * 141log_level_name(LogLevel level) 142{ 143 u_int i; 144 145 for (i = 0; log_levels[i].name != NULL; i++) 146 if (log_levels[i].val == level) 147 return log_levels[i].name; 148 return NULL; 149} 150 |
|
128/* Error messages that should be logged. */ 129 130void 131error(const char *fmt,...) 132{ 133 va_list args; 134 135 va_start(args, fmt); --- 172 unchanged lines hidden (view full) --- 308{ 309#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT) 310 struct syslog_data sdata = SYSLOG_DATA_INIT; 311#endif 312 char msgbuf[MSGBUFSIZ]; 313 char fmtbuf[MSGBUFSIZ]; 314 char *txt = NULL; 315 int pri = LOG_INFO; | 151/* Error messages that should be logged. */ 152 153void 154error(const char *fmt,...) 155{ 156 va_list args; 157 158 va_start(args, fmt); --- 172 unchanged lines hidden (view full) --- 331{ 332#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT) 333 struct syslog_data sdata = SYSLOG_DATA_INIT; 334#endif 335 char msgbuf[MSGBUFSIZ]; 336 char fmtbuf[MSGBUFSIZ]; 337 char *txt = NULL; 338 int pri = LOG_INFO; |
339 int saved_errno = errno; |
|
316 317 if (level > log_level) 318 return; 319 320 switch (level) { 321 case SYSLOG_LEVEL_FATAL: 322 if (!log_on_stderr) 323 txt = "fatal"; --- 44 unchanged lines hidden (view full) --- 368 syslog_r(pri, &sdata, "%.500s", fmtbuf); 369 closelog_r(&sdata); 370#else 371 openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility); 372 syslog(pri, "%.500s", fmtbuf); 373 closelog(); 374#endif 375 } | 340 341 if (level > log_level) 342 return; 343 344 switch (level) { 345 case SYSLOG_LEVEL_FATAL: 346 if (!log_on_stderr) 347 txt = "fatal"; --- 44 unchanged lines hidden (view full) --- 392 syslog_r(pri, &sdata, "%.500s", fmtbuf); 393 closelog_r(&sdata); 394#else 395 openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility); 396 syslog(pri, "%.500s", fmtbuf); 397 closelog(); 398#endif 399 } |
400 errno = saved_errno; |
|
376} | 401} |