aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/signalpipe.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/signalpipe.c')
-rw-r--r--networking/udhcp/signalpipe.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/networking/udhcp/signalpipe.c b/networking/udhcp/signalpipe.c
index 6355c5e90..b101b4ce4 100644
--- a/networking/udhcp/signalpipe.c
+++ b/networking/udhcp/signalpipe.c
@@ -25,9 +25,11 @@ static struct fd_pair signal_pipe;
25 25
26static void signal_handler(int sig) 26static void signal_handler(int sig)
27{ 27{
28 int sv = errno;
28 unsigned char ch = sig; /* use char, avoid dealing with partial writes */ 29 unsigned char ch = sig; /* use char, avoid dealing with partial writes */
29 if (write(signal_pipe.wr, &ch, 1) != 1) 30 if (write(signal_pipe.wr, &ch, 1) != 1)
30 bb_perror_msg("can't send signal"); 31 bb_perror_msg("can't send signal");
32 errno = sv;
31} 33}
32 34
33/* Call this before doing anything else. Sets up the socket pair 35/* Call this before doing anything else. Sets up the socket pair
@@ -46,28 +48,29 @@ void FAST_FUNC udhcp_sp_setup(void)
46 , signal_handler); 48 , signal_handler);
47} 49}
48 50
49/* Quick little function to setup the rfds. Will return the 51/* Quick little function to setup the pfds.
50 * max_fd for use with select. Limited in that you can only pass 52 * Limited in that you can only pass one extra fd.
51 * one extra fd */ 53 */
52int FAST_FUNC udhcp_sp_fd_set(fd_set *rfds, int extra_fd) 54void FAST_FUNC udhcp_sp_fd_set(struct pollfd pfds[2], int extra_fd)
53{ 55{
54 FD_ZERO(rfds); 56 pfds[0].fd = signal_pipe.rd;
55 FD_SET(signal_pipe.rd, rfds); 57 pfds[0].events = POLLIN;
58 pfds[1].fd = -1;
56 if (extra_fd >= 0) { 59 if (extra_fd >= 0) {
57 close_on_exec_on(extra_fd); 60 close_on_exec_on(extra_fd);
58 FD_SET(extra_fd, rfds); 61 pfds[1].fd = extra_fd;
62 pfds[1].events = POLLIN;
59 } 63 }
60 return signal_pipe.rd > extra_fd ? signal_pipe.rd : extra_fd;
61} 64}
62 65
63/* Read a signal from the signal pipe. Returns 0 if there is 66/* Read a signal from the signal pipe. Returns 0 if there is
64 * no signal, -1 on error (and sets errno appropriately), and 67 * no signal, -1 on error (and sets errno appropriately), and
65 * your signal on success */ 68 * your signal on success */
66int FAST_FUNC udhcp_sp_read(const fd_set *rfds) 69int FAST_FUNC udhcp_sp_read(struct pollfd pfds[2])
67{ 70{
68 unsigned char sig; 71 unsigned char sig;
69 72
70 if (!FD_ISSET(signal_pipe.rd, rfds)) 73 if (!pfds[0].revents)
71 return 0; 74 return 0;
72 75
73 if (safe_read(signal_pipe.rd, &sig, 1) != 1) 76 if (safe_read(signal_pipe.rd, &sig, 1) != 1)