From bdf3b7573b4a2ef6a84bdf34442063b32977f54e Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 17 Mar 2008 07:34:29 +0100 Subject: [PATCH] Fix para_next_signal(). The function returned zero in case of errors.. --- signal.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) 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; } /** -- 2.39.2