From: Ian Jackson Date: Sat, 8 May 2010 14:47:10 +0000 (+0100) Subject: rename [sys]die => [sys]crash and turn a few of them into dies X-Git-Tag: innduct-0.1~33 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=innduct.git;a=commitdiff_plain;h=53db7fc32be73c6665fe5f2e07e89351f5f43cea rename [sys]die => [sys]crash and turn a few of them into dies --- diff --git a/backends/innduct.c b/backends/innduct.c index 5d49ea6..d9091d6 100644 --- a/backends/innduct.c +++ b/backends/innduct.c @@ -592,8 +592,8 @@ static void logv(int sysloglevel, const char *pfx, int errnoval, va_end(al); \ } -diewrap(sysdie, " critical", LOG_CRIT, errno, 16); -diewrap(die, " critical", LOG_CRIT, -1, 16); +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); @@ -617,7 +617,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) sysdie("vasprintf(\"%s\",...) failed", fmt); + if (rc<0) sysfatal("vasprintf(\"%s\",...) failed", fmt); return str; } static char *masprintf(const char *fmt, ...) PRINTF(1,2); @@ -636,7 +636,7 @@ static int close_perhaps(int *fd) { } static void mclose(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 mclose_perhaps(int *fd, const char *what, const char *what2) { if (*fd <= 0) return; @@ -686,11 +686,11 @@ static int mwaitpid(pid_t *pid, const char *what) { 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; @@ -699,7 +699,7 @@ static int mwaitpid(pid_t *pid, const char *what) { static void *mmalloc(size_t sz) { void *p= malloc(sz); - if (!p) sysdie("unable to malloc %lu bytes",(unsigned long)sz); + if (!p) sysfatal("unable to malloc %lu bytes",(unsigned long)sz); return p; } @@ -711,18 +711,18 @@ static void *zmmalloc(size_t sz) { static void munlink(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 mtime(void) { time_t now= time(0); - if (now==-1) sysdie("time(2) failed"); + if (now==-1) syscrash("time(2) failed"); return now; } static void msigaction(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 msigsetdefault(int signo) { @@ -734,24 +734,24 @@ static void msigsetdefault(int signo) { static void mgettimeofday(struct timeval *tv_r) { int r= gettimeofday(tv_r,0); - if (r) sysdie("gettimeofday(2) failed"); + if (r) syscrash("gettimeofday(2) failed"); } static void msetnonblock(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 mfstat(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 mfstat_isreg(int fd, struct stat *stab_r, @@ -766,7 +766,7 @@ static void mlstat_isreg(const char *path, struct stat *stab, 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); @@ -1313,24 +1313,24 @@ static void *connchild_event(oop_source *lp, int fd, oop_event e, void *u) { 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; @@ -1348,11 +1348,11 @@ static void *connchild_event(oop_source *lp, int fd, oop_event e, void *u) { 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", @@ -1464,8 +1464,8 @@ static void connect_start(void) { 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); } @@ -1923,9 +1923,9 @@ static void article_done(Article *art, int whichcount) { 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; @@ -2100,8 +2100,8 @@ static void *feedfile_got_bad_data(InputFile *ipf, off_t offset, 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; } @@ -2112,8 +2112,8 @@ static void *feedfile_read_err(oop_source *lp, oop_read *rd, 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, @@ -2305,7 +2305,7 @@ static void filemon_method_stopfile(InputFile *ipf, Filemon_Perfile *pf) { int wd= pf->wd; debug("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; } @@ -2316,11 +2316,11 @@ static void *filemon_inotify_readable(oop_source *lp, int fd, 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);*/ @@ -2399,7 +2399,7 @@ static void inputfile_reading_resume(InputFile *ipf) { 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; } @@ -2577,10 +2577,10 @@ static void statemc_lock(void) { } 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, @@ -2611,8 +2611,8 @@ static void statemc_init(void) { " (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); } } @@ -2641,13 +2641,13 @@ static void statemc_init(void) { 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"); 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"); } @@ -2766,7 +2766,7 @@ static void statemc_check_backlog_done(void) { 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); @@ -2855,7 +2855,7 @@ static void open_defer(void) { mfstat_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; @@ -2865,14 +2865,14 @@ static void open_defer(void) { 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--; @@ -2886,14 +2886,14 @@ static void open_defer(void) { if (fflush(defer)) sysfatal("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) { @@ -2913,10 +2913,10 @@ static void close_defer(void) { (unsigned long)stab.st_ino); if (link(path_defer, backlog)) sysfatal("could not install defer file %s as backlog file %s", - path_defer, backlog); + 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); @@ -2976,8 +2976,8 @@ static void search_backlog_file(void) { 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) { @@ -3055,8 +3055,9 @@ static void *sigarrived_event(oop_source *lp, int fd, oop_event e, void *u) { 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)); @@ -3080,7 +3081,7 @@ static void sigarrived_handler(int signum) { 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"); @@ -3147,9 +3148,9 @@ static void *inndcomm_event(oop_source *lp, int fd, oop_event e, void *u) { 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"); @@ -3238,7 +3239,7 @@ static void postfork_inputfile(InputFile *ipf) { 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) { @@ -3491,7 +3492,7 @@ static void vbadusage(const char *fmt, va_list al) { "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_CRASH,"innduct: invoked with bad usage: %s",m); exit(8); } @@ -3807,7 +3808,7 @@ int main(int argc, char **argv) { globpat_backlog= masprintf("%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); @@ -3841,10 +3842,10 @@ int main(int argc, char **argv) { } 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); + if (r) sysfatal("could not chdir to pathrun %s", path_run); statemc_lock(); @@ -3854,7 +3855,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) die("storage manager initialisation (SMinit) failed"); + r= SMinit(); if (!r) fatal("storage manager initialisation (SMinit) failed"); if (interactive >= 2) cli_stdio(); @@ -3880,5 +3881,5 @@ int main(int argc, char **argv) { void *run= oop_sys_run(sysloop); assert(run == OOP_ERROR); - sysdie("event loop failed"); + syscrash("event loop failed"); }