aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archival/libunarchive/open_transformer.c16
-rw-r--r--archival/libunarchive/seek_by_jump.c2
-rw-r--r--archival/libunarchive/seek_by_read.c4
-rw-r--r--archival/tar.c8
-rw-r--r--include/libbb.h7
-rw-r--r--include/unarchive.h4
-rw-r--r--miscutils/crontab.c12
-rw-r--r--networking/httpd.c8
-rw-r--r--networking/ifupdown.c22
-rw-r--r--networking/udhcp/signalpipe.c20
-rw-r--r--runit/runsv.c47
-rw-r--r--runit/runsvdir.c20
12 files changed, 88 insertions, 82 deletions
diff --git a/archival/libunarchive/open_transformer.c b/archival/libunarchive/open_transformer.c
index d6f5e6271..3c551de06 100644
--- a/archival/libunarchive/open_transformer.c
+++ b/archival/libunarchive/open_transformer.c
@@ -15,10 +15,10 @@ int open_transformer(int src_fd,
15 USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd), 15 USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd),
16 const char *transform_prog) 16 const char *transform_prog)
17{ 17{
18 int fd_pipe[2]; 18 struct fd_pair fd_pipe;
19 int pid; 19 int pid;
20 20
21 xpipe(fd_pipe); 21 xpiped_pair(fd_pipe);
22 22
23#if BB_MMU 23#if BB_MMU
24 pid = fork(); 24 pid = fork();
@@ -30,12 +30,12 @@ int open_transformer(int src_fd,
30 30
31 if (pid == 0) { 31 if (pid == 0) {
32 /* child process */ 32 /* child process */
33 close(fd_pipe[0]); /* We don't want to read from the parent */ 33 close(fd_pipe.rd); /* We don't want to read from the parent */
34 // FIXME: error check? 34 // FIXME: error check?
35#if BB_MMU 35#if BB_MMU
36 transformer(src_fd, fd_pipe[1]); 36 transformer(src_fd, fd_pipe.wr);
37 if (ENABLE_FEATURE_CLEAN_UP) { 37 if (ENABLE_FEATURE_CLEAN_UP) {
38 close(fd_pipe[1]); /* Send EOF */ 38 close(fd_pipe.wr); /* Send EOF */
39 close(src_fd); 39 close(src_fd);
40 } 40 }
41 exit(0); 41 exit(0);
@@ -43,7 +43,7 @@ int open_transformer(int src_fd,
43 { 43 {
44 char *argv[4]; 44 char *argv[4];
45 xmove_fd(src_fd, 0); 45 xmove_fd(src_fd, 0);
46 xmove_fd(fd_pipe[1], 1); 46 xmove_fd(fd_pipe.wr, 1);
47 argv[0] = (char*)transform_prog; 47 argv[0] = (char*)transform_prog;
48 argv[1] = (char*)"-cf"; 48 argv[1] = (char*)"-cf";
49 argv[2] = (char*)"-"; 49 argv[2] = (char*)"-";
@@ -56,7 +56,7 @@ int open_transformer(int src_fd,
56 } 56 }
57 57
58 /* parent process */ 58 /* parent process */
59 close(fd_pipe[1]); /* Don't want to write to the child */ 59 close(fd_pipe.wr); /* Don't want to write to the child */
60 60
61 return fd_pipe[0]; 61 return fd_pipe.rd;
62} 62}
diff --git a/archival/libunarchive/seek_by_jump.c b/archival/libunarchive/seek_by_jump.c
index edbf46b21..8b5f3e887 100644
--- a/archival/libunarchive/seek_by_jump.c
+++ b/archival/libunarchive/seek_by_jump.c
@@ -6,7 +6,7 @@
6#include "libbb.h" 6#include "libbb.h"
7#include "unarchive.h" 7#include "unarchive.h"
8 8
9void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amount) 9void seek_by_jump(const archive_handle_t *archive_handle, unsigned amount)
10{ 10{
11 if (lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1) { 11 if (lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1) {
12#if ENABLE_FEATURE_UNARCHIVE_TAPE 12#if ENABLE_FEATURE_UNARCHIVE_TAPE
diff --git a/archival/libunarchive/seek_by_read.c b/archival/libunarchive/seek_by_read.c
index 452d82d10..1f2b80571 100644
--- a/archival/libunarchive/seek_by_read.c
+++ b/archival/libunarchive/seek_by_read.c
@@ -6,10 +6,10 @@
6#include "libbb.h" 6#include "libbb.h"
7#include "unarchive.h" 7#include "unarchive.h"
8 8
9/* If we are reading through a pipe(), or from stdin then we can't lseek, 9/* If we are reading through a pipe, or from stdin then we can't lseek,
10 * we must read and discard the data to skip over it. 10 * we must read and discard the data to skip over it.
11 */ 11 */
12void seek_by_read(const archive_handle_t *archive_handle, const unsigned int jump_size) 12void seek_by_read(const archive_handle_t *archive_handle, unsigned jump_size)
13{ 13{
14 if (jump_size) 14 if (jump_size)
15 bb_copyfd_exact_size(archive_handle->src_fd, -1, jump_size); 15 bb_copyfd_exact_size(archive_handle->src_fd, -1, jump_size);
diff --git a/archival/tar.c b/archival/tar.c
index a8ff7b894..4ec454b88 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -521,14 +521,14 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
521 521
522 volatile int vfork_exec_errno = 0; 522 volatile int vfork_exec_errno = 0;
523#if WAIT_FOR_CHILD 523#if WAIT_FOR_CHILD
524 struct { int rd; int wr; } gzipStatusPipe; 524 struct fd_pair gzipStatusPipe;
525#endif 525#endif
526 struct { int rd; int wr; } gzipDataPipe; 526 struct fd_pair gzipDataPipe;
527 const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2"; 527 const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
528 528
529 xpipe(&gzipDataPipe.rd); 529 xpiped_pair(gzipDataPipe);
530#if WAIT_FOR_CHILD 530#if WAIT_FOR_CHILD
531 xpipe(&gzipStatusPipe.rd); 531 xpiped_pair(gzipStatusPipe);
532#endif 532#endif
533 533
534 signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */ 534 signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
diff --git a/include/libbb.h b/include/libbb.h
index 3175c8e7f..f505cc718 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -294,10 +294,15 @@ int xopen(const char *pathname, int flags);
294int xopen3(const char *pathname, int flags, int mode); 294int xopen3(const char *pathname, int flags, int mode);
295int open_or_warn(const char *pathname, int flags); 295int open_or_warn(const char *pathname, int flags);
296int open3_or_warn(const char *pathname, int flags, int mode); 296int open3_or_warn(const char *pathname, int flags, int mode);
297void xpipe(int filedes[2]);
298off_t xlseek(int fd, off_t offset, int whence); 297off_t xlseek(int fd, off_t offset, int whence);
299off_t fdlength(int fd); 298off_t fdlength(int fd);
300 299
300void xpipe(int filedes[2]);
301/* In this form code with pipes is much more readable */
302struct fd_pair { int rd; int wr; };
303#define piped_pair(pair) pipe(&((pair).rd))
304#define xpiped_pair(pair) xpipe(&((pair).rd))
305
301/* Useful for having small structure members/global variables */ 306/* Useful for having small structure members/global variables */
302typedef int8_t socktype_t; 307typedef int8_t socktype_t;
303typedef int8_t family_t; 308typedef int8_t family_t;
diff --git a/include/unarchive.h b/include/unarchive.h
index 8b76217b4..bfd6488db 100644
--- a/include/unarchive.h
+++ b/include/unarchive.h
@@ -92,8 +92,8 @@ extern char get_header_tar_bz2(archive_handle_t *archive_handle);
92extern char get_header_tar_lzma(archive_handle_t *archive_handle); 92extern char get_header_tar_lzma(archive_handle_t *archive_handle);
93extern char get_header_tar_gz(archive_handle_t *archive_handle); 93extern char get_header_tar_gz(archive_handle_t *archive_handle);
94 94
95extern void seek_by_jump(const archive_handle_t *archive_handle, const unsigned amount); 95extern void seek_by_jump(const archive_handle_t *archive_handle, unsigned amount);
96extern void seek_by_read(const archive_handle_t *archive_handle, const unsigned amount); 96extern void seek_by_read(const archive_handle_t *archive_handle, unsigned amount);
97 97
98extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *buf, size_t count); 98extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *buf, size_t count);
99 99
diff --git a/miscutils/crontab.c b/miscutils/crontab.c
index 71037b7ee..b292535b1 100644
--- a/miscutils/crontab.c
+++ b/miscutils/crontab.c
@@ -70,18 +70,18 @@ static void edit_file(const struct passwd *pas, const char *file)
70 70
71static int open_as_user(const struct passwd *pas, const char *file) 71static int open_as_user(const struct passwd *pas, const char *file)
72{ 72{
73 int filedes[2]; 73 struct fd_pair filedes;
74 pid_t pid; 74 pid_t pid;
75 char c; 75 char c;
76 76
77 xpipe(filedes); 77 xpiped_pair(filedes);
78 pid = vfork(); 78 pid = vfork();
79 if (pid < 0) /* ERROR */ 79 if (pid < 0) /* ERROR */
80 bb_perror_msg_and_die("vfork"); 80 bb_perror_msg_and_die("vfork");
81 if (pid) { /* PARENT */ 81 if (pid) { /* PARENT */
82 int n = safe_read(filedes[0], &c, 1); 82 int n = safe_read(filedes.rd, &c, 1);
83 close(filedes[0]); 83 close(filedes.rd);
84 close(filedes[1]); 84 close(filedes.wr);
85 if (n > 0) /* child says it can read */ 85 if (n > 0) /* child says it can read */
86 return open(file, O_RDONLY); 86 return open(file, O_RDONLY);
87 return -1; 87 return -1;
@@ -95,7 +95,7 @@ static int open_as_user(const struct passwd *pas, const char *file)
95 /* We just try to read one byte. If that works, file is readable 95 /* We just try to read one byte. If that works, file is readable
96 * under this user. We signal that by sending one byte to parent. */ 96 * under this user. We signal that by sending one byte to parent. */
97 if (safe_read(xopen(file, O_RDONLY), &c, 1) == 1) 97 if (safe_read(xopen(file, O_RDONLY), &c, 1) == 1)
98 safe_write(filedes[1], &c, 1); /* "papa, I can read!" */ 98 safe_write(filedes.wr, &c, 1); /* "papa, I can read!" */
99 _exit(0); 99 _exit(0);
100} 100}
101 101
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)
987static int popen2(FILE **in, FILE **out, char *command, char *param) 987static 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
26static int signal_pipe[2]; 26static struct fd_pair signal_pipe;
27 27
28static void signal_handler(int sig) 28static 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)
38void udhcp_sp_setup(void) 38void 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)
54int udhcp_sp_fd_set(fd_set *rfds, int extra_fd) 54int 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;
diff --git a/runit/runsv.c b/runit/runsv.c
index e9a074580..e1d99e2df 100644
--- a/runit/runsv.c
+++ b/runit/runsv.c
@@ -90,8 +90,8 @@ struct globals {
90 smallint haslog; 90 smallint haslog;
91 smallint sigterm; 91 smallint sigterm;
92 smallint pidchanged; 92 smallint pidchanged;
93 int selfpipe[2]; 93 struct fd_pair selfpipe;
94 int logpipe[2]; 94 struct fd_pair logpipe;
95 char *dir; 95 char *dir;
96 struct svdir svd[2]; 96 struct svdir svd[2];
97}; 97};
@@ -130,13 +130,13 @@ static void warn_cannot(const char *m)
130 130
131static void s_child(int sig_no) 131static void s_child(int sig_no)
132{ 132{
133 write(selfpipe[1], "", 1); 133 write(selfpipe.wr, "", 1);
134} 134}
135 135
136static void s_term(int sig_no) 136static void s_term(int sig_no)
137{ 137{
138 sigterm = 1; 138 sigterm = 1;
139 write(selfpipe[1], "", 1); /* XXX */ 139 write(selfpipe.wr, "", 1); /* XXX */
140} 140}
141 141
142static char *add_str(char *p, const char *to_add) 142static char *add_str(char *p, const char *to_add)
@@ -275,7 +275,7 @@ static unsigned custom(struct svdir *s, char c)
275 return 0; 275 return 0;
276 } 276 }
277 if (!pid) { 277 if (!pid) {
278 if (haslog && dup2(logpipe[1], 1) == -1) 278 if (haslog && dup2(logpipe.wr, 1) == -1)
279 warn_cannot("setup stdout for control/?"); 279 warn_cannot("setup stdout for control/?");
280 prog[0] = a; 280 prog[0] = a;
281 prog[1] = NULL; 281 prog[1] = NULL;
@@ -335,13 +335,14 @@ static void startservice(struct svdir *s)
335 if (p == 0) { 335 if (p == 0) {
336 /* child */ 336 /* child */
337 if (haslog) { 337 if (haslog) {
338 /* NB: bug alert! right order is close, then dup2 */
338 if (s->islog) { 339 if (s->islog) {
339 xdup2(logpipe[0], 0);
340 close(logpipe[1]);
341 xchdir("./log"); 340 xchdir("./log");
341 close(logpipe.wr);
342 xdup2(logpipe.rd, 0);
342 } else { 343 } else {
343 xdup2(logpipe[1], 1); 344 close(logpipe.rd);
344 close(logpipe[0]); 345 xdup2(logpipe.wr, 1);
345 } 346 }
346 } 347 }
347 signal(SIGCHLD, SIG_DFL); 348 signal(SIGCHLD, SIG_DFL);
@@ -452,11 +453,11 @@ int runsv_main(int argc, char **argv)
452 bb_show_usage(); 453 bb_show_usage();
453 dir = argv[1]; 454 dir = argv[1];
454 455
455 xpipe(selfpipe); 456 xpiped_pair(selfpipe);
456 close_on_exec_on(selfpipe[0]); 457 close_on_exec_on(selfpipe.rd);
457 close_on_exec_on(selfpipe[1]); 458 close_on_exec_on(selfpipe.wr);
458 ndelay_on(selfpipe[0]); 459 ndelay_on(selfpipe.rd);
459 ndelay_on(selfpipe[1]); 460 ndelay_on(selfpipe.wr);
460 461
461 sig_block(SIGCHLD); 462 sig_block(SIGCHLD);
462 sig_catch(SIGCHLD, s_child); 463 sig_catch(SIGCHLD, s_child);
@@ -489,9 +490,9 @@ int runsv_main(int argc, char **argv)
489 gettimeofday_ns(&svd[1].start); 490 gettimeofday_ns(&svd[1].start);
490 if (stat("log/down", &s) != -1) 491 if (stat("log/down", &s) != -1)
491 svd[1].want = W_DOWN; 492 svd[1].want = W_DOWN;
492 xpipe(logpipe); 493 xpiped_pair(logpipe);
493 close_on_exec_on(logpipe[0]); 494 close_on_exec_on(logpipe.rd);
494 close_on_exec_on(logpipe[1]); 495 close_on_exec_on(logpipe.wr);
495 } 496 }
496 } 497 }
497 498
@@ -572,7 +573,7 @@ int runsv_main(int argc, char **argv)
572 if (svd[0].want == W_UP || svd[0].state == S_FINISH) 573 if (svd[0].want == W_UP || svd[0].state == S_FINISH)
573 startservice(&svd[0]); 574 startservice(&svd[0]);
574 575
575 x[0].fd = selfpipe[0]; 576 x[0].fd = selfpipe.rd;
576 x[0].events = POLLIN; 577 x[0].events = POLLIN;
577 x[1].fd = svd[0].fdcontrol; 578 x[1].fd = svd[0].fdcontrol;
578 x[1].events = POLLIN; 579 x[1].events = POLLIN;
@@ -585,7 +586,7 @@ int runsv_main(int argc, char **argv)
585 sig_block(SIGTERM); 586 sig_block(SIGTERM);
586 sig_block(SIGCHLD); 587 sig_block(SIGCHLD);
587 588
588 while (read(selfpipe[0], &ch, 1) == 1) 589 while (read(selfpipe.rd, &ch, 1) == 1)
589 continue; 590 continue;
590 591
591 for (;;) { 592 for (;;) {
@@ -630,7 +631,7 @@ int runsv_main(int argc, char **argv)
630 sleep(1); 631 sleep(1);
631 } 632 }
632 } 633 }
633 } 634 } /* for (;;) */
634 if (read(svd[0].fdcontrol, &ch, 1) == 1) 635 if (read(svd[0].fdcontrol, &ch, 1) == 1)
635 ctrl(&svd[0], ch); 636 ctrl(&svd[0], ch);
636 if (haslog) 637 if (haslog)
@@ -649,11 +650,11 @@ int runsv_main(int argc, char **argv)
649 svd[1].want = W_EXIT; 650 svd[1].want = W_EXIT;
650 /* stopservice(&svd[1]); */ 651 /* stopservice(&svd[1]); */
651 update_status(&svd[1]); 652 update_status(&svd[1]);
652 close(logpipe[1]); 653 close(logpipe.wr);
653 close(logpipe[0]); 654 close(logpipe.rd);
654 } 655 }
655 } 656 }
656 } 657 } /* for (;;) */
657 /* not reached */ 658 /* not reached */
658 return 0; 659 return 0;
659} 660}
diff --git a/runit/runsvdir.c b/runit/runsvdir.c
index 838490376..4225ac101 100644
--- a/runit/runsvdir.c
+++ b/runit/runsvdir.c
@@ -47,7 +47,7 @@ static char *svdir;
47static int svnum; 47static int svnum;
48static char *rplog; 48static char *rplog;
49static int rploglen; 49static int rploglen;
50static int logpipe[2]; 50static struct fd_pair logpipe;
51static struct pollfd pfd[1]; 51static struct pollfd pfd[1];
52static unsigned stamplog; 52static unsigned stamplog;
53static smallint check = 1; 53static smallint check = 1;
@@ -186,19 +186,19 @@ static int setup_log(void)
186 warnx("log must have at least seven characters"); 186 warnx("log must have at least seven characters");
187 return 0; 187 return 0;
188 } 188 }
189 if (pipe(logpipe)) { 189 if (piped_pair(logpipe)) {
190 warnx("cannot create pipe for log"); 190 warnx("cannot create pipe for log");
191 return -1; 191 return -1;
192 } 192 }
193 close_on_exec_on(logpipe[1]); 193 close_on_exec_on(logpipe.rd);
194 close_on_exec_on(logpipe[0]); 194 close_on_exec_on(logpipe.wr);
195 ndelay_on(logpipe[0]); 195 ndelay_on(logpipe.rd);
196 ndelay_on(logpipe[1]); 196 ndelay_on(logpipe.wr);
197 if (dup2(logpipe[1], 2) == -1) { 197 if (dup2(logpipe.wr, 2) == -1) {
198 warnx("cannot set filedescriptor for log"); 198 warnx("cannot set filedescriptor for log");
199 return -1; 199 return -1;
200 } 200 }
201 pfd[0].fd = logpipe[0]; 201 pfd[0].fd = logpipe.rd;
202 pfd[0].events = POLLIN; 202 pfd[0].events = POLLIN;
203 stamplog = monotonic_sec(); 203 stamplog = monotonic_sec();
204 return 1; 204 return 1;
@@ -296,7 +296,7 @@ int runsvdir_main(int argc, char **argv)
296 296
297 if (rplog) { 297 if (rplog) {
298 if ((int)(now - stamplog) >= 0) { 298 if ((int)(now - stamplog) >= 0) {
299 write(logpipe[1], ".", 1); 299 write(logpipe.wr, ".", 1);
300 stamplog = now + 900; 300 stamplog = now + 900;
301 } 301 }
302 } 302 }
@@ -311,7 +311,7 @@ int runsvdir_main(int argc, char **argv)
311 sig_unblock(SIGCHLD); 311 sig_unblock(SIGCHLD);
312 312
313 if (pfd[0].revents & POLLIN) { 313 if (pfd[0].revents & POLLIN) {
314 while (read(logpipe[0], &ch, 1) > 0) { 314 while (read(logpipe.rd, &ch, 1) > 0) {
315 if (ch) { 315 if (ch) {
316 for (i = 6; i < rploglen; i++) 316 for (i = 6; i < rploglen; i++)
317 rplog[i-1] = rplog[i]; 317 rplog[i-1] = rplog[i];