diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-26 16:44:20 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-26 16:44:20 +0000 |
commit | 5a6aeddfa7262e41802c77f70c9ef88e9c2c2476 (patch) | |
tree | 36bf70fe7e6c67e4ab37c446a191272eb90097ed /networking | |
parent | 6239b1f50a04121d96daba2cdc2f7c3765c9007b (diff) | |
download | busybox-w32-5a6aeddfa7262e41802c77f70c9ef88e9c2c2476.tar.gz busybox-w32-5a6aeddfa7262e41802c77f70c9ef88e9c2c2476.tar.bz2 busybox-w32-5a6aeddfa7262e41802c77f70c9ef88e9c2c2476.zip |
xpipe: introduce (saves ~170 bytes)
udhcp/signalpipe.c: use pipe instead of socketpair.
Diffstat (limited to 'networking')
-rw-r--r-- | networking/udhcp/signalpipe.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/networking/udhcp/signalpipe.c b/networking/udhcp/signalpipe.c index d52a931a9..9c7ead965 100644 --- a/networking/udhcp/signalpipe.c +++ b/networking/udhcp/signalpipe.c | |||
@@ -27,7 +27,8 @@ static int signal_pipe[2]; | |||
27 | 27 | ||
28 | static void signal_handler(int sig) | 28 | static void signal_handler(int sig) |
29 | { | 29 | { |
30 | if (send(signal_pipe[1], &sig, sizeof(sig), MSG_DONTWAIT) < 0) | 30 | unsigned char ch = sig; /* use char, avoid dealing with partial writes */ |
31 | if (write(signal_pipe[1], &ch, 1) != 1) | ||
31 | bb_perror_msg("cannot send signal"); | 32 | bb_perror_msg("cannot send signal"); |
32 | } | 33 | } |
33 | 34 | ||
@@ -36,11 +37,11 @@ static void signal_handler(int sig) | |||
36 | * and installs the signal handler */ | 37 | * and installs the signal handler */ |
37 | void udhcp_sp_setup(void) | 38 | void udhcp_sp_setup(void) |
38 | { | 39 | { |
39 | // BTW, why socketpair and not just pipe? | 40 | /* was socketpair, but it needs AF_UNIX in kernel */ |
40 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, signal_pipe)) | 41 | xpipe(signal_pipe); |
41 | bb_perror_msg_and_die("socketpair"); | ||
42 | fcntl(signal_pipe[0], F_SETFD, FD_CLOEXEC); | 42 | fcntl(signal_pipe[0], F_SETFD, FD_CLOEXEC); |
43 | fcntl(signal_pipe[1], F_SETFD, FD_CLOEXEC); | 43 | fcntl(signal_pipe[1], F_SETFD, FD_CLOEXEC); |
44 | fcntl(signal_pipe[1], F_SETFL, O_NONBLOCK); | ||
44 | signal(SIGUSR1, signal_handler); | 45 | signal(SIGUSR1, signal_handler); |
45 | signal(SIGUSR2, signal_handler); | 46 | signal(SIGUSR2, signal_handler); |
46 | signal(SIGTERM, signal_handler); | 47 | signal(SIGTERM, signal_handler); |
@@ -67,12 +68,12 @@ int udhcp_sp_fd_set(fd_set *rfds, int extra_fd) | |||
67 | * your signal on success */ | 68 | * your signal on success */ |
68 | int udhcp_sp_read(fd_set *rfds) | 69 | int udhcp_sp_read(fd_set *rfds) |
69 | { | 70 | { |
70 | int sig; | 71 | unsigned char sig; |
71 | 72 | ||
72 | if (!FD_ISSET(signal_pipe[0], rfds)) | 73 | if (!FD_ISSET(signal_pipe[0], rfds)) |
73 | return 0; | 74 | return 0; |
74 | 75 | ||
75 | if (read(signal_pipe[0], &sig, sizeof(sig)) < 0) | 76 | if (read(signal_pipe[0], &sig, 1) != 1) |
76 | return -1; | 77 | return -1; |
77 | 78 | ||
78 | return sig; | 79 | return sig; |