#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);
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 const 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); \
}
-diewrap(sysdie, " critical", LOG_CRIT, errno, 16);
-diewrap(die, " critical", LOG_CRIT, -1, 16);
+#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 INNLOGSET_CALL(fn, pfx, sysloglevel) \
+ message_handlers_##fn(1, duct_log_##fn);
+
+
+static int innduct_fatal_cleanup(void) { return 12; } /* used for libinn die */
-diewrap(sysfatal, " fatal", LOG_ERR, errno, 12);
-diewrap(fatal, " fatal", LOG_ERR, -1, 12);
+/* We want to extend the set of logging functions from inn, and we
+ * want to prepend the site name to all our messages. */
-logwrap(syswarn, " warning", LOG_WARNING, errno);
-logwrap(warn, " warning", LOG_WARNING, -1);
+DEFFATAL(syscrash, "critical", LOG_CRIT, errno, 16);
+DEFFATAL(crash, "critical", LOG_CRIT, -1, 16);
-logwrap(notice, " notice", LOG_NOTICE, -1);
-logwrap(info, " info", LOG_INFO, -1);
-logwrap(debug, " debug", LOG_DEBUG, -1);
+#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)
+
+DEFLOG(info, "info", LOG_INFO, -1)
+DEFLOG(dbg, "debug", LOG_DEBUG, -1)
/*========== utility functions etc. ==========*/
}
static void xclose(int fd, const char *what, const char *what2) {
int r= close(fd);
- if (r) sysdie("close %s%s",what,what2?what2:"");
+ if (r) syscrash("close %s%s",what,what2?what2:"");
}
static void xclose_perhaps(int *fd, const char *what, const char *what2) {
if (*fd <= 0) return;
pid_t child;
child= fork();
- if (child==-1) sysfatal("cannot fork for %s",what);
- debug("forked %s %ld", what, (unsigned long)child);
+ if (child==-1) sysdie("cannot fork for %s",what);
+ dbg("forked %s %ld", what, (unsigned long)child);
if (!child) postfork();
return child;
}
int status;
int r= kill(*pid, SIGKILL);
- if (r) sysdie("cannot kill %s child", what);
+ if (r) syscrash("cannot kill %s child", what);
pid_t got= waitpid(*pid, &status, 0);
- if (got==-1) sysdie("cannot reap %s child", what);
- if (got==0) die("cannot reap %s child", what);
+ if (got==-1) syscrash("cannot reap %s child", what);
+ if (got==0) crash("cannot reap %s child", what);
*pid= 0;
static void xunlink(const char *path, const char *what) {
int r= unlink(path);
- if (r) sysdie("can't unlink %s %s", path, what);
+ if (r) syscrash("can't unlink %s %s", path, what);
}
static time_t xtime(void) {
time_t now= time(0);
- if (now==-1) sysdie("time(2) failed");
+ if (now==-1) syscrash("time(2) failed");
return now;
}
static void xsigaction(int signo, const struct sigaction *sa) {
int r= sigaction(signo,sa,0);
- if (r) sysdie("sigaction failed for \"%s\"", strsignal(signo));
+ if (r) syscrash("sigaction failed for \"%s\"", strsignal(signo));
}
static void xsigsetdefault(int signo) {
static void xgettimeofday(struct timeval *tv_r) {
int r= gettimeofday(tv_r,0);
- if (r) sysdie("gettimeofday(2) failed");
+ if (r) syscrash("gettimeofday(2) failed");
}
static void xsetnonblock(int fd, int nonblocking) {
int errnoval= oop_fd_nonblock(fd, nonblocking);
- if (errnoval) { errno= errnoval; sysdie("setnonblocking"); }
+ if (errnoval) { errno= errnoval; syscrash("setnonblocking"); }
}
static void check_isreg(const struct stat *stab, const char *path,
const char *what) {
if (!S_ISREG(stab->st_mode))
- die("%s %s not a plain file (mode 0%lo)",
- what, path, (unsigned long)stab->st_mode);
+ crash("%s %s not a plain file (mode 0%lo)",
+ what, path, (unsigned long)stab->st_mode);
}
static void xfstat(int fd, struct stat *stab_r, const char *what) {
int r= fstat(fd, stab_r);
- if (r) sysdie("could not fstat %s", what);
+ if (r) syscrash("could not fstat %s", what);
}
static void xfstat_isreg(int fd, struct stat *stab_r,
int r= lstat(path, stab);
if (r) {
if (errno==ENOENT && enoent_r) { *enoent_r=1; return; }
- sysdie("could not lstat %s %s", what, path);
+ syscrash("could not lstat %s %s", what, path);
}
if (enoent_r) *enoent_r= 0;
check_isreg(stab, path, what);
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;
}
}
goto x;
}
-#define CHK(field, val) \
- if (h->cmsg_##field != val) { \
- die("connect: child sent cmsg with cmsg_" #field "=%d, expected %d", \
- h->cmsg_##field, val); \
- goto x; \
+#define CHK(field, val) \
+ if (h->cmsg_##field != val) { \
+ crash("connect: child sent cmsg with cmsg_" #field "=%d, expected %d", \
+ h->cmsg_##field, val); \
+ goto x; \
}
CHK(level, SOL_SOCKET);
CHK(type, SCM_RIGHTS);
CHK(len, CMSG_LEN(sizeof(conn->fd)));
#undef CHK
- if (CMSG_NXTHDR(&msg,h)) die("connect: child sent many cmsgs");
+ if (CMSG_NXTHDR(&msg,h)) crash("connect: child sent many cmsgs");
memcpy(&conn->fd, CMSG_DATA(h), sizeof(conn->fd));
int status;
pid_t got= waitpid(connecting_child, &status, 0);
- if (got==-1) sysdie("connect: real wait for child");
+ if (got==-1) syscrash("connect: real wait for child");
assert(got == connecting_child);
connecting_child= 0;
case CONNCHILD_ESTATUS_STREAM: conn->stream= 1; break;
case CONNCHILD_ESTATUS_NOSTREAM: conn->stream= 0; break;
default:
- fatal("connect: child gave unexpected exit status %d", es);
+ die("connect: child gave unexpected exit status %d", es);
}
/* Phew! */
loop->on_fd(loop, conn->fd, OOP_EXCEPTION, conn_exception, conn);
conn->rd= oop_rd_new_fd(loop,conn->fd, 0, 0); /* sets nonblocking, too */
- if (!conn->fd) die("oop_rd_new_fd conn failed (fd=%d)",conn->fd);
+ if (!conn->fd) crash("oop_rd_new_fd conn failed (fd=%d)",conn->fd);
int r= oop_rd_read(conn->rd, &peer_rd_style, NNTP_STRLEN,
&peer_rd_ok, conn,
&peer_rd_err, conn);
- if (r) sysdie("oop_rd_read for peer (fd=%d)",conn->fd);
+ if (r) syscrash("oop_rd_read for peer (fd=%d)",conn->fd);
LIST_ADDHEAD(conns, conn);
notice("C%d (now %d) connected %s",
--l;
}
if (!buf[0]) {
- sysfatal("connect: connection attempt failed");
+ sysdie("connect: connection attempt failed");
} else {
buf[l]= 0;
- fatal("connect: %s: %s", stripped ? "rejected" : "failed",
- sanitise(buf,-1));
+ die("connect: %s: %s", stripped ? "rejected" : "failed",
+ sanitise(buf,-1));
}
}
if (NNTPsendpassword((char*)remote_host, cn_from, cn_to) < 0)
- sysfatal("connect: authentication failed");
+ sysdie("connect: authentication failed");
if (try_stream) {
if (fputs("MODE STREAM\r\n", cn_to)==EOF ||
fflush(cn_to))
- sysfatal("connect: could not send MODE STREAM");
+ sysdie("connect: could not send MODE STREAM");
buf[sizeof(buf)-1]= 0;
if (!fgets(buf, sizeof(buf)-1, cn_from)) {
if (ferror(cn_from))
- sysfatal("connect: could not read response to MODE STREAM");
+ sysdie("connect: could not read response to MODE STREAM");
else
- fatal("connect: connection close in response to MODE STREAM");
+ die("connect: connection close in response to MODE STREAM");
}
int l= strlen(buf);
assert(l>=1);
if (buf[l-1]!='\n')
- fatal("connect: response to MODE STREAM is too long: %.100s...",
- sanitise(buf,-1));
+ die("connect: response to MODE STREAM is too long: %.100s...",
+ sanitise(buf,-1));
l--; if (l>0 && buf[l-1]=='\r') l--;
buf[l]= 0;
char *ep;
int rcode= strtoul(buf,&ep,10);
if (ep != &buf[3])
- fatal("connect: bad response to MODE STREAM: %.50s", sanitise(buf,-1));
+ die("connect: bad response to MODE STREAM: %.50s", sanitise(buf,-1));
switch (rcode) {
case 203:
msg.msg_controllen= cmsg->cmsg_len;
r= sendmsg(socks[1], &msg, 0);
- if (r<0) sysdie("sendmsg failed for new connection");
- if (r!=1) die("sendmsg for new connection gave wrong result %d",r);
+ if (r<0) syscrash("sendmsg failed for new connection");
+ if (r!=1) crash("sendmsg for new connection gave wrong result %d",r);
_exit(exitstatus);
}
open_defer();
if (fprintf(defer, "%s %s\n", TokenToText(art->token), art->messageid) <0
|| fflush(defer))
- sysfatal("write to defer file %s",path_defer);
+ sysdie("write to defer file %s",path_defer);
article_done(art, whichcount);
}
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;
}
int r= pwrite(ipf->fd, spaces, w, art->offset);
if (r==-1) {
if (errno==EINTR) continue;
- sysdie("failed to blank entry for %s (length %d at offset %lu) in %s",
- art->messageid, art->blanklen,
- (unsigned long)art->offset, ipf->path);
+ syscrash("failed to blank entry for %s (length %d at offset %lu) in %s",
+ art->messageid, art->blanklen,
+ (unsigned long)art->offset, ipf->path);
}
assert(r>=0 && r<=w);
art->blanklen -= w;
int fd= open(path, O_RDWR);
if (fd<0) {
if (errno==ENOENT) return 0;
- sysfatal("unable to open input file %s", path);
+ sysdie("unable to open input file %s", path);
}
assert(fd>0);
ipf->readcount_err++;
if (ipf->readcount_err > max_bad_data_initial +
(ipf->readcount_ok+ipf->readcount_blank) / max_bad_data_ratio)
- die("too much garbage in input file! (%d errs, %d ok, %d blank)",
- ipf->readcount_err, ipf->readcount_ok, ipf->readcount_blank);
+ crash("too much garbage in input file! (%d errs, %d ok, %d blank)",
+ ipf->readcount_err, ipf->readcount_ok, ipf->readcount_blank);
return OOP_CONTINUE;
}
InputFile *ipf= ipf_v;
assert(ev == OOP_RD_SYSTEM);
errno= errnoval;
- sysdie("error reading input file: %s, offset %lu",
- ipf->path, (unsigned long)ipf->offset);
+ syscrash("error reading input file: %s, offset %lu",
+ ipf->path, (unsigned long)ipf->offset);
}
static void *feedfile_got_article(oop_source *lp, oop_read *rd,
art->offset= old_offset;
art->blanklen= recsz;
strcpy(art->messageid, space+1);
- LIST_ADDTAIL(ipf->queue, art);
- if (ipf->autodefer >= 0)
+ if (ipf->autodefer >= 0) {
article_autodefer(ipf, art);
- else if (ipf==backlog_input_file)
- article_check_expired(art);
+ } else {
+ LIST_ADDTAIL(ipf->queue, art);
+
+ if (ipf==backlog_input_file)
+ article_check_expired(art);
+ }
if (sms==sm_NORMAL && ipf==main_input_file &&
ipf->offset >= target_max_feedfile_size)
static void filemon_method_startfile(InputFile *ipf, Filemon_Perfile *pf) {
int wd= inotify_add_watch(filemon_inotify_fd, ipf->path, IN_MODIFY);
- if (wd < 0) sysfatal("inotify_add_watch %s", ipf->path);
+ if (wd < 0) sysdie("inotify_add_watch %s", ipf->path);
if (wd >= filemon_inotify_wdmax) {
int newmax= wd+2;
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) sysdie("inotify_rm_watch");
+ if (r) syscrash("inotify_rm_watch");
filemon_inotify_wd2ipf[wd]= 0;
}
int r= read(filemon_inotify_fd, &iev, sizeof(iev));
if (r==-1) {
if (isewouldblock(errno)) break;
- sysdie("read from inotify master");
+ syscrash("read from inotify master");
} else if (r==sizeof(iev)) {
assert(iev.wd >= 0 && iev.wd < filemon_inotify_wdmax);
} else {
- die("inotify read %d bytes wanted struct of %d", r, (int)sizeof(iev));
+ 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;
xsetnonblock(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;
}
int r= oop_rd_read(ipf->rd, &feedfile_rdstyle, MAX_LINE_FEEDFILE,
feedfile_got_article,ipf, feedfile_read_err, ipf);
- if (r) sysdie("unable start reading feedfile %s",ipf->path);
+ if (r) syscrash("unable start reading feedfile %s",ipf->path);
ipf->paused= 0;
}
for (;;) {
lockfd= open(path_lock, O_CREAT|O_RDWR, 0600);
- if (lockfd<0) sysfatal("open lockfile %s", path_lock);
+ if (lockfd<0) sysdie("open lockfile %s", path_lock);
struct flock fl;
memset(&fl,0,sizeof(fl));
if (r==-1) {
if (errno==EACCES || isewouldblock(errno)) {
if (quiet_multiple) exit(0);
- fatal("another duct holds the lockfile");
+ die("another duct holds the lockfile");
}
- sysfatal("fcntl F_SETLK lockfile %s", path_lock);
+ sysdie("fcntl F_SETLK lockfile %s", path_lock);
}
xfstat_isreg(lockfd, &stabf, path_lock, "lockfile");
}
FILE *lockfile= fdopen(lockfd, "w");
- if (!lockfile) sysdie("fdopen lockfile");
+ if (!lockfile) syscrash("fdopen lockfile");
int r= ftruncate(lockfd, 0);
- if (r) sysdie("truncate lockfile to write new info");
+ if (r) syscrash("truncate lockfile to write new info");
if (fprintf(lockfile, "pid %ld\nsite %s\nfeedfile %s\nfqdn %s\n",
(unsigned long)self_pid,
sitename, feedfile, remote_host) == EOF ||
fflush(lockfile))
- sysfatal("write info to lockfile %s", path_lock);
+ sysdie("write info to lockfile %s", path_lock);
- debug("startup: locked");
+ dbg("startup: locked");
}
static void statemc_init(void) {
int defer_noent;
xlstat_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 */
" (presumably hardlink to backlog file)");
break;
default:
- die("defer file %s has unexpected link count %d",
- path_defer, stabdefer.st_nlink);
+ crash("defer file %s has unexpected link count %d",
+ path_defer, stabdefer.st_nlink);
}
}
xlstat_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");
xunlink(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);
- if (!main_input_file) die("feedfile vanished during startup");
+ if (!main_input_file) crash("feedfile vanished during startup");
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) die("feed file vanished during startup");
+ if (!file_f) crash("feed file vanished during startup");
startup_set_input_file(file_f);
SMS(NORMAL, spontaneous_flush_periods, "normal startup");
}
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,
until_flush);
int r= link(feedfile, path_flushing);
- if (r) sysfatal("link feedfile %s to flushing file %s",
- feedfile, path_flushing);
+ if (r) sysdie("link feedfile %s to flushing file %s",
+ feedfile, path_flushing);
/* => Hardlinked */
xunlink(feedfile, "old feedfile link");
close_input_file(ipf);
if (unlink(ipf->path)) {
if (errno != ENOENT)
- sysdie("could not unlink processed backlog file %s", ipf->path);
+ syscrash("could not unlink processed backlog file %s", ipf->path);
warn("backlog file %s vanished while we were reading it"
" so we couldn't remove it (but it's done now, anyway)",
ipf->path);
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;
if (defer) return;
defer= fopen(path_defer, "a+");
- if (!defer) sysfatal("could not open defer file %s", path_defer);
+ if (!defer) sysdie("could not open defer file %s", path_defer);
/* truncate away any half-written records */
xfstat_isreg(fileno(defer), &stab, path_defer, "newly opened defer file");
if (stab.st_size > LONG_MAX)
- die("defer file %s size is far too large", path_defer);
+ crash("defer file %s size is far too large", path_defer);
if (!stab.st_size)
return;
for (;;) {
if (!truncto) break; /* was only (if anything) one half-truncated record */
if (fseek(defer, truncto-1, SEEK_SET) < 0)
- sysdie("seek in defer file %s while truncating partial", path_defer);
+ syscrash("seek in defer file %s while truncating partial", path_defer);
int r= getc(defer);
if (r==EOF) {
if (ferror(defer))
- sysdie("failed read from defer file %s", path_defer);
+ syscrash("failed read from defer file %s", path_defer);
else
- die("defer file %s shrank while we were checking it!", path_defer);
+ crash("defer file %s shrank while we were checking it!", path_defer);
}
if (r=='\n') break;
truncto--;
path_defer, orgsize - truncto, orgsize, truncto);
if (fflush(defer))
- sysfatal("could not flush defer file %s", path_defer);
+ sysdie("could not flush defer file %s", path_defer);
if (ftruncate(fileno(defer), truncto))
- sysdie("could not truncate defer file %s", path_defer);
+ syscrash("could not truncate defer file %s", path_defer);
} else {
info("continuing existing defer file %s (%ld bytes)",
path_defer, orgsize);
}
if (fseek(defer, truncto, SEEK_SET))
- sysdie("could not seek to new end of defer file %s", path_defer);
+ syscrash("could not seek to new end of defer file %s", path_defer);
}
static void close_defer(void) {
struct stat stab;
xfstat_isreg(fileno(defer), &stab, path_defer, "defer file");
- if (fclose(defer)) sysfatal("could not close defer file %s", path_defer);
+ if (fclose(defer)) sysdie("could not close defer file %s", path_defer);
defer= 0;
time_t now= xtime();
(unsigned long)now,
(unsigned long)stab.st_ino);
if (link(path_defer, backlog))
- sysfatal("could not install defer file %s as backlog file %s",
+ sysdie("could not install defer file %s as backlog file %s",
path_defer, backlog);
if (unlink(path_defer))
- sysdie("could not unlink old defer link %s to backlog file %s",
- path_defer, backlog);
+ syscrash("could not unlink old defer link %s to backlog file %s",
+ path_defer, backlog);
free(backlog);
switch (r) {
case GLOB_ABORTED:
- sysfatal("failed to expand backlog pattern %s", globpat_backlog);
+ sysdie("failed to expand backlog pattern %s", globpat_backlog);
case GLOB_NOSPACE:
- fatal("out of memory expanding backlog pattern %s", globpat_backlog);
+ die("out of memory expanding backlog pattern %s", globpat_backlog);
case 0:
for (i=0; i<gl.gl_pathc; i++) {
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);
case GLOB_NOMATCH: /* fall through */
break;
default:
- sysdie("glob expansion of backlog pattern %s gave unexpected"
- " nonzero (error?) return value %d", globpat_backlog, r);
+ syscrash("glob expansion of backlog pattern %s gave unexpected"
+ " nonzero (error?) return value %d", globpat_backlog, r);
}
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:
assert(fd=signal_self_pipe[0]);
char buf[PIPE_BUF];
int r= read(signal_self_pipe[0], buf, sizeof(buf));
- if (r<0 && !isewouldblock(errno)) sysdie("failed to read signal self pipe");
- if (r==0) die("eof on signal self pipe");
+ if (r<0 && !isewouldblock(errno))
+ syscrash("failed to read signal self pipe");
+ if (r==0) crash("eof on signal self pipe");
if (terminate_sig_flag) {
preterminate();
notice("terminating (%s)", strsignal(terminate_sig_flag));
static void init_signals(void) {
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
- sysdie("could not ignore SIGPIPE");
+ syscrash("could not ignore SIGPIPE");
- if (pipe(signal_self_pipe)) sysfatal("create self-pipe for signals");
+ if (pipe(signal_self_pipe)) sysdie("create self-pipe for signals");
xsetnonblock(signal_self_pipe[0],1);
xsetnonblock(signal_self_pipe[1],1);
main_input_file= open_input_file(feedfile);
if (!main_input_file)
- die("flush succeeded but feedfile %s does not exist!"
- " (this probably means feedfile does not correspond"
- " to site %s in newsfeeds)", feedfile, sitename);
+ crash("flush succeeded but feedfile %s does not exist!"
+ " (this probably means feedfile does not correspond"
+ " to site %s in newsfeeds)", feedfile, sitename);
if (flushing_input_file) {
SMS(SEPARATED, max_separated_periods, "flush complete");
assert(!inndcomm_child);
assert(!inndcomm_sentinel_fd);
- if (pipe(pipefds)) sysfatal("create pipe for inndcomm child sentinel");
+ if (pipe(pipefds)) sysdie("create pipe for inndcomm child sentinel");
inndcomm_child= xfork("inndcomm child");
static void postfork_stdio(FILE *f, const char *what, const char *what2) {
/* we have no stdio streams that are buffered long-term */
if (!f) return;
- if (fclose(f)) sysdie("(in child) close %s%s", what, what2?what2:0);
+ if (fclose(f)) syscrash("(in child) close %s%s", what, what2?what2:0);
}
static void postfork(void) {
tailing_make_readable(flushing_input_file);
}
-static char *debug_report_ipf(InputFile *ipf) {
+static char *dbg_report_ipf(InputFile *ipf) {
if (!ipf) return xasprintf("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_CRIT,"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 */
+ message_program_name= "innduct";
+ message_fatal_cleanup= innduct_fatal_cleanup;
+ INNLOGSETS(INNLOGSET_CALL)
+
if (!argv[1]) {
printusage(stderr);
exit(8);
/* defaults */
int r= innconf_read(inndconffile);
- if (!r) badusage("could not read inn.conf (more info on stderr)");
+ if (!r) badusage("could not read inn.conf");
if (!remote_host) remote_host= sitename;
globpat_backlog= xasprintf("%s_backlog*", feedfile);
oop_source_sys *sysloop= oop_sys_new();
- if (!sysloop) sysdie("could not create liboop event loop");
+ if (!sysloop) syscrash("could not create liboop event loop");
loop= (oop_source*)sysloop;
LIST_INIT(conns);
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);
- if (null<0) sysfatal("failed to open /dev/null");
+ if (null<0) sysdie("failed to open /dev/null");
dup2(null,0);
dup2(null,1);
dup2(null,2);
if (child1) _exit(0);
pid_t sid= setsid();
- if (sid == -1) sysfatal("setsid failed");
+ if (sid == -1) sysdie("setsid failed");
pid_t child2= xfork("daemonise second fork");
if (child2) _exit(0);
}
self_pid= getpid();
- if (self_pid==-1) sysdie("getpid");
+ if (self_pid==-1) syscrash("getpid");
r= chdir(path_run);
if (r) sysdie("could not chdir to pathrun %s", path_run);
void *run= oop_sys_run(sysloop);
assert(run == OOP_ERROR);
- sysdie("event loop failed");
+ syscrash("event loop failed");
}