From: zoulasc Date: Fri, 21 Mar 2014 00:52:54 +0000 (-0400) Subject: From: Ian Kent X-Git-Url: https://git.fsl.cs.sunysb.edu/?a=commitdiff_plain;h=1bc698124825140020dcb2decc72de8e2b4a10ad;p=am-utils-6.2.git From: Ian Kent It's possible (and likely) a SIGCHLD signal can arrive while in syslog(2) and also attempt log log a message leading to deadlock. --- diff --git a/libamu/xutil.c b/libamu/xutil.c index 28286f61..1159fe5e 100644 --- a/libamu/xutil.c +++ b/libamu/xutil.c @@ -422,14 +422,33 @@ debug_option(char *opt) void dplog(const char *fmt, ...) { +#ifdef HAVE_SIGACTION + sigset_t old, chld; +#else /* not HAVE_SIGACTION */ + int mask; +#endif /* not HAVE_SIGACTION */ va_list ap; +#ifdef HAVE_SIGACTION + sigemptyset(&chld); + sigaddset(&chld, SIGCHLD); +#else /* not HAVE_SIGACTION */ + mask = sigblock(sigmask(SIGCHLD)); +#endif /* not HAVE_SIGACTION */ + + sigprocmask(SIG_BLOCK, &chld, &old); if (!logfp) logfp = stderr; /* initialize before possible first use */ va_start(ap, fmt); real_plog(XLOG_DEBUG, fmt, ap); va_end(ap); + +#ifdef HAVE_SIGACTION + sigprocmask(SIG_SETMASK, &old, NULL); +#else /* not HAVE_SIGACTION */ + mask = sigblock(sigmask(SIGCHLD)); +#endif /* not HAVE_SIGACTION */ } #endif /* DEBUG */ @@ -437,14 +456,33 @@ dplog(const char *fmt, ...) void plog(int lvl, const char *fmt, ...) { +#ifdef HAVE_SIGACTION + sigset_t old, chld; +#else /* not HAVE_SIGACTION */ + int mask; +#endif /* not HAVE_SIGACTION */ va_list ap; +#ifdef HAVE_SIGACTION + sigemptyset(&chld); + sigaddset(&chld, SIGCHLD); + sigprocmask(SIG_BLOCK, &chld, &old); +#else /* not HAVE_SIGACTION */ + mask = sigblock(sigmask(SIGCHLD)); +#endif /* not HAVE_SIGACTION */ + if (!logfp) logfp = stderr; /* initialize before possible first use */ va_start(ap, fmt); real_plog(lvl, fmt, ap); va_end(ap); + +#ifdef HAVE_SIGACTION + sigprocmask(SIG_SETMASK, &old, NULL); +#else /* not HAVE_SIGACTION */ + sigsetmask(mask); +#endif /* not HAVE_SIGACTION */ }