aboutsummaryrefslogtreecommitdiff
path: root/runit/runsv.c
diff options
context:
space:
mode:
Diffstat (limited to 'runit/runsv.c')
-rw-r--r--runit/runsv.c47
1 files changed, 24 insertions, 23 deletions
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}