-/*========== logging ==========*/
-
-static void logcore(int sysloglevel, const char *fmt, ...)
- __attribute__((printf,2,3))
-static void logcore(int sysloglevel, const char *fmt, ...) {
- va_list al;
- va_start(al,fmt);
- if (become_daemon) {
- vsyslog(sysloglevel,fmt,al);
- } else {
- vfprintf(stderr,fmt,al);
- putc('\n',stderr);
- }
-}
-
-static void logv(int sysloglevel, const char *pfx, int errnoval,
- int exitstatus, const char *fmt, va_list al)
- __attribute__((printf,4,0))
-static void logv(int sysloglevel, const char *pfx, int errnoval,
- int exitstatus, const char *fmt, va_list al) {
- char msgbuf[256];
- vsnprintf(msgbuf,sizeof(msgbuf), fmt,al);
- msgbuf[sizeof(msgbuf)-1]= 0;
-
- if (sysloglevel >= LOG_ERR && (errnoval==EACCES || errnoval==EPERM))
- sysloglevel= LOG_ERR; /* run by wrong user, probably */
-
- logcore(sysloglevel, "<%s>%s: %s%s%s",
- sitename, pfx, msgbuf,
- errnoval>=0 ? ": " : "",
- errnoval>=0 ? strerror(errnoval) : "");
-}
-
-#define logwrap(fn, pfx, sysloglevel, errno, estatus) \
- static void fn(const char *fmt, ...) \
- __attribute__((printf,1,2)); \
- static void fn(const char *fmt, ...) { \
- va_list al; \
- va_start(al,fmt); \
- logv(sysloglevel, pfx, errno, estatus, fmt, al); \
- }
-
-logwrap(sysdie, " critical", LOG_CRIT, errno, 16);
-logwrap(die, " critical", LOG_CRIT, -1, 16);
-
-logwrap(sysfatal, " fatal", LOG_ERR, errno, 12);
-logwrap(fatal, " fatal", LOG_ERR, -1, 12);
-
-logwrap(syswarn, " warning", LOG_WARN, errno, 0);
-logwrap(warn, " warning", LOG_WARN, -1, 0);
-
-logwrap(notice, "", LOG_NOTICE, -1, 0);
-logwrap(info, " info", LOG_INFO, -1, 0);
-logwrap(debug, " debug", LOG_DEBUG, -1, 0);
-
-