From: Ian Jackson Date: Wed, 21 Apr 2010 21:13:50 +0000 (+0100) Subject: WIP make it compile X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=inn-innduct.git;a=commitdiff_plain;h=4e748bf495b4c5c0582b877aee531dec31fc2a36 WIP make it compile rune is cd /home/ian/things/Innfeed/inn2-2.4.5 && debian/rules build --- diff --git a/backends/Makefile b/backends/Makefile index f419e3f..1d8071c 100644 --- a/backends/Makefile +++ b/backends/Makefile @@ -9,13 +9,13 @@ ALL = actmerge actsync actsyncd archive batcher buffchan \ cvtbatch filechan inndf innxmit innxbatch mod-active \ news2mail ninpaths nntpget nntpsend overchan send-ihave \ send-nntp send-uucp sendinpaths sendxbatches shlock \ - shrinkfile + shrinkfile innduct MAN = ../doc/man/send-uucp.8 SOURCES = actsync.c archive.c batcher.c buffchan.c cvtbatch.c \ filechan.c inndf.c innxbatch.c innxmit.c map.c ninpaths.c \ - nntpget.c overchan.c shlock.c shrinkfile.c + nntpget.c overchan.c shlock.c shrinkfile.c innduct.c all: $(ALL) @@ -26,7 +26,7 @@ warnings: install: all for F in actmerge actsyncd news2mail nntpsend send-ihave send-nntp \ - send-uucp sendinpaths sendxbatches ; do \ + send-uucp sendinpaths sendxbatches innduct ; do \ $(CP_XPUB) $$F $D$(PATHBIN)/$$F ; \ done $(CP_XPRI) mod-active $D$(PATHBIN)/mod-active @@ -75,6 +75,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) +innduct: innduct.o $(LIBINN) ; $(LINK) innduct.o $(INNLIBS) buffchan: buffchan.o map.o $(LIBINN) $(LINK) buffchan.o map.o $(LIBINN) $(LIBS) diff --git a/backends/innduct.c b/backends/innduct.c index 7fa943d..b812470 100644 --- a/backends/innduct.c +++ b/backends/innduct.c @@ -145,6 +145,24 @@ perl -ne 'print if m/-8\<-/..m/-\>8-/; print "\f" if m/-\^L-/' backends/innduct. * */ +#define _GNU_SOURCE + +#include "config.h" +#include "storage.h" +#include "oop.h" +#include "oop-read.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /*----- general definitions, probably best not changed -----*/ @@ -156,12 +174,14 @@ perl -ne 'print if m/-8\<-/..m/-\>8-/; print "\f" if m/-\^L-/' backends/innduct. #define INNDCOMMCHILD_ESTATUS_FAIL 6 #define INNDCOMMCHILD_ESTATUS_NONESUCH 7 +typedef struct Conn Conn; +typedef struct Article Article; /*----- configuration options -----*/ static char *sitename, *feedfile; static const char *remote_host; -static int quiet_multiple=0; +static int quiet_multiple=0, become_daemon=1; static int max_connections=10, max_queue_per_conn=200; @@ -228,7 +248,7 @@ typedef enum { /* in queue in conn->sent */ , counts[art_Unsolicited] x typedef enum { -#define RC_INDEX(x) RCI_##x +#define RC_INDEX(x) RCI_##x, RESULT_COUNTS(RC_INDEX, RC_INDEX) RCI_max } ResultCountIndex; @@ -239,7 +259,7 @@ typedef enum { #define CONNIOVS 128 typedef enum { - xk_Malloc, xk_Const, xk_Artdata; + xk_Malloc, xk_Const, xk_Artdata } XmitKind; typedef struct { @@ -253,16 +273,6 @@ typedef struct { /*----- core operational data structure types -----*/ -struct Article { - ArtState state; - int midlen; - InputFile *ipf; - TOKEN token; - off_t offset; - int blanklen; - char messageid[1]; -}; - typedef struct InputFile { /* This is an instance of struct oop_readable */ struct oop_readable readable; /* first */ @@ -280,6 +290,16 @@ typedef struct InputFile { char path[]; } InputFile; +struct Article { + ArtState state; + int midlen; + InputFile *ipf; + TOKEN token; + off_t offset; + int blanklen; + char messageid[1]; +}; + #define SMS_LIST(X) \ X(NORMAL) \ X(FLUSHING) \ @@ -312,6 +332,8 @@ struct Conn { /*----- operational variables -----*/ +static oop_source *loop; + static int nconns; static LIST(Conn) idle, working, full; static LIST(Article) *queue; @@ -338,10 +360,74 @@ static void filemon_callback(void); static void statemc_setstate(StateMachineState newsms, int periods, const char *forlog, const char *why); +/*========== logging ==========*/ + +static void logcore(int sysloglevel, const char *fmt, ...) + __attribute__((__format__(printf,2,3))); +static void logcore(int sysloglevel, const char *fmt, ...) { + va_list al; + va_start(al,fmt); + if (become_daemon) { + vsyslog(sysloglevel,fmt,al); + } else { + vfprintf(stderr,fmt,al); + putc('\n',stderr); + } + va_end(al); +} + +static void logv(int sysloglevel, const char *pfx, int errnoval, + int exitstatus, const char *fmt, va_list al) + __attribute__((__format__(printf,5,0))); +static void logv(int sysloglevel, const char *pfx, int errnoval, + int exitstatus, const char *fmt, va_list al) { + char msgbuf[256]; + vsnprintf(msgbuf,sizeof(msgbuf), fmt,al); + msgbuf[sizeof(msgbuf)-1]= 0; + + 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) : ""); +} + +#define logwrap(fn, pfx, sysloglevel, err, estatus) \ + static void fn(const char *fmt, ...) \ + __attribute__((__format__(printf,1,2))); \ + static void fn(const char *fmt, ...) { \ + va_list al; \ + va_start(al,fmt); \ + logv(sysloglevel, pfx, err, estatus, fmt, al); \ + } + +logwrap(sysdie, " critical", LOG_CRIT, errno, 16); +logwrap(die, " critical", LOG_CRIT, -1, 16); + +logwrap(sysfatal, " fatal", LOG_ERR, errno, 12); +logwrap(fatal, " fatal", LOG_ERR, -1, 12); + +logwrap(syswarn, " warning", LOG_WARNING, errno, 0); +logwrap(warn, " warning", LOG_WARNING, -1, 0); + +logwrap(notice, "", LOG_NOTICE, -1, 0); +logwrap(info, " info", LOG_INFO, -1, 0); +logwrap(debug, " debug", LOG_DEBUG, -1, 0); + + /*========== utility functions etc. ==========*/ static void perhaps_close(int *fd) { if (*fd) { close(*fd); fd=0; } } +static void *xmalloc(size_t sz) { + if (!sz) return 0; + void *r= malloc(sz); + if (r) return r; + sysdie("malloc (%ld bytes) failed", (unsigned long)sz); +} + static pid_t xfork(const char *what) { pid_t child; @@ -383,7 +469,7 @@ static void report_child_status(const char *what, int status) { static int xwaitpid(pid_t *pid, const char *what) { int status; - r= kill(*pid, SIGKILL); + int r= kill(*pid, SIGKILL); if (r) sysdie("cannot kill %s child", what); pid_t got= waitpid(*pid, &status, WNOHANG); @@ -407,17 +493,18 @@ static void check_isreg(const struct stat *stab, const char *path, } static void xfstat(int fd, struct stat *stab_r, const char *what) { - int r= fstab(path, stab); - if (r) sysdie("could not fstat %s %s", what, path); + int r= fstab(fd, stab_r); + if (r) sysdie("could not fstat %s", what); } -static void xfstat_isreg(int fd, struct stat *stab_r, const char *what) { +static void xfstat_isreg(int fd, struct stat *stab_r, + const char *path, const char *what) { xfstat(fd, stab_r, what); - check_isreg(stab, path, what); + check_isreg(stab_r, path, what); } static void xlstat_isreg(const char *path, struct stat *stab, - int *enoent_r /* 0 means ENOENT is fatal */ + int *enoent_r /* 0 means ENOENT is fatal */, const char *what) { int r= lstat(path, stab); if (r) { @@ -435,63 +522,6 @@ static int samefile(const struct stat *a, const struct stat *b) { a->st_dev == b->st_dev); } -/*========== logging ==========*/ - -static void logcore(int sysloglevel, const char *fmt, ...) - __attribute__((printf,2,3)) -static void logcore(int sysloglevel, const char *fmt, ...) { - va_list al; - va_start(al,fmt); - if (become_daemon) { - vsyslog(sysloglevel,fmt,al); - } else { - vfprintf(stderr,fmt,al); - putc('\n',stderr); - } - va_end(al); -} - -static void logv(int sysloglevel, const char *pfx, int errnoval, - int exitstatus, const char *fmt, va_list al) - __attribute__((printf,4,0)) -static void logv(int sysloglevel, const char *pfx, int errnoval, - int exitstatus, const char *fmt, va_list al) { - char msgbuf[256]; - vsnprintf(msgbuf,sizeof(msgbuf), fmt,al); - msgbuf[sizeof(msgbuf)-1]= 0; - - 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) : ""); -} - -#define logwrap(fn, pfx, sysloglevel, errno, estatus) \ - static void fn(const char *fmt, ...) \ - __attribute__((printf,1,2)); \ - static void fn(const char *fmt, ...) { \ - va_list al; \ - va_start(al,fmt); \ - logv(sysloglevel, pfx, errno, estatus, fmt, al); \ - } - -logwrap(sysdie, " critical", LOG_CRIT, errno, 16); -logwrap(die, " critical", LOG_CRIT, -1, 16); - -logwrap(sysfatal, " fatal", LOG_ERR, errno, 12); -logwrap(fatal, " fatal", LOG_ERR, -1, 12); - -logwrap(syswarn, " warning", LOG_WARN, errno, 0); -logwrap(warn, " warning", LOG_WARN, -1, 0); - -logwrap(notice, "", LOG_NOTICE, -1, 0); -logwrap(info, " info", LOG_INFO, -1, 0); -logwrap(debug, " debug", LOG_DEBUG, -1, 0); - - /*========== making new connections ==========*/ static int connecting_sockets[2]= {-1,-1}; @@ -505,7 +535,7 @@ static void connect_attempt_discard(void) { perhaps_close(&connecting_sockets[1]); if (connecting_child) { - r= kill(connecting_child, SIGTERM); + int r= kill(connecting_child, SIGTERM); if (r) syswarn("failed to kill connecting child"); int status= xwaitpid(&connecting_child, "connect"); @@ -528,7 +558,7 @@ static void *connchild_event(oop_source *lp, int fd, oop_event e, void *u) { conn= xmalloc(sizeof(*conn)); memset(conn,0,sizeof(*conn)); - DECL_MSG_CMSG(msg); + PREP_DECL_MSG_CMSG(msg); struct cmsghdr *h= 0; ssize_t rs= recvmsg(fd, &msg, MSG_DONTWAIT); if (rs >= 0) h= CMSG_FIRSTHDR(&msg); @@ -2370,6 +2400,9 @@ int main(int argc, char **argv) { 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"); + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) sysdie("could not ignore SIGPIPE");