From: Roy Marples Date: Sat, 7 Jun 2008 00:14:16 +0000 (+0000) Subject: We should test a specific fd instead of index 0 in a structure. X-Git-Tag: v4.0.2~293 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c45fb9338092de7ca988f6abbecd4b0d54d76cc;p=thirdparty%2Fdhcpcd.git We should test a specific fd instead of index 0 in a structure. --- diff --git a/signals.c b/signals.c index 4559749c..3d7f63cd 100644 --- a/signals.c +++ b/signals.c @@ -73,9 +73,9 @@ signal_fd(void) /* Check if we have a signal or not */ int -signal_exists(const struct pollfd *fd) +signal_exists(int fd) { - if (signals[0] || (fd && fd->revents & POLLIN)) + if (signals[0] || fd_hasdata(fd) == 1) return 0; return -1; } @@ -84,7 +84,7 @@ signal_exists(const struct pollfd *fd) * no signal, -1 on error (and sets errno appropriately), and * your signal on success */ int -signal_read(struct pollfd *fd) +signal_read(int fd) { int sig = -1; unsigned int i = 0; @@ -101,19 +101,12 @@ signal_read(struct pollfd *fd) } } - if (fd && fd->revents & POLLIN) { + if (fd_hasdata(fd) == 1) { memset(buf, 0, sizeof(buf)); bytes = read(signal_pipe[0], buf, sizeof(buf)); - if (bytes >= sizeof(sig)) memcpy(&sig, buf, sizeof(sig)); - - /* We need to clear us from rset if nothing left in the buffer - * in case we are called many times */ - if (bytes == sizeof(sig)) - fd->revents = 0; } - return sig; } diff --git a/signals.h b/signals.h index 948099d2..5972b311 100644 --- a/signals.h +++ b/signals.h @@ -34,7 +34,7 @@ int signal_init(void); int signal_setup(void); int signal_reset(void); int signal_fd(void); -int signal_exists(const struct pollfd *); -int signal_read(struct pollfd *); +int signal_exists(int fd); +int signal_read(int fd); #endif