*: more readable handling of pipe fds. No code changes.
This commit is contained in:
@@ -90,8 +90,8 @@ struct globals {
|
||||
smallint haslog;
|
||||
smallint sigterm;
|
||||
smallint pidchanged;
|
||||
int selfpipe[2];
|
||||
int logpipe[2];
|
||||
struct fd_pair selfpipe;
|
||||
struct fd_pair logpipe;
|
||||
char *dir;
|
||||
struct svdir svd[2];
|
||||
};
|
||||
@@ -130,13 +130,13 @@ static void warn_cannot(const char *m)
|
||||
|
||||
static void s_child(int sig_no)
|
||||
{
|
||||
write(selfpipe[1], "", 1);
|
||||
write(selfpipe.wr, "", 1);
|
||||
}
|
||||
|
||||
static void s_term(int sig_no)
|
||||
{
|
||||
sigterm = 1;
|
||||
write(selfpipe[1], "", 1); /* XXX */
|
||||
write(selfpipe.wr, "", 1); /* XXX */
|
||||
}
|
||||
|
||||
static char *add_str(char *p, const char *to_add)
|
||||
@@ -275,7 +275,7 @@ static unsigned custom(struct svdir *s, char c)
|
||||
return 0;
|
||||
}
|
||||
if (!pid) {
|
||||
if (haslog && dup2(logpipe[1], 1) == -1)
|
||||
if (haslog && dup2(logpipe.wr, 1) == -1)
|
||||
warn_cannot("setup stdout for control/?");
|
||||
prog[0] = a;
|
||||
prog[1] = NULL;
|
||||
@@ -335,13 +335,14 @@ static void startservice(struct svdir *s)
|
||||
if (p == 0) {
|
||||
/* child */
|
||||
if (haslog) {
|
||||
/* NB: bug alert! right order is close, then dup2 */
|
||||
if (s->islog) {
|
||||
xdup2(logpipe[0], 0);
|
||||
close(logpipe[1]);
|
||||
xchdir("./log");
|
||||
close(logpipe.wr);
|
||||
xdup2(logpipe.rd, 0);
|
||||
} else {
|
||||
xdup2(logpipe[1], 1);
|
||||
close(logpipe[0]);
|
||||
close(logpipe.rd);
|
||||
xdup2(logpipe.wr, 1);
|
||||
}
|
||||
}
|
||||
signal(SIGCHLD, SIG_DFL);
|
||||
@@ -452,11 +453,11 @@ int runsv_main(int argc, char **argv)
|
||||
bb_show_usage();
|
||||
dir = argv[1];
|
||||
|
||||
xpipe(selfpipe);
|
||||
close_on_exec_on(selfpipe[0]);
|
||||
close_on_exec_on(selfpipe[1]);
|
||||
ndelay_on(selfpipe[0]);
|
||||
ndelay_on(selfpipe[1]);
|
||||
xpiped_pair(selfpipe);
|
||||
close_on_exec_on(selfpipe.rd);
|
||||
close_on_exec_on(selfpipe.wr);
|
||||
ndelay_on(selfpipe.rd);
|
||||
ndelay_on(selfpipe.wr);
|
||||
|
||||
sig_block(SIGCHLD);
|
||||
sig_catch(SIGCHLD, s_child);
|
||||
@@ -489,9 +490,9 @@ int runsv_main(int argc, char **argv)
|
||||
gettimeofday_ns(&svd[1].start);
|
||||
if (stat("log/down", &s) != -1)
|
||||
svd[1].want = W_DOWN;
|
||||
xpipe(logpipe);
|
||||
close_on_exec_on(logpipe[0]);
|
||||
close_on_exec_on(logpipe[1]);
|
||||
xpiped_pair(logpipe);
|
||||
close_on_exec_on(logpipe.rd);
|
||||
close_on_exec_on(logpipe.wr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,7 +573,7 @@ int runsv_main(int argc, char **argv)
|
||||
if (svd[0].want == W_UP || svd[0].state == S_FINISH)
|
||||
startservice(&svd[0]);
|
||||
|
||||
x[0].fd = selfpipe[0];
|
||||
x[0].fd = selfpipe.rd;
|
||||
x[0].events = POLLIN;
|
||||
x[1].fd = svd[0].fdcontrol;
|
||||
x[1].events = POLLIN;
|
||||
@@ -585,7 +586,7 @@ int runsv_main(int argc, char **argv)
|
||||
sig_block(SIGTERM);
|
||||
sig_block(SIGCHLD);
|
||||
|
||||
while (read(selfpipe[0], &ch, 1) == 1)
|
||||
while (read(selfpipe.rd, &ch, 1) == 1)
|
||||
continue;
|
||||
|
||||
for (;;) {
|
||||
@@ -630,7 +631,7 @@ int runsv_main(int argc, char **argv)
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* for (;;) */
|
||||
if (read(svd[0].fdcontrol, &ch, 1) == 1)
|
||||
ctrl(&svd[0], ch);
|
||||
if (haslog)
|
||||
@@ -649,11 +650,11 @@ int runsv_main(int argc, char **argv)
|
||||
svd[1].want = W_EXIT;
|
||||
/* stopservice(&svd[1]); */
|
||||
update_status(&svd[1]);
|
||||
close(logpipe[1]);
|
||||
close(logpipe[0]);
|
||||
close(logpipe.wr);
|
||||
close(logpipe.rd);
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* for (;;) */
|
||||
/* not reached */
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user