Changeset View
Changeset View
Standalone View
Standalone View
sbin/dhclient/errwarn.c
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <errno.h> | #include <errno.h> | ||||
#include "dhcpd.h" | #include "dhcpd.h" | ||||
static void do_percentm(char *obuf, size_t size, char *ibuf); | static void do_percentm(char *obuf, size_t size, const char *ibuf); | ||||
static char mbuf[1024]; | static char mbuf[1024]; | ||||
static char fbuf[1024]; | static char fbuf[1024]; | ||||
int warnings_occurred; | int warnings_occurred; | ||||
/* | /* | ||||
* Log an error message, then exit. | * Log an error message, then exit. | ||||
*/ | */ | ||||
void | void | ||||
error(char *fmt, ...) | error(const char *fmt, ...) | ||||
{ | { | ||||
va_list list; | va_list list; | ||||
do_percentm(fbuf, sizeof(fbuf), fmt); | do_percentm(fbuf, sizeof(fbuf), fmt); | ||||
va_start(list, fmt); | va_start(list, fmt); | ||||
vsnprintf(mbuf, sizeof(mbuf), fbuf, list); | vsnprintf(mbuf, sizeof(mbuf), fbuf, list); | ||||
va_end(list); | va_end(list); | ||||
Show All 17 Lines | if (pidfile != NULL) | ||||
pidfile_remove(pidfile); | pidfile_remove(pidfile); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
/* | /* | ||||
* Log a warning message... | * Log a warning message... | ||||
*/ | */ | ||||
int | int | ||||
warning(char *fmt, ...) | warning(const char *fmt, ...) | ||||
{ | { | ||||
va_list list; | va_list list; | ||||
do_percentm(fbuf, sizeof(fbuf), fmt); | do_percentm(fbuf, sizeof(fbuf), fmt); | ||||
va_start(list, fmt); | va_start(list, fmt); | ||||
vsnprintf(mbuf, sizeof(mbuf), fbuf, list); | vsnprintf(mbuf, sizeof(mbuf), fbuf, list); | ||||
va_end(list); | va_end(list); | ||||
Show All 9 Lines | #endif | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Log a note... | * Log a note... | ||||
*/ | */ | ||||
int | int | ||||
note(char *fmt, ...) | note(const char *fmt, ...) | ||||
{ | { | ||||
va_list list; | va_list list; | ||||
do_percentm(fbuf, sizeof(fbuf), fmt); | do_percentm(fbuf, sizeof(fbuf), fmt); | ||||
va_start(list, fmt); | va_start(list, fmt); | ||||
vsnprintf(mbuf, sizeof(mbuf), fbuf, list); | vsnprintf(mbuf, sizeof(mbuf), fbuf, list); | ||||
va_end(list); | va_end(list); | ||||
Show All 9 Lines | #endif | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Log a debug message... | * Log a debug message... | ||||
*/ | */ | ||||
int | int | ||||
debug(char *fmt, ...) | debug(const char *fmt, ...) | ||||
{ | { | ||||
va_list list; | va_list list; | ||||
do_percentm(fbuf, sizeof(fbuf), fmt); | do_percentm(fbuf, sizeof(fbuf), fmt); | ||||
va_start(list, fmt); | va_start(list, fmt); | ||||
vsnprintf(mbuf, sizeof(mbuf), fbuf, list); | vsnprintf(mbuf, sizeof(mbuf), fbuf, list); | ||||
va_end(list); | va_end(list); | ||||
Show All 9 Lines | #endif | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Find %m in the input string and substitute an error message string. | * Find %m in the input string and substitute an error message string. | ||||
*/ | */ | ||||
static void | static void | ||||
do_percentm(char *obuf, size_t size, char *ibuf) | do_percentm(char *obuf, size_t size, const char *ibuf) | ||||
{ | { | ||||
char ch; | char ch; | ||||
char *s = ibuf; | const char *s = ibuf; | ||||
char *t = obuf; | char *t = obuf; | ||||
size_t prlen; | size_t prlen; | ||||
size_t fmt_left; | size_t fmt_left; | ||||
int saved_errno = errno; | int saved_errno = errno; | ||||
/* | /* | ||||
* We wouldn't need this mess if printf handled %m, or if | * We wouldn't need this mess if printf handled %m, or if | ||||
* strerror() had been invented before syslog(). | * strerror() had been invented before syslog(). | ||||
Show All 13 Lines | if (ch == '%' && s[1] == 'm') { | ||||
fmt_left--; | fmt_left--; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
*t = '\0'; | *t = '\0'; | ||||
} | } | ||||
int | int | ||||
parse_warn(char *fmt, ...) | parse_warn(const char *fmt, ...) | ||||
{ | { | ||||
va_list list; | va_list list; | ||||
static char spaces[] = | static char spaces[] = | ||||
" " | " " | ||||
" "; /* 80 spaces */ | " "; /* 80 spaces */ | ||||
do_percentm(mbuf, sizeof(mbuf), fmt); | do_percentm(mbuf, sizeof(mbuf), fmt); | ||||
snprintf(fbuf, sizeof(fbuf), "%s line %d: %s", tlname, lexline, mbuf); | snprintf(fbuf, sizeof(fbuf), "%s line %d: %s", tlname, lexline, mbuf); | ||||
Show All 25 Lines |