/*
* TODO
- * - actually implement badusage
- * - options for all options
- * - manpage
* - pid, sitename, hostname in lockfile
- * - -k kill mode ?
*/
/*
/*----- general definitions, probably best not changed -----*/
-#define CONNCHILD_ESTATUS_STREAM 4
-#define CONNCHILD_ESTATUS_NOSTREAM 5
+#define CONNCHILD_ESTATUS_STREAM 24
+#define CONNCHILD_ESTATUS_NOSTREAM 25
-#define INNDCOMMCHILD_ESTATUS_FAIL 6
-#define INNDCOMMCHILD_ESTATUS_NONESUCH 7
+#define INNDCOMMCHILD_ESTATUS_FAIL 26
+#define INNDCOMMCHILD_ESTATUS_NONESUCH 27
#define MAX_LINE_FEEDFILE (NNTP_MSGID_MAXLEN + sizeof(TOKEN)*2 + 10)
static oop_rd_call peer_rd_err, peer_rd_ok;
/*----- configuration options -----*/
+/* when changing defaults, remember to update the manpage */
static const char *sitename, *remote_host;
static const char *feedfile;
pid_t child;
child= fork();
- if (child==-1) sysdie("cannot fork for %s",what);
+ if (child==-1) sysfatal("cannot fork for %s",what);
debug("forked %s %ld", what, (unsigned long)child);
if (!child) postfork();
return child;
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) sysdie("inotify_add_watch %s", ipf->path);
+ if (wd < 0) sysfatal("inotify_add_watch %s", ipf->path);
if (wd >= filemon_inotify_wdmax) {
int newmax= wd+2;
path_defer= xasprintf("%s_defer", feedfile);
globpat_backlog= xasprintf("%s_backlog*", feedfile);
+ int lockfd;
+
for (;;) {
- int lockfd= open(path_lock, O_CREAT|O_RDWR, 0600);
+ lockfd= open(path_lock, O_CREAT|O_RDWR, 0600);
if (lockfd<0) sysfatal("open lockfile %s", path_lock);
struct flock fl;
if (quiet_multiple) exit(0);
fatal("another duct holds the lockfile");
}
- sysdie("fcntl F_SETLK lockfile %s", path_lock);
+ sysfatal("fcntl F_SETLK lockfile %s", path_lock);
}
xfstat_isreg(lockfd, &stabf, path_lock, "lockfile");
xclose(lockfd, "stale lockfile ", path_lock);
}
+ pid_t self= getpid();
+ if (self==-1) sysdie("getpid");
+
+ FILE *lockfile= fdopen(lockfd, "w");
+ if (!lockfile) sysdie("fdopen lockfile");
+
+ int r= ftruncate(lockfd, 0);
+ if (r) sysdie("truncate lockfile to write new info");
+
+ if (fprintf(lockfile, "pid %ld\nsite %s\nfeedfile %s\nfqdn %s\n",
+ (unsigned long)self, sitename, feedfile, remote_host) == EOF ||
+ fflush(lockfile))
+ sysfatal("write info to lockfile %s", path_lock);
+
debug("startup: locked");
search_backlog_file();
sm_period_counter);
int r= link(feedfile, path_flushing);
- if (r) sysdie("link feedfile %s to flushing file %s",
- feedfile, path_flushing);
+ if (r) sysfatal("link feedfile %s to flushing file %s",
+ feedfile, path_flushing);
/* => Hardlinked */
xunlink(feedfile, "old feedfile link");
switch (r) {
case GLOB_ABORTED:
- sysdie("failed to expand backlog pattern %s", globpat_backlog);
+ sysfatal("failed to expand backlog pattern %s", globpat_backlog);
case GLOB_NOSPACE:
- die("out of memory expanding backlog pattern %s", globpat_backlog);
+ fatal("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 (sms==sm_DROPPED) {
notice("feed dropped and our work is complete");
xunlink(path_lock, "lockfile for old feed");
- exit(0);
+ exit(4);
}
until_backlog_nextscan= backlog_spontrescan_periods;
goto xfree;
assert(!inndcomm_child);
assert(!inndcomm_sentinel_fd);
- if (pipe(pipefds)) sysdie("create pipe for inndcomm child sentinel");
+ if (pipe(pipefds)) sysfatal("create pipe for inndcomm child sentinel");
inndcomm_child= xfork("inndcomm child");
double v= strtod(val,&ep);
if (ep==val) badusage("bad time/duration value for %s",o->lng);
- if (!*ep || !strcmp(ep,"s")) unit= 1;
- else if (!strcmp(ep,"m")) unit= 60;
- else if (!strcmp(ep,"h")) unit= 3600;
- else if (!strcmp(ep,"d")) unit= 86400;
+ if (!*ep || !strcmp(ep,"s") || !strcmp(ep,"sec")) unit= 1;
+ else if (!strcmp(ep,"m") || !strcmp(ep,"min")) unit= 60;
+ else if (!strcmp(ep,"h") || !strcmp(ep,"hour")) unit= 3600;
+ else if (!strcmp(ep,"d") || !strcmp(ep,"day")) unit= 86400;
+ else if (!strcmp(ep,"das")) unit= 10;
+ else if (!strcmp(ep,"hs")) unit= 100;
+ else if (!strcmp(ep,"ks")) unit= 1000;
+ else if (!strcmp(ep,"Ms")) unit= 1000000;
else badusage("bad units %s for time/duration value for %s",ep,o->lng);
v *= unit;
int main(int argc, char **argv) {
if (!argv[1]) {
printusage(stderr);
- exit(12);
+ exit(8);
}
parse_options(innduct_options, &argv);
if (nocheck_decay < 0.1)
badusage("nocheck decay articles must be at least 0.1");
- nocheck_decay= 1 - 1.0/nocheck_decay;
+ nocheck_decay= pow(0.5, 1.0/nocheck_decay);
convert_to_periods_rndup(&reconnect_delay_periods);
convert_to_periods_rndup(&flushfail_retry_periods);
openlog("innduct",LOG_NDELAY|LOG_PID,LOG_NEWS);
int null= open("/dev/null",O_RDWR);
- if (null<0) sysdie("failed to open /dev/null");
+ if (null<0) sysfatal("failed to open /dev/null");
dup2(null,0);
dup2(null,1);
dup2(null,2);
if (child1) _exit(0);
pid_t sid= setsid();
- if (sid != child1) sysdie("setsid failed");
+ if (sid != child1) sysfatal("setsid failed");
pid_t child2= xfork("daemonise second fork");
if (child2) _exit(0);