}
/**
- * 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;
}
/**