runit

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

commit 83ff4be27c6cfc226648048c76ca27d90c14deee
parent d593fa1d819202fa5d5822bedd80eb5b10d255ac
Author: Gerrit Pape <pape@smarden.org>
Date:   Fri, 27 Sep 2002 09:01:20 +0000

rename rsv-* to runsv*.

Diffstat:
Mpackage/CHANGES | 5++---
Msrc/Makefile | 16++++++++--------
Msrc/TARGETS | 8++++----
Dsrc/rsv-control.c | 92-------------------------------------------------------------------------------
Dsrc/rsv-status.c | 154-------------------------------------------------------------------------------
Asrc/runsvctrl.c | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/runsvstat.c | 154+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 260 insertions(+), 261 deletions(-)

diff --git a/package/CHANGES b/package/CHANGES @@ -11,7 +11,6 @@ Wed, 25 Sep 2002 12:13:46 +0200 runit 0.5.3 Tue, 24 Sep 2002 12:14:02 +0200 - * package/commands: remove rsv-status, rsv-control. * runsvdir.c, runsv.c: code cleanup. * utmpset.c: setlock utmp and wtmp file. @@ -19,8 +18,8 @@ runit 0.5.2 Mon, 23 Sep 2002 16:25:07 +0200 * runsv, runsvdir: new; svscan/supervise replacement. * etc/runit/2: use runsvlog instead of svscanboot. - * rsv-status: new; svstat for runsv. - * rsv-control: new; svc for runsv. + * runsvstat.c: new; svstat for runsv. + * runsvctrl.c: new; svc for runsv. runit 0.5.0 Wed, 28 Aug 2002 11:18:28 +0200 diff --git a/src/Makefile b/src/Makefile @@ -14,11 +14,11 @@ runsv: load runsv.o unix.a byte.a time.a runsvdir: load runsvdir.o unix.a byte.a time.a ./load runsvdir unix.a byte.a time.a -rsv-status: load rsv-status.o unix.a byte.a time.a - ./load rsv-status unix.a byte.a time.a +runsvstat: load runsvstat.o unix.a byte.a time.a + ./load runsvstat unix.a byte.a time.a -rsv-control: load rsv-control.o unix.a byte.a - ./load rsv-control unix.a byte.a +runsvctrl: load runsvctrl.o unix.a byte.a + ./load runsvctrl unix.a byte.a svwaitup: load svwaitup.o unix.a byte.a time.a ./load svwaitup unix.a byte.a time.a @@ -38,11 +38,11 @@ runsv.o: compile sysdeps runsv.c runsvdir.o: compile sysdeps runsvdir.c ./compile runsvdir.c -rsv-status.o: compile sysdeps rsv-status.c - ./compile rsv-status.c +runsvstat.o: compile sysdeps runsvstat.c + ./compile runsvstat.c -rsv-control.o: compile rsv-control.c - ./compile rsv-control.c +runsvctrl.o: compile runsvctrl.c + ./compile runsvctrl.c svwaitup.o: compile sysdeps svwaitup.c ./compile svwaitup.c diff --git a/src/TARGETS b/src/TARGETS @@ -6,10 +6,10 @@ runsv runsv.o runsvdir runsvdir.o -rsv-status -rsv-status.o -rsv-control -rsv-control.o +runsvstat +runsvstat.o +runsvctrl +runsvctrl.o svwaitdown svwaitdown.o svwaitup diff --git a/src/rsv-control.c b/src/rsv-control.c @@ -1,92 +0,0 @@ -#include <unistd.h> -#include "strerr.h" -#include "error.h" -#include "open.h" - -#define USAGE " u|d|o|x|p|c|h|a|i|t|k service ..." - -#define VERSION "$Id$" - -#define FATAL "rsv-control: fatal: " -#define WARNING "rsv-control: warning: " - -char *progname; -unsigned int rc =0; - -void usage() { - strerr_die4x(1, "usage: ", progname, USAGE, "\n"); -} -void fatal(char *m1) { - strerr_die3sys(rc, FATAL, m1, ": "); -} -void warn(char *m1, char *m2) { - rc++; - strerr_warn5(WARNING, m1, ": ", m2, ": ", &strerr_sys); -} -void warnx(char *m1, char *m2) { - rc++; - strerr_warn4(WARNING, m1, ": ", m2, 0); -} - -int ctrl(char *name, char c) { - int fd; - - if ((fd =open_write("supervise/control")) == -1) { - if (errno == error_nodevice) - warnx(name, "supervise not running."); - else - warn(name, "unable to open supervise/control"); - return(-1); - } - if (write(fd, &c, 1) != 1) { - warn(name, "unable to write to supervise/control"); - return(-1); - } - return(1); -} - -int main(int argc, char **argv) { - char **dir; - int curdir; - char c; - - progname =*argv++; - - if (! argv || ! *argv) usage(); - - switch ((c =**argv)) { - case 'u': - case 'd': - case 'o': - case 'x': - case 'p': - case 'c': - case 'h': - case 'a': - case 'i': - case 't': - case 'k': - break; - default: - usage(); - } - dir =++argv; - if (! dir || ! *dir) usage(); - - if ((curdir =open_read(".")) == -1) { - rc =100; - fatal("unable to open current directory"); - } - for (; dir && *dir; dir++) { - if (chdir(*dir) == -1) { - warn(*dir, "unable to change directory"); - continue; - } - ctrl(*dir, c); - if (fchdir(curdir) == -1) { - rc =100; - fatal("unable to change directory"); - } - } - exit(rc); -} diff --git a/src/rsv-status.c b/src/rsv-status.c @@ -1,154 +0,0 @@ -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include "strerr.h" -#include "error.h" -#include "open.h" -#include "buffer.h" -#include "tai.h" -#include "fmt.h" - -#define USAGE " service ..." - -#define VERSION "$Id$" - -#define FATAL "rsv-status: fatal: " -#define WARNING "rsv-status: warning: " - -char *progname; -unsigned int rc =0; -struct stat s; - -void usage() { - strerr_die4x(1, "usage: ", progname, USAGE, "\n"); -} -void fatal(char *m1) { - strerr_die3sys(rc, FATAL, m1, ": "); -} -void warn(char *m1, char *m2) { - rc++; - strerr_warn5(WARNING, m1, ": ", m2, ": ", &strerr_sys); -} -void warnx(char *m1, char *m2) { - rc++; - strerr_warn4(WARNING, m1, ": ", m2, 0); -} - -int show_status(char *name) { - char status[19]; - int pid; - int fd; - int normallyup =0; - char sulong[FMT_ULONG]; - struct tai when; - struct tai now; - - if (stat("down", &s) == -1) { - if (errno != error_noent) { - warn(name, "unable to stat down"); - return(-1); - } - normallyup = 1; - } - if ((fd =open_write("supervise/ok")) == -1) { - if (errno == error_nodevice) - warnx(name, "runsv not running."); - else - warn(name, "unable to open supervise/ok"); - return(-1); - } - close(fd); - if ((fd =open_read("supervise/status")) == -1) { - warn(name, "unable to open supervise/status"); - return(-1); - } - switch(read(fd, status, 19)) { - case 19: - break; - case -1: - warn(name, "unable to read supervise/status"); - return(-1); - default: - warnx(name, "unable to read supervise/status: bad format."); - return(-1); - } - pid = (unsigned char) status[15]; - pid <<= 8; pid += (unsigned char) status[14]; - pid <<= 8; pid += (unsigned char) status[13]; - pid <<= 8; pid += (unsigned char) status[12]; - - tai_unpack(status,&when); - tai_now(&now); - if (tai_less(&now,&when)) when = now; - tai_sub(&when,&now,&when); - - buffer_puts(buffer_1, name); - buffer_puts(buffer_1, ": "); - if (pid) { - buffer_puts(buffer_1, "up (pid "); - buffer_put(buffer_1, sulong, fmt_ulong(sulong, pid)); - buffer_puts(buffer_1, ") "); - } - else - buffer_puts(buffer_1, "down "); - buffer_put(buffer_1, sulong, fmt_ulong(sulong, tai_approx(&when))); - buffer_puts(buffer_1, " seconds"); - if (pid && !normallyup) - buffer_puts(buffer_1,", normally down"); - if (!pid && normallyup) - buffer_puts(buffer_1,", normally up"); - if (pid && status[16]) - buffer_puts(buffer_1,", paused"); - if (!pid && (status[17] == 'u')) - buffer_puts(buffer_1,", want up"); - if (pid && (status[17] == 'd')) - buffer_puts(buffer_1,", want down"); - if (pid && status[18]) - buffer_puts(buffer_1, ", got TERM"); - // buffer_putsflush(buffer_1, "\n"); - return(1); -} - -int main(int argc, char **argv) { - int curdir; - char **dir; - - progname =*argv++; - - dir =argv; - if (! dir || ! *dir) usage(); - - if ((curdir =open_read(".")) == -1) { - rc =100; - fatal("unable to open current directory"); - } - for (; dir && *dir; dir++) { - if (chdir(*dir) == -1) { - warn(*dir, "unable to change directory"); - continue; - } - if (show_status(*dir) == 1) { - if (stat("log", &s) == -1) { - if (errno != error_noent) - warn("unable to stat()", "./log"); - } - else { - if (! S_ISDIR(s.st_mode)) - warnx("./log", "not a directory."); - else { - if (chdir("log") == -1) { - warn(*dir, "unable to change directory"); - continue; - } - show_status("\n log"); - } - } - buffer_putsflush(buffer_1, "\n"); - } - if (fchdir(curdir) == -1) { - rc =100; - fatal("unable to change directory"); - } - } - exit(rc); -} diff --git a/src/runsvctrl.c b/src/runsvctrl.c @@ -0,0 +1,92 @@ +#include <unistd.h> +#include "strerr.h" +#include "error.h" +#include "open.h" + +#define USAGE " u|d|o|x|p|c|h|a|i|t|k service ..." + +#define VERSION "$Id$" + +#define FATAL "runsvctrl: fatal: " +#define WARNING "runsvctrl: warning: " + +char *progname; +unsigned int rc =0; + +void usage() { + strerr_die4x(1, "usage: ", progname, USAGE, "\n"); +} +void fatal(char *m1) { + strerr_die3sys(rc, FATAL, m1, ": "); +} +void warn(char *m1, char *m2) { + rc++; + strerr_warn5(WARNING, m1, ": ", m2, ": ", &strerr_sys); +} +void warnx(char *m1, char *m2) { + rc++; + strerr_warn4(WARNING, m1, ": ", m2, 0); +} + +int ctrl(char *name, char c) { + int fd; + + if ((fd =open_write("supervise/control")) == -1) { + if (errno == error_nodevice) + warnx(name, "supervise not running."); + else + warn(name, "unable to open supervise/control"); + return(-1); + } + if (write(fd, &c, 1) != 1) { + warn(name, "unable to write to supervise/control"); + return(-1); + } + return(1); +} + +int main(int argc, char **argv) { + char **dir; + int curdir; + char c; + + progname =*argv++; + + if (! argv || ! *argv) usage(); + + switch ((c =**argv)) { + case 'u': + case 'd': + case 'o': + case 'x': + case 'p': + case 'c': + case 'h': + case 'a': + case 'i': + case 't': + case 'k': + break; + default: + usage(); + } + dir =++argv; + if (! dir || ! *dir) usage(); + + if ((curdir =open_read(".")) == -1) { + rc =100; + fatal("unable to open current directory"); + } + for (; dir && *dir; dir++) { + if (chdir(*dir) == -1) { + warn(*dir, "unable to change directory"); + continue; + } + ctrl(*dir, c); + if (fchdir(curdir) == -1) { + rc =100; + fatal("unable to change directory"); + } + } + exit(rc); +} diff --git a/src/runsvstat.c b/src/runsvstat.c @@ -0,0 +1,154 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include "strerr.h" +#include "error.h" +#include "open.h" +#include "buffer.h" +#include "tai.h" +#include "fmt.h" + +#define USAGE " service ..." + +#define VERSION "$Id$" + +#define FATAL "runsvstat: fatal: " +#define WARNING "runsvstat: warning: " + +char *progname; +unsigned int rc =0; +struct stat s; + +void usage() { + strerr_die4x(1, "usage: ", progname, USAGE, "\n"); +} +void fatal(char *m1) { + strerr_die3sys(rc, FATAL, m1, ": "); +} +void warn(char *m1, char *m2) { + rc++; + strerr_warn5(WARNING, m1, ": ", m2, ": ", &strerr_sys); +} +void warnx(char *m1, char *m2) { + rc++; + strerr_warn4(WARNING, m1, ": ", m2, 0); +} + +int show_status(char *name) { + char status[19]; + int pid; + int fd; + int normallyup =0; + char sulong[FMT_ULONG]; + struct tai when; + struct tai now; + + if (stat("down", &s) == -1) { + if (errno != error_noent) { + warn(name, "unable to stat down"); + return(-1); + } + normallyup = 1; + } + if ((fd =open_write("supervise/ok")) == -1) { + if (errno == error_nodevice) + warnx(name, "runsv not running."); + else + warn(name, "unable to open supervise/ok"); + return(-1); + } + close(fd); + if ((fd =open_read("supervise/status")) == -1) { + warn(name, "unable to open supervise/status"); + return(-1); + } + switch(read(fd, status, 19)) { + case 19: + break; + case -1: + warn(name, "unable to read supervise/status"); + return(-1); + default: + warnx(name, "unable to read supervise/status: bad format."); + return(-1); + } + pid = (unsigned char) status[15]; + pid <<= 8; pid += (unsigned char) status[14]; + pid <<= 8; pid += (unsigned char) status[13]; + pid <<= 8; pid += (unsigned char) status[12]; + + tai_unpack(status,&when); + tai_now(&now); + if (tai_less(&now,&when)) when = now; + tai_sub(&when,&now,&when); + + buffer_puts(buffer_1, name); + buffer_puts(buffer_1, ": "); + if (pid) { + buffer_puts(buffer_1, "up (pid "); + buffer_put(buffer_1, sulong, fmt_ulong(sulong, pid)); + buffer_puts(buffer_1, ") "); + } + else + buffer_puts(buffer_1, "down "); + buffer_put(buffer_1, sulong, fmt_ulong(sulong, tai_approx(&when))); + buffer_puts(buffer_1, " seconds"); + if (pid && !normallyup) + buffer_puts(buffer_1,", normally down"); + if (!pid && normallyup) + buffer_puts(buffer_1,", normally up"); + if (pid && status[16]) + buffer_puts(buffer_1,", paused"); + if (!pid && (status[17] == 'u')) + buffer_puts(buffer_1,", want up"); + if (pid && (status[17] == 'd')) + buffer_puts(buffer_1,", want down"); + if (pid && status[18]) + buffer_puts(buffer_1, ", got TERM"); + // buffer_putsflush(buffer_1, "\n"); + return(1); +} + +int main(int argc, char **argv) { + int curdir; + char **dir; + + progname =*argv++; + + dir =argv; + if (! dir || ! *dir) usage(); + + if ((curdir =open_read(".")) == -1) { + rc =100; + fatal("unable to open current directory"); + } + for (; dir && *dir; dir++) { + if (chdir(*dir) == -1) { + warn(*dir, "unable to change directory"); + continue; + } + if (show_status(*dir) == 1) { + if (stat("log", &s) == -1) { + if (errno != error_noent) + warn("unable to stat()", "./log"); + } + else { + if (! S_ISDIR(s.st_mode)) + warnx("./log", "not a directory."); + else { + if (chdir("log") == -1) { + warn(*dir, "unable to change directory"); + continue; + } + show_status("\n log"); + } + } + buffer_putsflush(buffer_1, "\n"); + } + if (fchdir(curdir) == -1) { + rc =100; + fatal("unable to change directory"); + } + } + exit(rc); +}