diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-16 13:20:56 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-16 13:20:56 +0000 |
commit | 3718832a1542f7bf786a1678741b8566ad3a35c6 (patch) | |
tree | ac5851de53237fb3a0c77c9cead27acd279897f0 /networking | |
parent | 1e18f1bab3400246129756a35bb5752ba98f4c90 (diff) | |
download | busybox-w32-3718832a1542f7bf786a1678741b8566ad3a35c6.tar.gz busybox-w32-3718832a1542f7bf786a1678741b8566ad3a35c6.tar.bz2 busybox-w32-3718832a1542f7bf786a1678741b8566ad3a35c6.zip |
*: more readable handling of pipe fds. No code changes.
Diffstat (limited to 'networking')
-rw-r--r-- | networking/httpd.c | 8 | ||||
-rw-r--r-- | networking/ifupdown.c | 22 | ||||
-rw-r--r-- | networking/udhcp/signalpipe.c | 20 |
3 files changed, 25 insertions, 25 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index 1ac49e7a2..2c580b032 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -1305,8 +1305,8 @@ static void send_cgi_and_exit( | |||
1305 | const char *cookie, | 1305 | const char *cookie, |
1306 | const char *content_type) | 1306 | const char *content_type) |
1307 | { | 1307 | { |
1308 | struct { int rd; int wr; } fromCgi; /* CGI -> httpd pipe */ | 1308 | struct fd_pair fromCgi; /* CGI -> httpd pipe */ |
1309 | struct { int rd; int wr; } toCgi; /* httpd -> CGI pipe */ | 1309 | struct fd_pair toCgi; /* httpd -> CGI pipe */ |
1310 | char *fullpath; | 1310 | char *fullpath; |
1311 | char *script; | 1311 | char *script; |
1312 | char *purl; | 1312 | char *purl; |
@@ -1396,8 +1396,8 @@ static void send_cgi_and_exit( | |||
1396 | if (referer) | 1396 | if (referer) |
1397 | setenv1("HTTP_REFERER", referer); | 1397 | setenv1("HTTP_REFERER", referer); |
1398 | 1398 | ||
1399 | xpipe(&fromCgi.rd); | 1399 | xpiped_pair(fromCgi); |
1400 | xpipe(&toCgi.rd); | 1400 | xpiped_pair(toCgi); |
1401 | 1401 | ||
1402 | pid = vfork(); | 1402 | pid = vfork(); |
1403 | if (pid < 0) { | 1403 | if (pid < 0) { |
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index d0d7bfe5b..58e69530c 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -987,11 +987,11 @@ static int iface_down(struct interface_defn_t *iface) | |||
987 | static int popen2(FILE **in, FILE **out, char *command, char *param) | 987 | static int popen2(FILE **in, FILE **out, char *command, char *param) |
988 | { | 988 | { |
989 | char *argv[3] = { command, param, NULL }; | 989 | char *argv[3] = { command, param, NULL }; |
990 | int infd[2], outfd[2]; | 990 | struct fd_pair infd, outfd; |
991 | pid_t pid; | 991 | pid_t pid; |
992 | 992 | ||
993 | xpipe(infd); | 993 | xpiped_pair(infd); |
994 | xpipe(outfd); | 994 | xpiped_pair(outfd); |
995 | 995 | ||
996 | fflush(NULL); | 996 | fflush(NULL); |
997 | pid = fork(); | 997 | pid = fork(); |
@@ -1001,18 +1001,18 @@ static int popen2(FILE **in, FILE **out, char *command, char *param) | |||
1001 | bb_perror_msg_and_die("fork"); | 1001 | bb_perror_msg_and_die("fork"); |
1002 | case 0: /* child */ | 1002 | case 0: /* child */ |
1003 | /* NB: close _first_, then move fds! */ | 1003 | /* NB: close _first_, then move fds! */ |
1004 | close(infd[1]); | 1004 | close(infd.wr); |
1005 | close(outfd[0]); | 1005 | close(outfd.rd); |
1006 | xmove_fd(infd[0], 0); | 1006 | xmove_fd(infd.rd, 0); |
1007 | xmove_fd(outfd[1], 1); | 1007 | xmove_fd(outfd.wr, 1); |
1008 | BB_EXECVP(command, argv); | 1008 | BB_EXECVP(command, argv); |
1009 | _exit(127); | 1009 | _exit(127); |
1010 | } | 1010 | } |
1011 | /* parent */ | 1011 | /* parent */ |
1012 | close(infd[0]); | 1012 | close(infd.rd); |
1013 | close(outfd[1]); | 1013 | close(outfd.wr); |
1014 | *in = fdopen(infd[1], "w"); | 1014 | *in = fdopen(infd.wr, "w"); |
1015 | *out = fdopen(outfd[0], "r"); | 1015 | *out = fdopen(outfd.rd, "r"); |
1016 | return pid; | 1016 | return pid; |
1017 | } | 1017 | } |
1018 | 1018 | ||
diff --git a/networking/udhcp/signalpipe.c b/networking/udhcp/signalpipe.c index 845aa3a9a..918abd02d 100644 --- a/networking/udhcp/signalpipe.c +++ b/networking/udhcp/signalpipe.c | |||
@@ -23,12 +23,12 @@ | |||
23 | #include "common.h" | 23 | #include "common.h" |
24 | 24 | ||
25 | 25 | ||
26 | static int signal_pipe[2]; | 26 | static struct fd_pair signal_pipe; |
27 | 27 | ||
28 | static void signal_handler(int sig) | 28 | static void signal_handler(int sig) |
29 | { | 29 | { |
30 | unsigned char ch = sig; /* use char, avoid dealing with partial writes */ | 30 | unsigned char ch = sig; /* use char, avoid dealing with partial writes */ |
31 | if (write(signal_pipe[1], &ch, 1) != 1) | 31 | if (write(signal_pipe.wr, &ch, 1) != 1) |
32 | bb_perror_msg("cannot send signal"); | 32 | bb_perror_msg("cannot send signal"); |
33 | } | 33 | } |
34 | 34 | ||
@@ -38,10 +38,10 @@ static void signal_handler(int sig) | |||
38 | void udhcp_sp_setup(void) | 38 | void udhcp_sp_setup(void) |
39 | { | 39 | { |
40 | /* was socketpair, but it needs AF_UNIX in kernel */ | 40 | /* was socketpair, but it needs AF_UNIX in kernel */ |
41 | xpipe(signal_pipe); | 41 | xpiped_pair(signal_pipe); |
42 | close_on_exec_on(signal_pipe[0]); | 42 | close_on_exec_on(signal_pipe.rd); |
43 | close_on_exec_on(signal_pipe[1]); | 43 | close_on_exec_on(signal_pipe.wr); |
44 | ndelay_on(signal_pipe[1]); | 44 | ndelay_on(signal_pipe.wr); |
45 | signal(SIGUSR1, signal_handler); | 45 | signal(SIGUSR1, signal_handler); |
46 | signal(SIGUSR2, signal_handler); | 46 | signal(SIGUSR2, signal_handler); |
47 | signal(SIGTERM, signal_handler); | 47 | signal(SIGTERM, signal_handler); |
@@ -54,12 +54,12 @@ void udhcp_sp_setup(void) | |||
54 | int udhcp_sp_fd_set(fd_set *rfds, int extra_fd) | 54 | int udhcp_sp_fd_set(fd_set *rfds, int extra_fd) |
55 | { | 55 | { |
56 | FD_ZERO(rfds); | 56 | FD_ZERO(rfds); |
57 | FD_SET(signal_pipe[0], rfds); | 57 | FD_SET(signal_pipe.rd, rfds); |
58 | if (extra_fd >= 0) { | 58 | if (extra_fd >= 0) { |
59 | close_on_exec_on(extra_fd); | 59 | close_on_exec_on(extra_fd); |
60 | FD_SET(extra_fd, rfds); | 60 | FD_SET(extra_fd, rfds); |
61 | } | 61 | } |
62 | return signal_pipe[0] > extra_fd ? signal_pipe[0] : extra_fd; | 62 | return signal_pipe.rd > extra_fd ? signal_pipe.rd : extra_fd; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
@@ -70,10 +70,10 @@ int udhcp_sp_read(const fd_set *rfds) | |||
70 | { | 70 | { |
71 | unsigned char sig; | 71 | unsigned char sig; |
72 | 72 | ||
73 | if (!FD_ISSET(signal_pipe[0], rfds)) | 73 | if (!FD_ISSET(signal_pipe.rd, rfds)) |
74 | return 0; | 74 | return 0; |
75 | 75 | ||
76 | if (read(signal_pipe[0], &sig, 1) != 1) | 76 | if (safe_read(signal_pipe.rd, &sig, 1) != 1) |
77 | return -1; | 77 | return -1; |
78 | 78 | ||
79 | return sig; | 79 | return sig; |