X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=innduct.git;a=blobdiff_plain;f=help.c;h=46a784eb04d6817a469cdd9507536bfdadebb6cf;hp=144ab86f7298f9c2a2689534ab86855ce18755a8;hb=a34c62479ae1f91aac7b30d3d5f1a5106a6635f5;hpb=f4aee95c41a0d6231d115386b8fbb23f6b8e349a diff --git a/help.c b/help.c index 144ab86..46a784e 100644 --- a/help.c +++ b/help.c @@ -1,7 +1,7 @@ /* * innduct * tailing reliable realtime streaming feeder for inn - * logging and utility functions + * help.c - logging and utility functions * * Copyright (C) 2010 Ian Jackson * @@ -49,7 +49,7 @@ static void logcore(int sysloglevel, const char *fmt, ...) { void logv(int sysloglevel, const char *pfx, int errnoval, const char *fmt, va_list al) { - char msgbuf[1024]; /* NB do not call xvasprintf here or you'll recurse */ + char msgbuf[1024]; /* NB do not call mvasprintf here or you'll recurse */ vsnprintf(msgbuf,sizeof(msgbuf), fmt,al); msgbuf[sizeof(msgbuf)-1]= 0; @@ -70,24 +70,18 @@ void logv(int sysloglevel, const char *pfx, int errnoval, exit(estatus); \ } -#define DEFLOG(fn, pfx, sysloglevel, err) \ - static void fn(const char *fmt, ...) { \ - VA; \ - logv(sysloglevel, pfx, err, fmt, al); \ - va_end(al); \ +#define DEFLOG(fn, pfx, sysloglevel, err) \ + void fn(const char *fmt, ...) { \ + VA; \ + logv(sysloglevel, pfx, err, fmt, al); \ + va_end(al); \ } -#define INNLOGSET_DECLARE(fn, pfx, sysloglevel) \ - static void duct_log_##fn(int l, const char *fmt, va_list al, int errval) \ - PRINTF(3,0); \ - static void duct_log_##fn(int l, const char *fmt, va_list al, int errval) { \ - logv(sysloglevel, pfx, errval ? errval : -1, fmt, al); \ +#define INNLOGSET_DEFINE(fn, pfx, sysloglevel) \ + void duct_log_##fn(int l, const char *fmt, va_list al, int errval) { \ + logv(sysloglevel, pfx, errval ? errval : -1, fmt, al); \ } -#define INNLOGSET_CALL(fn, pfx, sysloglevel) \ - message_handlers_##fn(1, duct_log_##fn); - -static int innduct_fatal_cleanup(void) { return 12; } /* used for libinn die */ /* We want to extend the set of logging functions from inn, and we * want to prepend the site name to all our messages. */ @@ -95,12 +89,7 @@ static int innduct_fatal_cleanup(void) { return 12; } /* used for libinn die */ DEFFATAL(syscrash, "critical", LOG_CRIT, errno, 16); DEFFATAL(crash, "critical", LOG_CRIT, -1, 16); -#define INNLOGSETS(INNLOGSET) \ - INNLOGSET(die, "fatal", LOG_ERR) \ - INNLOGSET(warn, "warning", LOG_WARNING) \ - INNLOGSET(notice, "notice", LOG_NOTICE) \ - INNLOGSET(trace, "trace", LOG_NOTICE) -INNLOGSETS(INNLOGSET_DECLARE) +INNLOGSETS(INNLOGSET_DEFINE) DEFLOG(info, "info", LOG_INFO, -1) DEFLOG(dbg, "debug", LOG_DEBUG, -1) @@ -108,16 +97,16 @@ DEFLOG(dbg, "debug", LOG_DEBUG, -1) /*========== utility functions etc. ==========*/ -char *xvasprintf(const char *fmt, va_list al) { +char *mvasprintf(const char *fmt, va_list al) { char *str; int rc= vasprintf(&str,fmt,al); if (rc<0) sysdie("vasprintf(\"%s\",...) failed", fmt); return str; } -char *xasprintf(const char *fmt, ...) { +char *masprintf(const char *fmt, ...) { VA; - char *str= xvasprintf(fmt,al); + char *str= mvasprintf(fmt,al); va_end(al); return str; } @@ -138,12 +127,15 @@ void xclose_perhaps(int *fd, const char *what, const char *what2) { *fd=0; } -pid_t xfork(const char *what) { - pid_t child; - - child= fork(); +pid_t xfork_bare(const char *what) { + pid_t child= fork(); if (child==-1) sysdie("cannot fork for %s",what); dbg("forked %s %ld", what, (unsigned long)child); + return child; +} + +pid_t xfork(const char *what) { + pid_t child= xfork_bare(what); if (!child) postfork(); return child; } @@ -218,6 +210,11 @@ void xsigsetdefault(int signo) { sa.sa_handler= SIG_DFL; xsigaction(signo,&sa); } +void raise_default(int signo) { + xsigsetdefault(signo); + raise(signo); + abort(); +} void xgettimeofday(struct timeval *tv_r) { int r= gettimeofday(tv_r,0); @@ -235,13 +232,13 @@ void check_isreg(const struct stat *stab, const char *path, what, path, (unsigned long)stab->st_mode); } -static void xfstat(int fd, struct stat *stab_r, const char *what) { +void xfstat(int fd, struct stat *stab_r, const char *what) { int r= fstat(fd, stab_r); if (r) syscrash("could not fstat %s", what); } -static void xfstat_isreg(int fd, struct stat *stab_r, - const char *path, const char *what) { +void xfstat_isreg(int fd, struct stat *stab_r, + const char *path, const char *what) { xfstat(fd, stab_r, what); check_isreg(stab_r, path, what); }