From 287303f0ea9256244004fb559b3ba0e1c48b5fc1 Mon Sep 17 00:00:00 2001 From: Yaroslav Tykhiy Date: Fri, 15 Jun 2007 10:10:40 +0000 Subject: [PATCH] Make perr() variadic and add perrx() to use in cases where errno is irrelevant. Some code duplication can be reduced if perr() is variadic and perrx() is available. --- libexec/atrun/atrun.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/libexec/atrun/atrun.c b/libexec/atrun/atrun.c index 9881415637a9..977eaa0cfee7 100644 --- a/libexec/atrun/atrun.c +++ b/libexec/atrun/atrun.c @@ -41,6 +41,7 @@ static const char rcsid[] = #include #include #include +#include #include #include #include @@ -88,7 +89,8 @@ static const char rcsid[] = static int debug = 0; -void perr(const char *a); +void perr(const char *fmt, ...); +void perrx(const char *fmt, ...); static void usage(void); /* Local functions */ @@ -384,14 +386,38 @@ run_file(const char *filename, uid_t uid, gid_t gid) /* Needed in gloadavg.c */ void -perr(const char *a) +perr(const char *fmt, ...) { + const char * const fmtadd = ": %m"; + char nfmt[strlen(fmt) + strlen(fmtadd) + 1]; + va_list ap; + + va_start(ap, fmt); if (debug) { - warn("%s", a); + vwarn(fmt, ap); } else - syslog(LOG_ERR, "%s: %m", a); + { + snprintf(nfmt, sizeof(nfmt), "%s%s", fmt, fmtadd); + vsyslog(LOG_ERR, nfmt, ap); + } + va_end(ap); + + exit(EXIT_FAILURE); +} + +void +perrx(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + if (debug) + vwarnx(fmt, ap); + else + vsyslog(LOG_ERR, fmt, ap); + va_end(ap); exit(EXIT_FAILURE); }