From: Andre Noll Date: Mon, 17 Mar 2008 06:34:29 +0000 (+0100) Subject: Fix para_next_signal(). X-Git-Tag: v0.3.2~61^2~2 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=bdf3b7573b4a2ef6a84bdf34442063b32977f54e Fix para_next_signal(). The function returned zero in case of errors.. --- diff --git a/signal.c b/signal.c index 78e788d1..0490a3a1 100644 --- a/signal.c +++ b/signal.c @@ -124,25 +124,31 @@ int para_install_sighandler(int sig) } /** - * return number of next pending signal + * Return the number of next pending signal. * * This should be called if the fd for the signal pipe is ready for reading. * - * \return On success, the number of the received signal is returned. \p - * -E_SIGNAL_READ is returned if a read error occurred while reading the signal - * pipe. If the read was interrupted by another signal the function returns 0. + * \return On success, the number of the received signal is returned. If the + * read returned zero or was interrupted by another signal the function returns + * 0. Otherwise, a negative error value is returned. */ int para_next_signal(void) { int s; - ssize_t r; + ssize_t r = read(signal_pipe[0], &s, sizeof(s)); - r = read(signal_pipe[0], &s, sizeof(s)); - if (r == sizeof(s)) { - PARA_DEBUG_LOG("next signal: %d\n", s); - return s; + if (!r) { + PARA_CRIT_LOG("read from signal pipe returned zero\n"); + return 0; + } + if (r < 0) { + if (errno == EAGAIN || errno == EINTR) + return 0; + return -ERRNO_TO_PARA_ERROR(errno); } - return r < 0 && (errno != EAGAIN)? 0 : -E_SIGNAL_READ; + assert(r == sizeof(s)); + PARA_DEBUG_LOG("next signal: %d\n", s); + return s; } /**