summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryar <yar@FreeBSD.org>2007-06-15 10:10:40 +0000
committeryar <yar@FreeBSD.org>2007-06-15 10:10:40 +0000
commit0a5d437c3dd0eac9955bd0742b4f63b7e0dc12b3 (patch)
tree0cf4f0b23b39d0349e39ff79da38da3b350b7334
parentd4335e2e0b750eb3e39554d703b90e85eb89441e (diff)
downloadFreeBSD-src-0a5d437c3dd0eac9955bd0742b4f63b7e0dc12b3.zip
FreeBSD-src-0a5d437c3dd0eac9955bd0742b4f63b7e0dc12b3.tar.gz
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.
-rw-r--r--libexec/atrun/atrun.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/libexec/atrun/atrun.c b/libexec/atrun/atrun.c
index 9881415..977eaa0 100644
--- a/libexec/atrun/atrun.c
+++ b/libexec/atrun/atrun.c
@@ -41,6 +41,7 @@ static const char rcsid[] =
#include <grp.h>
#include <pwd.h>
#include <signal.h>
+#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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
+ {
+ 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
- syslog(LOG_ERR, "%s: %m", a);
+ vsyslog(LOG_ERR, fmt, ap);
+ va_end(ap);
exit(EXIT_FAILURE);
}
OpenPOWER on IntegriCloud