diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-05-26 16:44:20 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-05-26 16:44:20 +0000 |
commit | caf6acaea106e3af96450e7e8260b530f11055f6 (patch) | |
tree | 36bf70fe7e6c67e4ab37c446a191272eb90097ed | |
parent | dc95a5501c89b98e36c298a0b19a67bd0ae73dcd (diff) | |
download | busybox-w32-caf6acaea106e3af96450e7e8260b530f11055f6.tar.gz busybox-w32-caf6acaea106e3af96450e7e8260b530f11055f6.tar.bz2 busybox-w32-caf6acaea106e3af96450e7e8260b530f11055f6.zip |
xpipe: introduce (saves ~170 bytes)
udhcp/signalpipe.c: use pipe instead of socketpair.
git-svn-id: svn://busybox.net/trunk/busybox@18695 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | archival/libunarchive/open_transformer.c | 4 | ||||
-rw-r--r-- | archival/tar.c | 4 | ||||
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/xfuncs.c | 32 | ||||
-rw-r--r-- | networking/udhcp/signalpipe.c | 13 | ||||
-rw-r--r-- | runit/runsv.c | 5 | ||||
-rw-r--r-- | runit/runsvdir.c | 2 | ||||
-rw-r--r-- | shell/hush.c | 6 | ||||
-rw-r--r-- | shell/lash.c | 3 |
9 files changed, 35 insertions, 36 deletions
diff --git a/archival/libunarchive/open_transformer.c b/archival/libunarchive/open_transformer.c index 456d3e986..58a89b918 100644 --- a/archival/libunarchive/open_transformer.c +++ b/archival/libunarchive/open_transformer.c | |||
@@ -17,9 +17,7 @@ int open_transformer(int src_fd, | |||
17 | int fd_pipe[2]; | 17 | int fd_pipe[2]; |
18 | int pid; | 18 | int pid; |
19 | 19 | ||
20 | if (pipe(fd_pipe) != 0) { | 20 | xpipe(fd_pipe); |
21 | bb_perror_msg_and_die("can't create pipe"); | ||
22 | } | ||
23 | 21 | ||
24 | pid = fork(); | 22 | pid = fork(); |
25 | if (pid == -1) { | 23 | if (pid == -1) { |
diff --git a/archival/tar.c b/archival/tar.c index 79979b05f..e634cc670 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -507,8 +507,8 @@ static int writeTarFile(const int tar_fd, const int verboseFlag, | |||
507 | volatile int vfork_exec_errno = 0; | 507 | volatile int vfork_exec_errno = 0; |
508 | const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2"; | 508 | const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2"; |
509 | 509 | ||
510 | if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0) | 510 | xpipe(gzipDataPipe); |
511 | bb_perror_msg_and_die("pipe"); | 511 | xpipe(gzipStatusPipe); |
512 | 512 | ||
513 | signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */ | 513 | signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */ |
514 | 514 | ||
diff --git a/include/libbb.h b/include/libbb.h index 1859a3f09..4561ef6a5 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -261,10 +261,10 @@ int xopen(const char *pathname, int flags); | |||
261 | int xopen3(const char *pathname, int flags, int mode); | 261 | int xopen3(const char *pathname, int flags, int mode); |
262 | int open_or_warn(const char *pathname, int flags); | 262 | int open_or_warn(const char *pathname, int flags); |
263 | int open3_or_warn(const char *pathname, int flags, int mode); | 263 | int open3_or_warn(const char *pathname, int flags, int mode); |
264 | void xpipe(int filedes[2]); | ||
264 | off_t xlseek(int fd, off_t offset, int whence); | 265 | off_t xlseek(int fd, off_t offset, int whence); |
265 | off_t fdlength(int fd); | 266 | off_t fdlength(int fd); |
266 | 267 | ||
267 | |||
268 | int xsocket(int domain, int type, int protocol); | 268 | int xsocket(int domain, int type, int protocol); |
269 | void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); | 269 | void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); |
270 | void xlisten(int s, int backlog); | 270 | void xlisten(int s, int backlog); |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index a85a046cf..4eb4737c0 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -106,7 +106,7 @@ FILE *xfopen(const char *path, const char *mode) | |||
106 | { | 106 | { |
107 | FILE *fp = fopen(path, mode); | 107 | FILE *fp = fopen(path, mode); |
108 | if (fp == NULL) | 108 | if (fp == NULL) |
109 | bb_perror_msg_and_die("cannot open '%s'", path); | 109 | bb_perror_msg_and_die("can't open '%s'", path); |
110 | return fp; | 110 | return fp; |
111 | } | 111 | } |
112 | 112 | ||
@@ -117,7 +117,7 @@ int xopen3(const char *pathname, int flags, int mode) | |||
117 | 117 | ||
118 | ret = open(pathname, flags, mode); | 118 | ret = open(pathname, flags, mode); |
119 | if (ret < 0) { | 119 | if (ret < 0) { |
120 | bb_perror_msg_and_die("cannot open '%s'", pathname); | 120 | bb_perror_msg_and_die("can't open '%s'", pathname); |
121 | } | 121 | } |
122 | return ret; | 122 | return ret; |
123 | } | 123 | } |
@@ -135,7 +135,7 @@ int open3_or_warn(const char *pathname, int flags, int mode) | |||
135 | 135 | ||
136 | ret = open(pathname, flags, mode); | 136 | ret = open(pathname, flags, mode); |
137 | if (ret < 0) { | 137 | if (ret < 0) { |
138 | bb_perror_msg("cannot open '%s'", pathname); | 138 | bb_perror_msg("can't open '%s'", pathname); |
139 | } | 139 | } |
140 | return ret; | 140 | return ret; |
141 | } | 141 | } |
@@ -146,21 +146,27 @@ int open_or_warn(const char *pathname, int flags) | |||
146 | return open3_or_warn(pathname, flags, 0666); | 146 | return open3_or_warn(pathname, flags, 0666); |
147 | } | 147 | } |
148 | 148 | ||
149 | void xpipe(int filedes[2]) | ||
150 | { | ||
151 | if (pipe(filedes)) | ||
152 | bb_perror_msg_and_die("can't create pipe"); | ||
153 | } | ||
154 | |||
149 | void xunlink(const char *pathname) | 155 | void xunlink(const char *pathname) |
150 | { | 156 | { |
151 | if (unlink(pathname)) | 157 | if (unlink(pathname)) |
152 | bb_perror_msg_and_die("cannot remove file '%s'", pathname); | 158 | bb_perror_msg_and_die("can't remove file '%s'", pathname); |
153 | } | 159 | } |
154 | 160 | ||
155 | // Turn on nonblocking I/O on a fd | 161 | // Turn on nonblocking I/O on a fd |
156 | int ndelay_on(int fd) | 162 | int ndelay_on(int fd) |
157 | { | 163 | { |
158 | return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) | O_NONBLOCK); | 164 | return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL,0) | O_NONBLOCK); |
159 | } | 165 | } |
160 | 166 | ||
161 | int ndelay_off(int fd) | 167 | int ndelay_off(int fd) |
162 | { | 168 | { |
163 | return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) & ~O_NONBLOCK); | 169 | return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL,0) & ~O_NONBLOCK); |
164 | } | 170 | } |
165 | 171 | ||
166 | // "Renumber" opened fd | 172 | // "Renumber" opened fd |
@@ -169,7 +175,7 @@ void xmove_fd(int from, int to) | |||
169 | if (from == to) | 175 | if (from == to) |
170 | return; | 176 | return; |
171 | if (dup2(from, to) != to) | 177 | if (dup2(from, to) != to) |
172 | bb_perror_msg_and_die("cannot duplicate file descriptor"); | 178 | bb_perror_msg_and_die("can't duplicate file descriptor"); |
173 | close(from); | 179 | close(from); |
174 | } | 180 | } |
175 | 181 | ||
@@ -199,7 +205,7 @@ off_t xlseek(int fd, off_t offset, int whence) | |||
199 | void die_if_ferror(FILE *fp, const char *fn) | 205 | void die_if_ferror(FILE *fp, const char *fn) |
200 | { | 206 | { |
201 | if (ferror(fp)) { | 207 | if (ferror(fp)) { |
202 | /* doesn't set useful errno */ | 208 | /* ferror doesn't set useful errno */ |
203 | bb_error_msg_and_die("%s: I/O error", fn); | 209 | bb_error_msg_and_die("%s: I/O error", fn); |
204 | } | 210 | } |
205 | } | 211 | } |
@@ -520,7 +526,7 @@ DIR *warn_opendir(const char *path) | |||
520 | 526 | ||
521 | dp = opendir(path); | 527 | dp = opendir(path); |
522 | if (!dp) | 528 | if (!dp) |
523 | bb_perror_msg("cannot open '%s'", path); | 529 | bb_perror_msg("can't open '%s'", path); |
524 | return dp; | 530 | return dp; |
525 | } | 531 | } |
526 | 532 | ||
@@ -531,7 +537,7 @@ DIR *xopendir(const char *path) | |||
531 | 537 | ||
532 | dp = opendir(path); | 538 | dp = opendir(path); |
533 | if (!dp) | 539 | if (!dp) |
534 | bb_perror_msg_and_die("cannot open '%s'", path); | 540 | bb_perror_msg_and_die("can't open '%s'", path); |
535 | return dp; | 541 | return dp; |
536 | } | 542 | } |
537 | 543 | ||
@@ -568,10 +574,8 @@ void xlisten(int s, int backlog) | |||
568 | if (listen(s, backlog)) bb_perror_msg_and_die("listen"); | 574 | if (listen(s, backlog)) bb_perror_msg_and_die("listen"); |
569 | } | 575 | } |
570 | 576 | ||
571 | /* Die with an error message if we the sendto failed. | 577 | /* Die with an error message if sendto failed. |
572 | * Return bytes sent otherwise | 578 | * Return bytes sent otherwise */ |
573 | */ | ||
574 | |||
575 | ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, | 579 | ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, |
576 | socklen_t tolen) | 580 | socklen_t tolen) |
577 | { | 581 | { |
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; |
diff --git a/runit/runsv.c b/runit/runsv.c index bd4a81eee..d5bfd4e89 100644 --- a/runit/runsv.c +++ b/runit/runsv.c | |||
@@ -420,7 +420,7 @@ int runsv_main(int argc, char **argv) | |||
420 | if (!argv[1] || argv[2]) usage(); | 420 | if (!argv[1] || argv[2]) usage(); |
421 | dir = argv[1]; | 421 | dir = argv[1]; |
422 | 422 | ||
423 | if (pipe(selfpipe) == -1) fatal_cannot("create selfpipe"); | 423 | xpipe(selfpipe); |
424 | coe(selfpipe[0]); | 424 | coe(selfpipe[0]); |
425 | coe(selfpipe[1]); | 425 | coe(selfpipe[1]); |
426 | ndelay_on(selfpipe[0]); | 426 | ndelay_on(selfpipe[0]); |
@@ -456,8 +456,7 @@ int runsv_main(int argc, char **argv) | |||
456 | taia_now(&svd[1].start); | 456 | taia_now(&svd[1].start); |
457 | if (stat("log/down", &s) != -1) | 457 | if (stat("log/down", &s) != -1) |
458 | svd[1].want = W_DOWN; | 458 | svd[1].want = W_DOWN; |
459 | if (pipe(logpipe) == -1) | 459 | xpipe(logpipe); |
460 | fatal_cannot("create log pipe"); | ||
461 | coe(logpipe[0]); | 460 | coe(logpipe[0]); |
462 | coe(logpipe[1]); | 461 | coe(logpipe[1]); |
463 | } | 462 | } |
diff --git a/runit/runsvdir.c b/runit/runsvdir.c index 39929fc49..4b94aa211 100644 --- a/runit/runsvdir.c +++ b/runit/runsvdir.c | |||
@@ -184,7 +184,7 @@ static int setup_log(void) | |||
184 | warnx("log must have at least seven characters"); | 184 | warnx("log must have at least seven characters"); |
185 | return 0; | 185 | return 0; |
186 | } | 186 | } |
187 | if (pipe(logpipe) == -1) { | 187 | if (pipe(logpipe)) { |
188 | warnx("cannot create pipe for log"); | 188 | warnx("cannot create pipe for log"); |
189 | return -1; | 189 | return -1; |
190 | } | 190 | } |
diff --git a/shell/hush.c b/shell/hush.c index 800b0f970..2e6f286dc 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -1800,8 +1800,7 @@ static int run_pipe_real(struct pipe *pi) | |||
1800 | 1800 | ||
1801 | /* pipes are inserted between pairs of commands */ | 1801 | /* pipes are inserted between pairs of commands */ |
1802 | if ((i + 1) < pi->num_progs) { | 1802 | if ((i + 1) < pi->num_progs) { |
1803 | if (pipe(pipefds) < 0) | 1803 | pipe(pipefds); |
1804 | bb_perror_msg_and_die("pipe"); | ||
1805 | nextout = pipefds[1]; | 1804 | nextout = pipefds[1]; |
1806 | } else { | 1805 | } else { |
1807 | nextout = 1; | 1806 | nextout = 1; |
@@ -3134,8 +3133,7 @@ static FILE *generate_stream_from_list(struct pipe *head) | |||
3134 | FILE *pf; | 3133 | FILE *pf; |
3135 | int pid, channel[2]; | 3134 | int pid, channel[2]; |
3136 | 3135 | ||
3137 | if (pipe(channel) < 0) | 3136 | xpipe(channel); |
3138 | bb_perror_msg_and_die("pipe"); | ||
3139 | #if BB_MMU | 3137 | #if BB_MMU |
3140 | pid = fork(); | 3138 | pid = fork(); |
3141 | #else | 3139 | #else |
diff --git a/shell/lash.c b/shell/lash.c index 24e48c337..28449b791 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
@@ -1222,8 +1222,7 @@ static int run_command(struct job *newjob, int inbg, int outpipe[2]) | |||
1222 | 1222 | ||
1223 | nextout = 1; | 1223 | nextout = 1; |
1224 | if ((i + 1) < newjob->num_progs) { | 1224 | if ((i + 1) < newjob->num_progs) { |
1225 | if (pipe(pipefds) < 0) | 1225 | xpipe(pipefds); |
1226 | bb_perror_msg_and_die("pipe"); | ||
1227 | nextout = pipefds[1]; | 1226 | nextout = pipefds[1]; |
1228 | } else if (outpipe[1] != -1) { | 1227 | } else if (outpipe[1] != -1) { |
1229 | nextout = outpipe[1]; | 1228 | nextout = outpipe[1]; |