runit

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 4f980a523dcc75ab77beadcc036ee45c95505c9f
parent 2e8fe0b3bfadce7d48785b3e7538a09ed449ba71
Author: Gerrit Pape <pape@smarden.org>
Date:   Sat, 23 Jul 2005 12:04:36 +0000

  * runsv.c: optimize output buffer handling; porperly run custom t, d, x,
    k, when stopping service; no longer support e control character.

Diffstat:
Msrc/runsv.c | 38+++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)

diff --git a/src/runsv.c b/src/runsv.c @@ -101,7 +101,8 @@ void update_status(struct svdir *s) { spid[fmt_ulong(spid, (unsigned long)s->pid)] =0; if (s->pid) { buffer_puts(&b, spid); - buffer_putsflush(&b, "\n"); + buffer_puts(&b, "\n"); + buffer_flush(&b); } close(fd); if (s->islog) { @@ -147,7 +148,8 @@ void update_status(struct svdir *s) { buffer_puts(&b, ", want exit"); break; } - buffer_putsflush(&b, "\n"); + buffer_puts(&b, "\n"); + buffer_flush(&b); close(fd); if (s->islog) { if (rename("supervise/stat.new", "log/supervise/stat") == -1) @@ -233,15 +235,26 @@ unsigned int custom(struct svdir *s, char c) { return(! wait_exitcode(w)); } } - else - if (errno != error_noent) warn("unable to stat control/?"); + else { + if (errno == error_noent) return(0); + warn("unable to stat control/?"); + } return(0); } void stopservice(struct svdir *s) { - if (s->pid) kill(s->pid, SIGTERM); - s->ctrl |=C_TERM; - update_status(s); - if ((s->want == W_DOWN) || (s->want == W_EXIT)) kill(s->pid, SIGCONT); + if (s->pid && ! custom(s, 't')) { + kill(s->pid, SIGTERM); + s->ctrl |=C_TERM; + update_status(s); + } + if (s->want == W_DOWN) { + kill(s->pid, SIGCONT); + custom(s, 'd'); return; + } + if (s->want == W_EXIT) { + kill(s->pid, SIGCONT); + custom(s, 'x'); + } } void startservice(struct svdir *s) { @@ -301,25 +314,24 @@ int ctrl(struct svdir *s, char c) { case 'd': /* down */ s->want =W_DOWN; update_status(s); - if (s->pid && s->state != S_FINISH && ! custom(s, c)) stopservice(s); + if (s->pid && s->state != S_FINISH) stopservice(s); break; case 'u': /* up */ s->want =W_UP; update_status(s); if (s->pid == 0) startservice(s); break; - case 'e': case 'x': /* exit */ if (s->islog) break; s->want =W_EXIT; update_status(s); - if (s->pid && s->state != S_FINISH && ! custom(s, c)) stopservice(s); + if (s->pid && s->state != S_FINISH) stopservice(s); break; case 't': /* sig term */ - if (s->pid && s->state != S_FINISH && ! custom(s, c)) stopservice(s); + if (s->pid && s->state != S_FINISH) stopservice(s); break; case 'k': /* sig kill */ - if (s->pid) kill(s->pid, SIGKILL); + if (s->pid && ! custom(s, c)) kill(s->pid, SIGKILL); s->state =S_DOWN; break; case 'p': /* sig pause */