static double accept_proportion;
static int nocheck, nocheck_reported, in_child;
-/* for simulation, debugging, etc. */
+/* for logging, simulation, debugging, etc. */
int simulate_flush= -1;
+int logv_use_syslog;
+static char *logv_prefix="";
/*========== logging ==========*/
static void logcore(int sysloglevel, const char *fmt, ...) PRINTF(2,3);
static void logcore(int sysloglevel, const char *fmt, ...) {
VA;
- if (interactive < 2) {
+ if (logv_use_syslog) {
vsyslog(sysloglevel,fmt,al);
} else {
if (self_pid) fprintf(stderr,"[%lu] ",(unsigned long)self_pid);
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) : "");
+ logcore(sysloglevel, "%s%s: %s%s%s",
+ logv_prefix, pfx, msgbuf,
+ errnoval>=0 ? ": " : "",
+ errnoval>=0 ? strerror(errnoval) : "");
}
-#define DIEWRAP(fn, pfx, sysloglevel, err, estatus) \
+#define DEFFATAL(fn, pfx, sysloglevel, err, estatus) \
static void fn(const char *fmt, ...) NORET_PRINTF(1,2); \
static void fn(const char *fmt, ...) { \
preterminate(); \
exit(estatus); \
}
-#define LOGWRAP(fn, pfx, sysloglevel, err) \
+#define DEFLOG(fn, pfx, sysloglevel, err) \
static void fn(const char *fmt, ...) PRINTF(1,2); \
static void fn(const char *fmt, ...) { \
VA; \
va_end(al); \
}
-#define INNLOGWRAP_DECLARE(fn, pfx, sysloglevel) \
- static void duct_log_##fn(int errval, const char *fmt, va_list al, int l) { \
+#define INNLOGSET_DECLARE(fn, pfx, sysloglevel) \
+ static void duct_log_##fn(int l, const char *fmt, va_list al, int errval) { \
logv(sysloglevel, pfx, errval ? errval : -1, fmt, al); \
}
-#define INNLOGWRAP_CALL(fn, pfx, sysloglevel) \
+#define INNLOGSET_CALL(fn, pfx, sysloglevel) \
message_handlers_##fn(1, duct_log_##fn);
/* We want to extend the set of logging functions from inn, and we
* want to prepend the site name to all our messages. */
-DIEWRAP(syscrash, " critical", LOG_CRIT, errno, 16);
-DIEWRAP(crash, " critical", LOG_CRIT, -1, 16);
+DEFFATAL(syscrash, "critical", LOG_CRIT, errno, 16);
+DEFFATAL(crash, "critical", LOG_CRIT, -1, 16);
-#define INNLOGWRAPS(INNLOGWRAP) \
- INNLOGWRAP(die, " fatal", LOG_ERR) \
- INNLOGWRAP(warn, " warning", LOG_WARNING) \
- INNLOGWRAP(notice, " notice", LOG_NOTICE)
-INNLOGWRAPS(INNLOGWRAP_DECLARE)
+#define INNLOGSETS(INNLOGSET) \
+ INNLOGSET(die, "fatal", LOG_ERR) \
+ INNLOGSET(warn, "warning", LOG_WARNING) \
+ INNLOGSET(notice, "notice", LOG_NOTICE) \
+ INNLOGSET(trace, "trace", LOG_NOTICE)
+INNLOGSETS(INNLOGSET_DECLARE)
-LOGWRAP(info, " info", LOG_INFO, -1)
-LOGWRAP(dbg, " debug", LOG_DEBUG, -1)
+DEFLOG(info, "info", LOG_INFO, -1)
+DEFLOG(dbg, "debug", LOG_DEBUG, -1)
/*========== utility functions etc. ==========*/
static void *statemc_check_input_done(oop_source *lp, struct timeval now,
void *u) {
- assert(!inputfile_is_done(main_input_file));
+ /* main input file may be idle but if so that's because
+ * we haven't got to it yet, but that doesn't mean it's really done */
statemc_check_flushing_done();
statemc_check_backlog_done();
return OOP_CONTINUE;
/* set up libinn logging */
message_program_name= "innduct";
message_fatal_cleanup= innduct_fatal_cleanup;
- INNLOGWRAPS(INNLOGWRAP_CALL)
+ INNLOGSETS(INNLOGSET_CALL)
if (!argv[1]) {
printusage(stderr);
close(i);
}
- if (interactive < 2)
+ logv_prefix= xasprintf("<%s> ", sitename);
+ if (interactive < 2) {
openlog("innduct",LOG_NDELAY|LOG_PID,LOG_NEWS);
+ logv_use_syslog= 1;
+ }
if (interactive < 1) {
int null= open("/dev/null",O_RDWR);