chiark / gitweb /
it compiles and links
authorIan Jackson <ian@liberator.(none)>
Tue, 27 Apr 2010 10:54:01 +0000 (11:54 +0100)
committerIan Jackson <ian@liberator.(none)>
Tue, 27 Apr 2010 10:54:01 +0000 (11:54 +0100)
backends/Makefile
backends/innduct.c

index 2e3956c5ee86b477366c3c7e86458e70ecd75b4d..e6365d3437c25b3d3cfc4743d9a9e2c6cc7c5eb8 100644 (file)
@@ -77,7 +77,7 @@ nntpget:      nntpget.o    $(BOTH)    ; $(LINK) nntpget.o    $(STORELIBS)
 overchan:      overchan.o   $(BOTH)    ; $(LINK) overchan.o   $(STORELIBS)
 shlock:                shlock.o     $(LIBINN)  ; $(LINK) shlock.o     $(INNLIBS)
 shrinkfile:    shrinkfile.o $(LIBINN)  ; $(LINK) shrinkfile.o $(INNLIBS)
 overchan:      overchan.o   $(BOTH)    ; $(LINK) overchan.o   $(STORELIBS)
 shlock:                shlock.o     $(LIBINN)  ; $(LINK) shlock.o     $(INNLIBS)
 shrinkfile:    shrinkfile.o $(LIBINN)  ; $(LINK) shrinkfile.o $(INNLIBS)
-innduct:       innduct.o    $(LIBINN)  ; $(LINK) innduct.o    $(INNLIBS)
+innduct:       innduct.o    $(BOTH)    ; $(LINK) innduct.o $(STORELIBS) -loop
 
 buffchan:      buffchan.o map.o $(LIBINN)
        $(LINK) buffchan.o map.o $(LIBINN) $(LIBS)
 
 buffchan:      buffchan.o map.o $(LIBINN)
        $(LINK) buffchan.o map.o $(LIBINN) $(LIBS)
index 60cfea6625e5d4c5e226ec53c695854b9369bc90..58d2870de5b8bed162d49e161635e384584f8834 100644 (file)
@@ -3,6 +3,9 @@
  *  - close idle connections
  *  - cope better with garbage in feed file
  *  - cope better with NULs in feed file
  *  - close idle connections
  *  - cope better with garbage in feed file
  *  - cope better with NULs in feed file
+ *  - check all structs initialised
+ *  - check all fd watches properly undone
+ *  - check all init functions called
  *  - -k kill mode ?
  */
 
  *  - -k kill mode ?
  */
 
@@ -157,13 +160,15 @@ perl -ne 'print if m/-8\<-/..m/-\>8-/; print "\f" if m/-\^L-/' backends/innduct.
 
 #define _GNU_SOURCE
 
 
 #define _GNU_SOURCE
 
-#include "inn/list.h"
 #include "config.h"
 #include "storage.h"
 #include "nntp.h"
 #include "libinn.h"
 #include "inndcomm.h"
 
 #include "config.h"
 #include "storage.h"
 #include "nntp.h"
 #include "libinn.h"
 #include "inndcomm.h"
 
+#include "inn/list.h"
+#include "inn/innconf.h"
+
 #include <sys/uio.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/uio.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -181,6 +186,7 @@ perl -ne 'print if m/-8\<-/..m/-\>8-/; print "\f" if m/-\^L-/' backends/innduct.
 #include <stdlib.h>
 #include <glob.h>
 #include <time.h>
 #include <stdlib.h>
 #include <glob.h>
 #include <time.h>
+#include <math.h>
 
 #include <oop.h>
 #include <oop-read.h>
 
 #include <oop.h>
 #include <oop-read.h>
@@ -294,7 +300,7 @@ static void filemon_callback(InputFile *ipf);
 
 /*----- configuration options -----*/
 
 
 /*----- configuration options -----*/
 
-static char *sitename, *feedfile;
+static const char *sitename, *feedfile, *pathoutgoing;
 static const char *remote_host;
 static int quiet_multiple=0, become_daemon=1;
 
 static const char *remote_host;
 static int quiet_multiple=0, become_daemon=1;
 
@@ -455,11 +461,13 @@ static int nocheck, nocheck_reported;
 
 /*========== logging ==========*/
 
 
 /*========== logging ==========*/
 
-static void logcore(int sysloglevel, const char *fmt, ...)
-     __attribute__((__format__(printf,2,3)));
+#define VA                va_list al;  va_start(al,fmt)
+#define PRINTF(f,a)       __attribute__((__format__(printf,f,a)))
+#define NORET_PRINTF(f,a) __attribute__((__noreturn__,__format__(printf,f,a)))
+
+static void logcore(int sysloglevel, const char *fmt, ...) PRINTF(2,3);
 static void logcore(int sysloglevel, const char *fmt, ...) {
 static void logcore(int sysloglevel, const char *fmt, ...) {
-  va_list al;
-  va_start(al,fmt);
+  VA;
   if (become_daemon) {
     vsyslog(sysloglevel,fmt,al);
   } else {
   if (become_daemon) {
     vsyslog(sysloglevel,fmt,al);
   } else {
@@ -470,8 +478,7 @@ static void logcore(int sysloglevel, const char *fmt, ...) {
 }
 
 static void logv(int sysloglevel, const char *pfx, int errnoval,
 }
 
 static void logv(int sysloglevel, const char *pfx, int errnoval,
-                const char *fmt, va_list al)
-     __attribute__((__format__(printf,5,0)));
+                const char *fmt, va_list al) PRINTF(5,0);
 static void logv(int sysloglevel, const char *pfx, int errnoval,
                 const char *fmt, va_list al) {
   char msgbuf[256]; /* NB do not call xvasprintf here or you'll recurse */
 static void logv(int sysloglevel, const char *pfx, int errnoval,
                 const char *fmt, va_list al) {
   char msgbuf[256]; /* NB do not call xvasprintf here or you'll recurse */
@@ -488,21 +495,17 @@ static void logv(int sysloglevel, const char *pfx, int errnoval,
 }
 
 #define diewrap(fn, pfx, sysloglevel, err, estatus)            \
 }
 
 #define diewrap(fn, pfx, sysloglevel, err, estatus)            \
-  static void fn(const char *fmt, ...)                         \
-      __attribute__((__noreturn__,__format__(printf,1,2)));    \
+  static void fn(const char *fmt, ...) NORET_PRINTF(1,2);      \
   static void fn(const char *fmt, ...) {                       \
   static void fn(const char *fmt, ...) {                       \
-    va_list al;                                                        \
-    va_start(al,fmt);                                          \
+    VA;                                                                \
     logv(sysloglevel, pfx, err, fmt, al);                      \
     exit(estatus);                                             \
   }
 
 #define logwrap(fn, pfx, sysloglevel, err)             \
     logv(sysloglevel, pfx, err, fmt, al);                      \
     exit(estatus);                                             \
   }
 
 #define logwrap(fn, pfx, sysloglevel, err)             \
-  static void fn(const char *fmt, ...)                 \
-      __attribute__((__format__(printf,1,2)));         \
+  static void fn(const char *fmt, ...) PRINTF(1,2);    \
   static void fn(const char *fmt, ...) {               \
   static void fn(const char *fmt, ...) {               \
-    va_list al;                                                \
-    va_start(al,fmt);                                  \
+    VA;                                                        \
     logv(sysloglevel, pfx, err, fmt, al);              \
     va_end(al);                                                \
   }
     logv(sysloglevel, pfx, err, fmt, al);              \
     va_end(al);                                                \
   }
@@ -523,19 +526,16 @@ logwrap(debug,    " debug",    LOG_DEBUG,   -1);
 
 /*========== utility functions etc. ==========*/
 
 
 /*========== utility functions etc. ==========*/
 
-static char *xvasprintf(const char *fmt, va_list al)
-     __attribute__((__format__(printf,1,0)));
+static char *xvasprintf(const char *fmt, va_list al) PRINTF(1,0);
 static char *xvasprintf(const char *fmt, va_list al) {
   char *str;
   int rc= vasprintf(&str,fmt,al);
   if (rc<0) sysdie("vasprintf(\"%s\",...) failed", fmt);
   return str;
 }
 static char *xvasprintf(const char *fmt, va_list al) {
   char *str;
   int rc= vasprintf(&str,fmt,al);
   if (rc<0) sysdie("vasprintf(\"%s\",...) failed", fmt);
   return str;
 }
-static char *xasprintf(const char *fmt, ...)
-     __attribute__((__format__(printf,1,2)));
+static char *xasprintf(const char *fmt, ...) PRINTF(1,2);
 static char *xasprintf(const char *fmt, ...) {
 static char *xasprintf(const char *fmt, ...) {
-  va_list al;
-  va_start(al,fmt);
+  VA;
   char *str= xvasprintf(fmt,al);
   va_end(al);
   return str;
   char *str= xvasprintf(fmt,al);
   va_end(al);
   return str;
@@ -952,9 +952,7 @@ static void conn_maybe_write(Conn *conn)  {
   }
 }
 
   }
 }
 
-static void vconnfail(Conn *conn, const char *fmt, va_list al)
-     __attribute__((__format__(printf,2,0)));
-
+static void vconnfail(Conn *conn, const char *fmt, va_list al) PRINTF(2,0);
 static void vconnfail(Conn *conn, const char *fmt, va_list al) {
   int requeue[art_MaxState];
 
 static void vconnfail(Conn *conn, const char *fmt, va_list al) {
   int requeue[art_MaxState];
 
@@ -982,8 +980,7 @@ static void vconnfail(Conn *conn, const char *fmt, va_list al) {
   check_master_queue();
 }
 
   check_master_queue();
 }
 
-static void connfail(Conn *conn, const char *fmt, ...)
-     __attribute__((__format__(printf,2,3)));
+static void connfail(Conn *conn, const char *fmt, ...) PRINTF(2,3);
 static void connfail(Conn *conn, const char *fmt, ...) {
   va_list al;
   va_start(al,fmt);
 static void connfail(Conn *conn, const char *fmt, ...) {
   va_list al;
   va_start(al,fmt);
@@ -2410,13 +2407,13 @@ EVERY(period, PERIOD_SECONDS,0, {
 
 /*========== option parsing ==========*/
 
 
 /*========== option parsing ==========*/
 
-static void vbadusage(const char *fmt, va_list al)
-     __attribute__((__noreturn__,__format__(printf,1,0)));
+/*---------- generic option parser and logging ----------*/
+
+static void vbadusage(const char *fmt, va_list al) NORET_PRINTF(1,0);
 static void vbadusage(const char *fmt, va_list al) {
   abort();
 }
 static void vbadusage(const char *fmt, va_list al) {
   abort();
 }
-static void badusage(const char *fmt, ...)
-     __attribute__((__noreturn__,__format__(printf,1,2)));
+static void badusage(const char *fmt, ...) NORET_PRINTF(1,2);
 static void badusage(const char *fmt, ...) {
   va_list al;
   va_start(al,fmt);
 static void badusage(const char *fmt, ...) {
   va_list al;
   va_start(al,fmt);
@@ -2436,9 +2433,11 @@ struct Option {
   const char *lng;
   void *store;
   OptionParser *fn;
   const char *lng;
   void *store;
   OptionParser *fn;
-  int noarg;
+  int noarg, intval;
 };
 
 };
 
+/*---------- specific option types ----------*/
+
 static void op_integer(const Option *o, const char *val) {
   char *ep;
   errno= 0;
 static void op_integer(const Option *o, const char *val) {
   char *ep;
   errno= 0;
@@ -2459,14 +2458,14 @@ static void op_double(const Option *o, const char *val) {
 }
 
 static void op_string(const Option *o, const char *val) {
 }
 
 static void op_string(const Option *o, const char *val) {
-  char **store= o->store;
-  free(*store);
+  const char **store= o->store;
   *store= val;
 }
 
 static void op_seconds(const Option *o, const char *val) {
   int *store= o->store;
   char *ep;
   *store= val;
 }
 
 static void op_seconds(const Option *o, const char *val) {
   int *store= o->store;
   char *ep;
+  int unit;
 
   double v= strtod(val,&ep);
   if (ep==val) badusage("bad time/duration value for %s",o->lng);
 
   double v= strtod(val,&ep);
   if (ep==val) badusage("bad time/duration value for %s",o->lng);
@@ -2490,36 +2489,33 @@ static void op_periods_rndup(const Option *o, const char *val) {
   *store /= PERIOD_SECONDS;
 }
 
   *store /= PERIOD_SECONDS;
 }
 
-static void op_periods_booltrue(const Option *o, const char *val) {
+static void op_setint(const Option *o, const char *val) {
   int *store= o->store;
   int *store= o->store;
-  *store= 1;
-}
-static void op_periods_boolfalse(const Option *o, const char *val) {
-  int *store= o->store;
-  *store= 0;
+  *store= o->intval;
 }
 
 }
 
+/*---------- specific options ----------*/
+
 static const Option options[]= {
 {'f',"feedfile",              &feedfile,                 op_string           },
 static const Option options[]= {
 {'f',"feedfile",              &feedfile,                 op_string           },
-{'q',"quiet-multiple",        &quiet_multiple,           op_booltrue,  1     },
+{'q',"quiet-multiple",        &quiet_multiple,           op_setint,   1,1    },
 
 
-{ 0, "max-connections",       &max_connections           op_integer          },
-{ 0, "max-queue-per-conn",    &max_queue_per_conn        op_integer          },
+{ 0, "max-connections",       &max_connections,          op_integer          },
+{ 0, "max-queue-per-conn",    &max_queue_per_conn,       op_integer          },
 
 
 
 
-{ 0, "streaming",             &try_stream,               op_booltrue,  1     },
-{ 0, "no-streaming",          &try_stream,               op_boolfalse, 1     },
-{'P',"port",                  &port                      op_integer          },
+{ 0, "streaming",             &try_stream,               op_setint,  1,1     },
+{ 0, "no-streaming",          &try_stream,               op_setint,  1,0     },
+{'P',"port",                  &port,                     op_integer          },
 { 0, "inndconf",              &inndconffile,             op_string           },
 { 0, "inndconf",              &inndconffile,             op_string           },
-{'d',"daemon",                &become_daemon,            op_booltrue,  1     },
-{ 0, "no-daemon",             &become_daemon,            op_boolfalse, 1     },
+{'d',"daemon",                &become_daemon,            op_setint,  1,1     },
+{ 0, "no-daemon",             &become_daemon,            op_setint,  1,0     },
 
 { 0, "no-check-proportion",   &nocheck_thresh_pct,       op_double           },
 { 0, "no-check-filter",       &nocheck_decay_articles,   op_double           },
 
 { 0, "reconnect-interval",    &reconnect_delay_periods,  op_periods_rndup    },
 { 0, "flush-retry-interval",  &flushfail_retry_periods,  op_periods_rndup    },
 
 { 0, "no-check-proportion",   &nocheck_thresh_pct,       op_double           },
 { 0, "no-check-filter",       &nocheck_decay_articles,   op_double           },
 
 { 0, "reconnect-interval",    &reconnect_delay_periods,  op_periods_rndup    },
 { 0, "flush-retry-interval",  &flushfail_retry_periods,  op_periods_rndup    },
-{ 0, "connection-timeout",    &connection_timeout,       op_seconds          },
 { 0, "inndcomm-timeout",      &inndcomm_flush_timeout,   op_seconds          },
 };
 
 { 0, "inndcomm-timeout",      &inndcomm_flush_timeout,   op_seconds          },
 };
 
@@ -2606,13 +2602,15 @@ int main(int argc, char **argv) {
     if (strchr(feedfile, c))
       badusage("feed filename may not contain metacharacter %c",c);
 
     if (strchr(feedfile, c))
       badusage("feed filename may not contain metacharacter %c",c);
 
-  loop= oop_sys_new();
-  if (!loop) sysdie("could not create liboop event loop");
+  oop_source_sys *sysloop= oop_sys_new();
+  if (!sysloop) sysdie("could not create liboop event loop");
+  loop= (oop_source*)sysloop;
 
   if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
     sysdie("could not ignore SIGPIPE");
 
   if (become_daemon) {
 
   if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
     sysdie("could not ignore SIGPIPE");
 
   if (become_daemon) {
+    int i;
     for (i=3; i<255; i++)
       /* do this now before we open syslog, etc. */
       close(i);
     for (i=3; i<255; i++)
       /* do this now before we open syslog, etc. */
       close(i);
@@ -2637,7 +2635,7 @@ int main(int argc, char **argv) {
 
   notice("starting");
 
 
   notice("starting");
 
-  if (!filemon_init()) {
+  if (!filemon_method_init()) {
     warn("no file monitoring available, polling");
     filepoll_schedule();
   }
     warn("no file monitoring available, polling");
     filepoll_schedule();
   }
@@ -2646,5 +2644,7 @@ int main(int argc, char **argv) {
 
   statemc_init();
 
 
   statemc_init();
 
-  loop->execute.
+  void *r= oop_sys_run(sysloop);
+  assert(r == OOP_ERROR);
+  sysdie("event loop failed");
 }
 }