From f6c01014890cd563725a1783dbc1f5b524aac3f0 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 8 May 2010 16:12:07 +0100 Subject: [PATCH] use libinn for die (rename fatal -> die) --- backends/innduct.c | 92 +++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 50 deletions(-) diff --git a/backends/innduct.c b/backends/innduct.c index 00bbe2d..5da5600 100644 --- a/backends/innduct.c +++ b/backends/innduct.c @@ -225,8 +225,8 @@ perl -ne 'print if m/-8\<-/..m/-\>8-/; print "\f" if m/-\^L-/' backends/innduct. #define NORET_PRINTF(f,a) __attribute__((__noreturn__,__format__(printf,f,a))) #define NORET __attribute__((__noreturn__)) -#define NEW(ptr) ((ptr)= zmmalloc(sizeof(*(ptr)))) -#define NEW_DECL(type,ptr) type ptr = zmmalloc(sizeof(*(ptr))) +#define NEW(ptr) ((ptr)= zxmalloc(sizeof(*(ptr)))) +#define NEW_DECL(type,ptr) type ptr = zxmalloc(sizeof(*(ptr))) #define DUMPV(fmt,pfx,v) fprintf(f, " " #v "=" fmt, pfx v); @@ -608,10 +608,8 @@ static int innduct_fatal_cleanup(void) { return 12; } /* used for libinn die */ 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); - #define INNLOGWRAPS(INNLOGWRAP) \ + INNLOGWRAP(die, " fatal", LOG_ERR) \ INNLOGWRAP(warn, " warning", LOG_WARNING) \ INNLOGWRAP(notice, " notice", LOG_NOTICE) INNLOGWRAPS(INNLOGWRAP_DECLARE) @@ -631,7 +629,7 @@ static char *mvasprintf(const char *fmt, va_list al) PRINTF(1,0); static char *mvasprintf(const char *fmt, va_list al) { char *str; int rc= vasprintf(&str,fmt,al); - if (rc<0) sysfatal("vasprintf(\"%s\",...) failed", fmt); + if (rc<0) sysdie("vasprintf(\"%s\",...) failed", fmt); return str; } static char *masprintf(const char *fmt, ...) PRINTF(1,2); @@ -662,7 +660,7 @@ static pid_t mfork(const char *what) { pid_t child; child= fork(); - if (child==-1) sysfatal("cannot fork for %s",what); + if (child==-1) sysdie("cannot fork for %s",what); dbg("forked %s %ld", what, (unsigned long)child); if (!child) postfork(); return child; @@ -711,14 +709,8 @@ static int mwaitpid(pid_t *pid, const char *what) { return status; } -static void *mmalloc(size_t sz) { - void *p= malloc(sz); - if (!p) sysfatal("unable to malloc %lu bytes",(unsigned long)sz); - return p; -} - -static void *zmmalloc(size_t sz) { - void *p= mmalloc(sz); +static void *zxmalloc(size_t sz) { + void *p= xmalloc(sz); memset(p,0,sz); return p; } @@ -1354,7 +1346,7 @@ static void *connchild_event(oop_source *lp, int fd, oop_event e, void *u) { 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! */ @@ -1421,37 +1413,37 @@ static void connect_start(void) { --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: @@ -1620,7 +1612,7 @@ static void article_defer(Article *art /* not on a queue */, int whichcount) { 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); } @@ -2081,11 +2073,11 @@ static InputFile *open_input_file(const char *path) { 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); - InputFile *ipf= mmalloc(sizeof(*ipf) + strlen(path) + 1); + InputFile *ipf= xmalloc(sizeof(*ipf) + strlen(path) + 1); memset(ipf,0,sizeof(*ipf)); ipf->fd= fd; @@ -2180,7 +2172,7 @@ static void *feedfile_got_article(oop_source *lp, oop_read *rd, ipf->readcount_ok++; - art= mmalloc(sizeof(*art) - 1 + midlen + 1); + art= xmalloc(sizeof(*art) - 1 + midlen + 1); memset(art,0,sizeof(*art)); art->state= art_Unchecked; art->midlen= midlen; @@ -2295,7 +2287,7 @@ struct Filemon_Perfile { 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; @@ -2565,7 +2557,7 @@ static void statemc_lock(void) { 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)); @@ -2575,9 +2567,9 @@ static void statemc_lock(void) { 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); } mfstat_isreg(lockfd, &stabf, path_lock, "lockfile"); @@ -2600,7 +2592,7 @@ static void statemc_lock(void) { (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); dbg("startup: locked"); } @@ -2678,8 +2670,8 @@ static void statemc_start_flush(const char *why) { /* Normal => Flushing */ 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 */ munlink(feedfile, "old feedfile link"); @@ -2862,7 +2854,7 @@ static void open_defer(void) { 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 */ @@ -2898,7 +2890,7 @@ static void open_defer(void) { 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)) syscrash("could not truncate defer file %s", path_defer); @@ -2917,7 +2909,7 @@ static void close_defer(void) { struct stat stab; mfstat_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= mtime(); @@ -2926,8 +2918,8 @@ static void close_defer(void) { (unsigned long)now, (unsigned long)stab.st_ino); if (link(path_defer, backlog)) - sysfatal("could not install defer file %s as backlog file %s", - path_defer, backlog); + sysdie("could not install defer file %s as backlog file %s", + path_defer, backlog); if (unlink(path_defer)) syscrash("could not unlink old defer link %s to backlog file %s", path_defer, backlog); @@ -2962,9 +2954,9 @@ static void search_backlog_file(void) { 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 Flushing */ 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= mfork("inndcomm child"); @@ -3844,7 +3836,7 @@ int main(int argc, char **argv) { 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); @@ -3854,7 +3846,7 @@ int main(int argc, char **argv) { if (child1) _exit(0); pid_t sid= setsid(); - if (sid == -1) sysfatal("setsid failed"); + if (sid == -1) sysdie("setsid failed"); pid_t child2= mfork("daemonise second fork"); if (child2) _exit(0); @@ -3864,7 +3856,7 @@ int main(int argc, char **argv) { if (self_pid==-1) syscrash("getpid"); r= chdir(path_run); - if (r) sysfatal("could not chdir to pathrun %s", path_run); + if (r) sysdie("could not chdir to pathrun %s", path_run); statemc_lock(); @@ -3874,7 +3866,7 @@ int main(int argc, char **argv) { int val= 1; r= SMsetup(SM_PREOPEN, &val); if (!r) warn("SMsetup SM_PREOPEN failed"); - r= SMinit(); if (!r) fatal("storage manager initialisation (SMinit) failed"); + r= SMinit(); if (!r) die("storage manager initialisation (SMinit) failed"); if (interactive >= 2) cli_stdio(); -- 2.30.2