runit

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

commit 85e7f28629d41b2afb2a2f4804c1312929b1a398
parent 78cf1ae3619287716f2235278e5a435f1fb4a32c
Author: Gerrit Pape <pape@smarden.org>
Date:   Mon, 23 Sep 2002 14:27:35 +0000

  * rsv-status: new; svstat for runsv.
  * rsv-control: new; svc for runsv.

Diffstat:
Mpackage/CHANGES | 4+++-
Mpackage/commands | 2++
Msrc/Makefile | 21+++++++++++++++++----
Msrc/TARGETS | 4++++
Asrc/rsv-control.c | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/rsv-status.c | 154+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/runsv.c | 2+-
7 files changed, 273 insertions(+), 6 deletions(-)

diff --git a/package/CHANGES b/package/CHANGES @@ -1,7 +1,9 @@ runit 0.5.2 -Mon, 23 Sep 2002 12:07:42 +0200 +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. runit 0.5.0 Wed, 28 Aug 2002 11:18:28 +0200 diff --git a/package/commands b/package/commands @@ -2,6 +2,8 @@ runit runit-init runsv runsvdir +rsv-status +rsv-control svwaitdown svwaitup utmpset diff --git a/src/Makefile b/src/Makefile @@ -1,4 +1,5 @@ -IT=sysdeps runit runit-init runsv runsvdir svwaitup svwaitdown utmpset +IT=sysdeps runit runit-init runsv runsvdir rsv-status rsv-control svwaitup \ +svwaitdown utmpset default: $(IT) @@ -14,6 +15,12 @@ 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 + +rsv-control: load rsv-control.o unix.a byte.a + ./load rsv-control unix.a byte.a + svwaitup: load svwaitup.o unix.a byte.a time.a ./load svwaitup unix.a byte.a time.a @@ -29,13 +36,19 @@ runit-init.o: compile runit-init.c runsv.o: compile sysdeps runsv.c ./compile runsv.c -runsvdir.o: compile runsvdir.c direntry.h iopause.h uint64.h +runsvdir.o: compile sysdeps runsvdir.c ./compile runsvdir.c -svwaitup.o: compile svwaitup.c uint64.h +rsv-status.o: compile sysdeps rsv-status.c + ./compile rsv-status.c + +rsv-control.o: compile rsv-control.c + ./compile rsv-control.c + +svwaitup.o: compile sysdeps svwaitup.c ./compile svwaitup.c -svwaitdown.o: compile svwaitdown.c uint64.h +svwaitdown.o: compile sysdeps svwaitdown.c ./compile svwaitdown.c utmpset: load utmpset.o unix.a byte.a diff --git a/src/TARGETS b/src/TARGETS @@ -6,6 +6,10 @@ runsv runsv.o runsvdir runsvdir.o +rsv-status +rsv-status.o +rsv-control +rsv-control.o svwaitdown svwaitdown.o svwaitup diff --git a/src/rsv-control.c b/src/rsv-control.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 "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 @@ -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 "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/runsv.c b/src/runsv.c @@ -48,7 +48,6 @@ struct svdir { int fdlock; int fdcontrol; int fdcontrolwrite; - // int fdok; int islog; }; struct svdir svd[2]; @@ -430,6 +429,7 @@ int main(int argc, char **argv) { break; } svd[0].state =S_DOWN; + svd[0].ctrl &=~C_TERM; taia_now(&svd[0].start); update_status(&svd[0]); if (svd[0].want == W_UP) {