aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-16 13:20:56 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-16 13:20:56 +0000
commit3718832a1542f7bf786a1678741b8566ad3a35c6 (patch)
treeac5851de53237fb3a0c77c9cead27acd279897f0 /networking
parent1e18f1bab3400246129756a35bb5752ba98f4c90 (diff)
downloadbusybox-3718832a1542f7bf786a1678741b8566ad3a35c6.tar.gz
*: more readable handling of pipe fds. No code changes.
Diffstat (limited to 'networking')
-rw-r--r--networking/httpd.c8
-rw-r--r--networking/ifupdown.c22
-rw-r--r--networking/udhcp/signalpipe.c20
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(
const char *cookie,
const char *content_type)
{
- struct { int rd; int wr; } fromCgi; /* CGI -> httpd pipe */
- struct { int rd; int wr; } toCgi; /* httpd -> CGI pipe */
+ struct fd_pair fromCgi; /* CGI -> httpd pipe */
+ struct fd_pair toCgi; /* httpd -> CGI pipe */
char *fullpath;
char *script;
char *purl;
@@ -1396,8 +1396,8 @@ static void send_cgi_and_exit(
if (referer)
setenv1("HTTP_REFERER", referer);
- xpipe(&fromCgi.rd);
- xpipe(&toCgi.rd);
+ xpiped_pair(fromCgi);
+ xpiped_pair(toCgi);
pid = vfork();
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)
static int popen2(FILE **in, FILE **out, char *command, char *param)
{
char *argv[3] = { command, param, NULL };
- int infd[2], outfd[2];
+ struct fd_pair infd, outfd;
pid_t pid;
- xpipe(infd);
- xpipe(outfd);
+ xpiped_pair(infd);
+ xpiped_pair(outfd);
fflush(NULL);
pid = fork();
@@ -1001,18 +1001,18 @@ static int popen2(FILE **in, FILE **out, char *command, char *param)
bb_perror_msg_and_die("fork");
case 0: /* child */
/* NB: close _first_, then move fds! */
- close(infd[1]);
- close(outfd[0]);
- xmove_fd(infd[0], 0);
- xmove_fd(outfd[1], 1);
+ close(infd.wr);
+ close(outfd.rd);
+ xmove_fd(infd.rd, 0);
+ xmove_fd(outfd.wr, 1);
BB_EXECVP(command, argv);
_exit(127);
}
/* parent */
- close(infd[0]);
- close(outfd[1]);
- *in = fdopen(infd[1], "w");
- *out = fdopen(outfd[0], "r");
+ close(infd.rd);
+ close(outfd.wr);
+ *in = fdopen(infd.wr, "w");
+ *out = fdopen(outfd.rd, "r");
return pid;
}
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 @@
#include "common.h"
-static int signal_pipe[2];
+static struct fd_pair signal_pipe;
static void signal_handler(int sig)
{
unsigned char ch = sig; /* use char, avoid dealing with partial writes */
- if (write(signal_pipe[1], &ch, 1) != 1)
+ if (write(signal_pipe.wr, &ch, 1) != 1)
bb_perror_msg("cannot send signal");
}
@@ -38,10 +38,10 @@ static void signal_handler(int sig)
void udhcp_sp_setup(void)
{
/* was socketpair, but it needs AF_UNIX in kernel */
- xpipe(signal_pipe);
- close_on_exec_on(signal_pipe[0]);
- close_on_exec_on(signal_pipe[1]);
- ndelay_on(signal_pipe[1]);
+ xpiped_pair(signal_pipe);
+ close_on_exec_on(signal_pipe.rd);
+ close_on_exec_on(signal_pipe.wr);
+ ndelay_on(signal_pipe.wr);
signal(SIGUSR1, signal_handler);
signal(SIGUSR2, signal_handler);
signal(SIGTERM, signal_handler);
@@ -54,12 +54,12 @@ void udhcp_sp_setup(void)
int udhcp_sp_fd_set(fd_set *rfds, int extra_fd)
{
FD_ZERO(rfds);
- FD_SET(signal_pipe[0], rfds);
+ FD_SET(signal_pipe.rd, rfds);
if (extra_fd >= 0) {
close_on_exec_on(extra_fd);
FD_SET(extra_fd, rfds);
}
- return signal_pipe[0] > extra_fd ? signal_pipe[0] : extra_fd;
+ return signal_pipe.rd > extra_fd ? signal_pipe.rd : extra_fd;
}
@@ -70,10 +70,10 @@ int udhcp_sp_read(const fd_set *rfds)
{
unsigned char sig;
- if (!FD_ISSET(signal_pipe[0], rfds))
+ if (!FD_ISSET(signal_pipe.rd, rfds))
return 0;
- if (read(signal_pipe[0], &sig, 1) != 1)
+ if (safe_read(signal_pipe.rd, &sig, 1) != 1)
return -1;
return sig;