#include "inn/list.h"
#include "inn/innconf.h"
+#include "inn/messages.h"
#include <sys/uio.h>
#include <sys/types.h>
static void search_backlog_file(void);
static void preterminate(void);
static void raise_default(int signo) NORET;
-static char *debug_report_ipf(InputFile *ipf);
static void inputfile_reading_start(InputFile *ipf);
static void inputfile_reading_stop(InputFile *ipf);
errnoval>=0 ? strerror(errnoval) : "");
}
-#define diewrap(fn, pfx, sysloglevel, err, estatus) \
+#define DIEWRAP(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 LOGWRAP(fn, pfx, sysloglevel, err) \
static void fn(const char *fmt, ...) PRINTF(1,2); \
static void fn(const char *fmt, ...) { \
VA; \
#define INNLOGWRAP_DECLARE(fn, pfx, sysloglevel) \
static void duct_log_##fn(int errval, const char *fmt, va_list al, int l) { \
- logv(sysloglevel, pfx, errnoval ? errnoval : -1, fmt, al); \
+ logv(sysloglevel, pfx, errval ? errval : -1, fmt, al); \
}
#define INNLOGWRAP_CALL(fn, pfx, sysloglevel) \
- fn##_set_handlers(1, duct_log_##fn);
+ message_handlers_##fn(1, duct_log_##fn);
static int innduct_fatal_cleanup(void) { return 12; } /* used for libinn die */
/* 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);
+DIEWRAP(syscrash, " critical", LOG_CRIT, errno, 16);
+DIEWRAP(crash, " critical", LOG_CRIT, -1, 16);
-diewrap(sysfatal, " fatal", LOG_ERR, errno, 12);
-diewrap(fatal, " fatal", LOG_ERR, -1, 12);
+DIEWRAP(sysfatal, " fatal", LOG_ERR, errno, 12);
+DIEWRAP(fatal, " fatal", LOG_ERR, -1, 12);
-#define INNLOGWRAPS \
- INNLOGWRAP(warn, " warning", LOG_WARNING, errno) \
- INNLOGWRAP(notice, " notice", LOG_NOTICE, -1)
+#define INNLOGWRAPS(INNLOGWRAP) \
+ INNLOGWRAP(warn, " warning", LOG_WARNING) \
+ INNLOGWRAP(notice, " notice", LOG_NOTICE)
INNLOGWRAPS(INNLOGWRAP_DECLARE)
-logwrap(info, " info", LOG_INFO, -1);
-logwrap(debug, " debug", LOG_DEBUG, -1);
+LOGWRAP(info, " info", LOG_INFO, -1)
+LOGWRAP(dbg, " debug", LOG_DEBUG, -1)
/*========== utility functions etc. ==========*/
child= fork();
if (child==-1) sysfatal("cannot fork for %s",what);
- debug("forked %s %ld", what, (unsigned long)child);
+ dbg("forked %s %ld", what, (unsigned long)child);
if (!child) postfork();
return child;
}
if (!todo) {
conn->quitting= why;
conn->since_activity= 0;
- debug("C%d is idle (%s), quitting", conn->fd, why);
+ dbg("C%d is idle (%s), quitting", conn->fd, why);
break;
}
}
notice("entering nocheck mode for the first time");
nocheck_reported= 1;
} else if (new_nocheck != nocheck) {
- debug("nocheck mode %s", new_nocheck ? "start" : "stop");
+ dbg("nocheck mode %s", new_nocheck ? "start" : "stop");
}
nocheck= new_nocheck;
}
assert(!filemon_inotify_wd2ipf[wd]);
filemon_inotify_wd2ipf[wd]= ipf;
- debug("filemon inotify startfile %p wd=%d wdmax=%d",
- ipf, wd, filemon_inotify_wdmax);
+ dbg("filemon inotify startfile %p wd=%d wdmax=%d",
+ ipf, wd, filemon_inotify_wdmax);
pf->wd= wd;
}
static void filemon_method_stopfile(InputFile *ipf, Filemon_Perfile *pf) {
int wd= pf->wd;
- debug("filemon inotify stopfile %p wd=%d", ipf, wd);
+ dbg("filemon inotify stopfile %p wd=%d", ipf, wd);
int r= inotify_rm_watch(filemon_inotify_fd, wd);
if (r) syscrash("inotify_rm_watch");
filemon_inotify_wd2ipf[wd]= 0;
crash("inotify read %d bytes wanted struct of %d", r, (int)sizeof(iev));
}
InputFile *ipf= filemon_inotify_wd2ipf[iev.wd];
- /*debug("filemon inotify readable read %p wd=%d", ipf, iev.wd);*/
+ /*dbg("filemon inotify readable read %p wd=%d", ipf, iev.wd);*/
tailing_make_readable(ipf);
}
return OOP_CONTINUE;
msetnonblock(filemon_inotify_fd, 1);
loop->on_fd(loop, filemon_inotify_fd, OOP_READ, filemon_inotify_readable, 0);
- debug("filemon inotify init filemon_inotify_fd=%d", filemon_inotify_fd);
+ dbg("filemon inotify init filemon_inotify_fd=%d", filemon_inotify_fd);
return 1;
}
fflush(lockfile))
sysfatal("write info to lockfile %s", path_lock);
- debug("startup: locked");
+ dbg("startup: locked");
}
static void statemc_init(void) {
int defer_noent;
mlstat_isreg(path_defer, &stabdefer, &defer_noent, "defer file");
if (defer_noent) {
- debug("startup: ductdefer ENOENT");
+ dbg("startup: ductdefer ENOENT");
} else {
- debug("startup: ductdefer nlink=%ld", (long)stabdefer.st_nlink);
+ dbg("startup: ductdefer nlink=%ld", (long)stabdefer.st_nlink);
switch (stabdefer.st_nlink==1) {
case 1:
open_defer(); /* so that we will later close it and rename it */
mlstat_isreg(feedfile, &stab_f, &noent_f, "feedfile");
if (!noent_f && file_d && samefile(&stab_f, &stab_d)) {
- debug("startup: F==D => Hardlinked");
+ dbg("startup: F==D => Hardlinked");
munlink(feedfile, "feed file (during startup)"); /* => Moved */
noent_f= 1;
}
if (noent_f) {
- debug("startup: F ENOENT => Moved");
+ dbg("startup: F ENOENT => Moved");
if (file_d) startup_set_input_file(file_d);
spawn_inndcomm_flush("feedfile missing at startup");
/* => Flushing, sms:=FLUSHING */
} else {
if (file_d) {
- debug("startup: F!=D => Separated");
+ dbg("startup: F!=D => Separated");
startup_set_input_file(file_d);
flushing_input_file= main_input_file;
main_input_file= open_input_file(feedfile);
SMS(SEPARATED, max_separated_periods,
"found both old and current feed files");
} else {
- debug("startup: F exists, D ENOENT => Normal");
+ dbg("startup: F exists, D ENOENT => Normal");
InputFile *file_f= open_input_file(feedfile);
if (!file_f) crash("feed file vanished during startup");
startup_set_input_file(file_f);
static void statemc_start_flush(const char *why) { /* Normal => Flushing */
assert(sms == sm_NORMAL);
- debug("starting flush (%s) (%lu >?= %lu) (%d)",
+ dbg("starting flush (%s) (%lu >?= %lu) (%d)",
why,
(unsigned long)(main_input_file ? main_input_file->offset : 0),
(unsigned long)target_max_feedfile_size,
const char *path= gl.gl_pathv[i];
if (strchr(path,'#') || strchr(path,'~')) {
- debug("backlog file search skipping %s", path);
+ dbg("backlog file search skipping %s", path);
continue;
}
r= stat(path, &stab);
}
if (!oldest_path) {
- debug("backlog scan: none");
+ dbg("backlog scan: none");
if (sms==sm_DROPPED) {
preterminate();
long age_deficiency= (backlog_retry_minperiods * period_seconds) - age;
if (age_deficiency <= 0) {
- debug("backlog scan: found age=%f deficiency=%ld oldest=%s",
+ dbg("backlog scan: found age=%f deficiency=%ld oldest=%s",
age, age_deficiency, oldest_path);
backlog_input_file= open_input_file(oldest_path);
until_backlog_nextscan > backlog_spontrescan_periods)
until_backlog_nextscan= backlog_spontrescan_periods;
- debug("backlog scan: young age=%f deficiency=%ld nextscan=%d oldest=%s",
+ dbg("backlog scan: young age=%f deficiency=%ld nextscan=%d oldest=%s",
age, age_deficiency, until_backlog_nextscan, oldest_path);
xfree:
tailing_make_readable(flushing_input_file);
}
-static char *debug_report_ipf(InputFile *ipf) {
+static char *dbg_report_ipf(InputFile *ipf) {
if (!ipf) return masprintf("none");
const char *slash= strrchr(ipf->path,'/');
}
static void period(void) {
- char *dipf_main= debug_report_ipf(main_input_file);
- char *dipf_flushing= debug_report_ipf(flushing_input_file);
- char *dipf_backlog= debug_report_ipf(backlog_input_file);
-
- debug("PERIOD"
- " sms=%s[%d] conns=%d until_connect=%d"
- " input_files main:%s flushing:%s backlog:%s[%d]"
- " children connecting=%ld inndcomm=%ld lowvol_total=%d"
- ,
- sms_names[sms], until_flush, conns.count, until_connect,
- dipf_main, dipf_flushing, dipf_backlog, until_backlog_nextscan,
- (long)connecting_child, (long)inndcomm_child, lowvol_total
- );
+ char *dipf_main= dbg_report_ipf(main_input_file);
+ char *dipf_flushing= dbg_report_ipf(flushing_input_file);
+ char *dipf_backlog= dbg_report_ipf(backlog_input_file);
+
+ dbg("PERIOD"
+ " sms=%s[%d] conns=%d until_connect=%d"
+ " input_files main:%s flushing:%s backlog:%s[%d]"
+ " children connecting=%ld inndcomm=%ld lowvol_total=%d"
+ ,
+ sms_names[sms], until_flush, conns.count, until_connect,
+ dipf_main, dipf_flushing, dipf_backlog, until_backlog_nextscan,
+ (long)connecting_child, (long)inndcomm_child, lowvol_total
+ );
free(dipf_main);
free(dipf_flushing);
static void dump_input_file(FILE *f, const CliCommand *c,
InputFile *ipf, const char *wh) {
- char *dipf= debug_report_ipf(ipf);
+ char *dipf= dbg_report_ipf(ipf);
fprintf(f,"input %s %s", wh, dipf);
free(dipf);
"say --help for help, or read the manpage\n",
m);
if (interactive < 2)
- syslog(LOG_CRASH,"innduct: invoked with bad usage: %s",m);
+ syslog(LOG_ERR,"innduct: invoked with bad usage: %s",m);
exit(8);
}
int main(int argc, char **argv) {
/* set up libinn logging */
- error_program_name= "innduct";
+ message_program_name= "innduct";
message_fatal_cleanup= innduct_fatal_cleanup;
INNLOGWRAPS(INNLOGWRAP_CALL)