diff --git a/src/Makefile b/src/Makefile index 5b660a8..e7ee715 100644 --- a/src/Makefile +++ b/src/Makefile @@ -34,26 +34,10 @@ runsvdir: runsvdir.o unix.a byte.a time.a @printf " [CCLD]\t\t$@\n" ${SILENT}$(CC) $^ $(LDFLAGS) $(BUILD_STATIC) -o $@ -runsvstat: runsvstat.o unix.a byte.a time.a - @printf " [CCLD]\t\t$@\n" - ${SILENT}$(CC) $^ $(LDFLAGS) $(BUILD_STATIC) -o $@ - -runsvctrl: runsvctrl.o unix.a byte.a - @printf " [CCLD]\t\t$@\n" - ${SILENT}$(CC) $^ $(LDFLAGS) $(BUILD_STATIC) -o $@ - sv: sv.o unix.a byte.a time.a @printf " [CCLD]\t\t$@\n" ${SILENT}$(CC) $^ $(LDFLAGS) $(BUILD_STATIC) -o $@ -svwaitup: svwaitup.o unix.a byte.a time.a - @printf " [CCLD]\t\t$@\n" - ${SILENT}$(CC) $^ $(LDFLAGS) $(BUILD_STATIC) -o $@ - -svwaitdown: svwaitdown.o unix.a byte.a time.a - @printf " [CCLD]\t\t$@\n" - ${SILENT}$(CC) $^ $(LDFLAGS) $(BUILD_STATIC) -o $@ - utmpset: utmpset.o unix.a byte.a @printf " [CCLD]\t\t$@\n" ${SILENT}$(CC) $^ $(LDFLAGS) $(BUILD_STATIC) -o $@ diff --git a/src/runsvctrl.c b/src/runsvctrl.c deleted file mode 100644 index 4954ca5..0000000 --- a/src/runsvctrl.c +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include "strerr.h" -#include "error.h" -#include "open.h" - -#define USAGE " u|d|o|p|c|h|a|i|q|1|2|t|k|x|e service ..." - -#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(111, 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, "runsv 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 'e': c ='x'; - case 'u': case 'd': case 'o': case 'x': case 'p': case 'c': case 'h': - case 'a': case 'i': case 't': case 'k': case 'q': case '1': case '2': - 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"); - } - } - if (rc > 100) rc =100; - _exit(rc); -} diff --git a/src/runsvctrl.check b/src/runsvctrl.check deleted file mode 100755 index 7911074..0000000 --- a/src/runsvctrl.check +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh -rm -rf "${ctmp}" - -runsvctrl -echo $? - -mkdir "${ctmp}" -echo '#!/bin/sh' >"${ctmp}"/run -echo 'echo starting' >>"${ctmp}"/run -echo 'exec sleep 14' >>"${ctmp}"/run -chmod 700 "${ctmp}"/run -runsv "${ctmp}" & -sleep 1 -test -r "${ctmp}"/supervise/stat || sleep 2 -runsvctrl down "${ctmp}" -echo $? -sleep 1 -cat "${ctmp}"/supervise/stat -runsvctrl exit "${ctmp}" -echo $? -wait -echo $? -rm -rf "${ctmp}" diff --git a/src/runsvctrl.dist b/src/runsvctrl.dist deleted file mode 100644 index b07cf8a..0000000 --- a/src/runsvctrl.dist +++ /dev/null @@ -1,8 +0,0 @@ -usage: runsvctrl u|d|o|p|c|h|a|i|q|1|2|t|k|x|e service ... - -1 -starting -0 -down -0 -0 diff --git a/src/runsvstat.c b/src/runsvstat.c deleted file mode 100644 index baa387b..0000000 --- a/src/runsvstat.c +++ /dev/null @@ -1,166 +0,0 @@ -#include -#include -#include -#include "strerr.h" -#include "strquote.h" -#include "error.h" -#include "sgetopt.h" -#include "open.h" -#include "buffer.h" -#include "tai.h" -#include "fmt.h" - -#define USAGE " [ -l ] service ..." - -#define FATAL "runsvstat: fatal: " -#define WARNING "runsvstat: warning: " - -const char *progname; -unsigned int rc =0; -struct stat s; -int showlog =0; - -void usage() { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); } - -void fatal(char *m1) { strerr_die3sys(111, 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[20]; - 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, 20)) { - case 20: 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) { - switch (status[19]) { - case 1: buffer_puts(buffer_1, "run "); break; - case 2: buffer_puts(buffer_1, "finish "); break; - } - buffer_puts(buffer_1, "(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 opt; - int curdir; - char **dir; - - progname =*argv; - - while ((opt =getopt(argc, (const char * const *)argv, "lV")) != opteof) { - switch(opt) { - case 'l': - showlog =1; - break; - case 'V': - strerr_warn1(STR(VERSION), 0); - case '?': - usage(); - } - } - argv +=optind; - - 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 (showlog) { - 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_puts(buffer_1, "\n"); buffer_flush(buffer_1); - } - if (fchdir(curdir) == -1) { - rc =100; - fatal("unable to change directory"); - } - } - if (rc > 100) rc =100; - _exit(rc); -} diff --git a/src/runsvstat.check b/src/runsvstat.check deleted file mode 100755 index 6ccde11..0000000 --- a/src/runsvstat.check +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -rm -rf "${ctmp}" - -runsvstat -echo $? -runsvstat -V -echo $? - -mkdir "${ctmp}" -echo '#!/bin/sh' >"${ctmp}"/run -echo 'echo starting' >>"${ctmp}"/run -echo 'exec sleep 14' >>"${ctmp}"/run -chmod 700 "${ctmp}"/run -chpst -2 runsvstat "${ctmp}" -echo $? -runsv "${ctmp}" & -sleep 1 -test -r "${ctmp}"/supervise/stat || sleep 2 -chpst -1 runsvstat "${ctmp}" -echo $? -runsvctrl exit "${ctmp}" -wait -echo $? -chpst -2 runsvstat "${ctmp}" -echo $? -rm -rf "${ctmp}" diff --git a/src/runsvstat.dist b/src/runsvstat.dist deleted file mode 100644 index 24b9ed4..0000000 --- a/src/runsvstat.dist +++ /dev/null @@ -1,12 +0,0 @@ -usage: runsvstat [ -l ] service ... - -1 -$Id$ -usage: runsvstat [ -l ] service ... - -1 -1 -starting -0 -0 -1 diff --git a/src/svwaitdown.c b/src/svwaitdown.c deleted file mode 100644 index e3e744e..0000000 --- a/src/svwaitdown.c +++ /dev/null @@ -1,176 +0,0 @@ -#include -#include "strerr.h" -#include "strquote.h" -#include "error.h" -#include "sgetopt.h" -#include "scan.h" -#include "open.h" -#include "tai.h" -#include "buffer.h" - -#define FATAL "svwaitdown: fatal: " -#define WARN "svwaitdown: warning: " -#define INFO "svwaitdown: " -#define USAGE " [-v] [-t 1..6000] service ..." - -const char *progname; -const char * const *dir; -unsigned int rc =0; - -void fatal(const char *m) { strerr_die3sys(111, FATAL, m, ": "); } -void warn(const char *s1, const char *s2, struct strerr *e) { - dir++; rc++; - strerr_warn3(WARN, s1, s2, e); -} -void usage() { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); } - -int main(int argc, const char * const *argv) { - int opt; - unsigned long sec =600; - int verbose =0; - int doexit =0; - int dokill =0; - int wdir; - int fd; - char status[20]; - int r; - unsigned long pid; - struct tai start; - struct tai now; - - progname =*argv; - - while ((opt =getopt(argc, argv, "t:xkvV")) != opteof) { - switch(opt) { - case 't': - scan_ulong(optarg, &sec); - if ((sec < 1) || (sec > 6000)) usage(); - break; - case 'x': - doexit =1; - break; - case 'k': - dokill =1; - break; - case 'v': - verbose =1; - break; - case 'V': - strerr_warn1(STR(VERSION), 0); - case '?': - usage(); - } - } - argv +=optind; - if (! argv || ! *argv) usage(); - - if ((wdir =open_read(".")) == -1) - fatal("unable to open current working directory"); - - for (dir =argv; *dir; ++dir) { - if (dir != argv) - if (fchdir(wdir) == -1) fatal("unable to switch to starting directory"); - if (chdir(*dir) == -1) continue; /* bummer */ - if ((fd =open_write("supervise/control")) == -1) continue; /* bummer */ - if (write(fd, "dx", 1 +doexit) != (1 +doexit)) { - close(fd); continue; /* bummer */ - } - close(fd); - } - dir =argv; - - tai_now(&start); - while (*dir) { - if (fchdir(wdir) == -1) fatal("unable to switch to starting directory"); - if (chdir(*dir) == -1) { - warn(*dir, ": unable to change directory: ", &strerr_sys); - continue; - } - if ((fd =open_write("supervise/ok")) == -1) { - if (errno == error_nodevice) { - if (verbose) strerr_warn3(INFO, *dir, ": runsv not running.", 0); - dir++; - } - else - warn(*dir, ": unable to open supervise/ok: ", &strerr_sys); - continue; - } - close(fd); - - if ((fd =open_read("supervise/status")) == -1) { - warn(*dir, "unable to open supervise/status: ", &strerr_sys); - continue; - } - r =buffer_unixread(fd, status, 20); - close(fd); - if ((r < 18) || (r == 19)) { /* supervise compatibility */ - if (r == -1) - warn(*dir, "unable to read supervise/status: ", &strerr_sys); - else - warn(*dir, ": unable to read supervise/status: bad format.", 0); - continue; - } - 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]; - - if (! doexit && ! pid) { - /* ok, service is down */ - if (verbose) strerr_warn3(INFO, *dir, ": down.", 0); - dir++; - continue; - } - - if (status[17] != 'd') { /* catch previous failures */ - if ((fd =open_write("supervise/control")) == -1) { - warn(*dir, ": unable to open supervise/control: ", &strerr_sys); - continue; - } - if (write(fd, "dx", 1 +doexit) != (1 +doexit)) { - warn(*dir, ": unable to write to supervise/control: ", &strerr_sys); - close(fd); - continue; - } - close(fd); - } - - tai_now(&now); - tai_sub(&now, &now, &start); - if (tai_approx(&now) >= sec) { - /* timeout */ - if (verbose) strerr_warn2(INFO, "timeout.", 0); - if (dokill) { - if (chdir(*dir) == -1) { - warn(*dir, ": unable to change directory: ", &strerr_sys); - continue; - } - if ((fd =open_write("supervise/control")) == -1) { - if (errno == error_nodevice) { - if (verbose) - strerr_warn3(INFO, *dir, ": runsv not running.", 0); - dir++; - } - else - warn(*argv, ": unable to open supervise/control: ", &strerr_sys); - continue; - } - if (write(fd, "k", 1) != 1) - warn(*argv, ": unable to write to supervise/control: ", &strerr_sys); - else - strerr_warn3(INFO, *dir, ": killed.", 0); - close(fd); - dir++; - if (! *dir) _exit(111); - continue; - } - _exit(111); - } - sleep(1); - } - if (fchdir(wdir) == -1) - strerr_warn2(WARN, "unable to switch to starting directory: ", &strerr_sys); - close(wdir); - if (rc > 100) rc =100; - _exit(rc); -} diff --git a/src/svwaitdown.check b/src/svwaitdown.check deleted file mode 100755 index 5cf6c21..0000000 --- a/src/svwaitdown.check +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -rm -rf "${ctmp}" - -svwaitdown -echo $? -svwaitdown -V -echo $? - -mkdir "${ctmp}" -echo '#!/bin/sh' >"${ctmp}"/run -echo 'echo starting' >>"${ctmp}"/run -echo 'exec sleep 14' >>"${ctmp}"/run -chmod 700 "${ctmp}"/run -runsv "${ctmp}" & -sleep 1 -test -r "${ctmp}"/supervise/stat || sleep 2 -svwaitdown "${ctmp}" -echo $? -svwaitdown -x "${ctmp}" -echo $? -cat "${ctmp}"/supervise/stat -wait -echo $? -rm -rf "${ctmp}" diff --git a/src/svwaitdown.dist b/src/svwaitdown.dist deleted file mode 100644 index 2d83839..0000000 --- a/src/svwaitdown.dist +++ /dev/null @@ -1,12 +0,0 @@ -usage: svwaitdown [-v] [-t 1..6000] service ... - -1 -$Id$ -usage: svwaitdown [-v] [-t 1..6000] service ... - -1 -starting -0 -0 -down -0 diff --git a/src/svwaitup.c b/src/svwaitup.c deleted file mode 100644 index 0d7eb0a..0000000 --- a/src/svwaitup.c +++ /dev/null @@ -1,127 +0,0 @@ -#include -#include "strerr.h" -#include "strquote.h" -#include "error.h" -#include "sgetopt.h" -#include "scan.h" -#include "open.h" -#include "tai.h" -#include "buffer.h" -#include "fmt.h" - -#define FATAL "svwaitup: fatal: " -#define WARN "svwaitup: warning: " -#define INFO "svwaitup: " -#define USAGE " [-v] [-s 1..600] service ..." - -const char *progname; -unsigned long sec =2; -unsigned int rc =0; -const char * const *dir; - -void fatal(const char *m) { strerr_die3sys(111, FATAL, m, ": "); } -void warn(const char *s1, const char *s2, struct strerr *e) { - dir++; rc++; - strerr_warn3(WARN, s1, s2, e); -} -void usage() { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); } - -int main(int argc, const char * const *argv) { - int opt; - int verbose =0; - char status[18]; - int fd; - int is; - int r; - int wdir; - unsigned long pid; - struct tai when; - struct tai now; - char sulong[FMT_ULONG]; - - progname =*argv; - - while ((opt =getopt(argc, argv, "s:vV")) != opteof) { - switch(opt) { - case 's': - scan_ulong(optarg, &sec); - if ((sec < 1) || (sec > 600)) usage(); - break; - case 'v': - verbose =1; - break; - case 'V': - strerr_warn1(STR(VERSION), 0); - case '?': - usage(); - } - } - argv +=optind; - if (! argv || ! *argv) usage(); - - if ((wdir =open_read(".")) == -1) - fatal("unable to open current working directory"); - - dir =argv; - while (*dir) { - if (dir != argv) - if (fchdir(wdir) == -1) fatal("unable to switch to starting directory"); - if (chdir(*dir) == -1) { - warn(*dir, ": unable to change directory: ", &strerr_sys); - continue; - } - if ((fd =open_write("supervise/ok")) == -1) { - if (errno == error_nodevice) - warn(*dir, ": runsv not running.", 0); - else - warn(*dir, ": unable to open supervise/ok: ", &strerr_sys); - continue; - } - close(fd); - - if ((fd =open_read("supervise/status")) == -1) { - warn(*dir, "unable to open supervise/status: ", &strerr_sys); - continue; - } - r =buffer_unixread(fd, status, sizeof status); - close(fd); - if (r < sizeof status) { - if (r == -1) - warn(*dir, "unable to read supervise/status: ", &strerr_sys); - else - warn(*dir, ": unable to read supervise/status: bad format.", 0); - continue; - } - - 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]; - if (! pid) { - warn(*dir, ": is down.", 0); - continue; - } - - tai_unpack(status, &when); - tai_now(&now); - if (tai_less(&now, &when)) when =now; - tai_sub(&when, &now, &when); - is =tai_approx(&when); - - if (is >= sec) { - /* ok */ - if (verbose) { - sulong[fmt_ulong(sulong, is)] =0; - strerr_warn5(INFO, *dir, ": is up (", sulong, " seconds)", 0); - } - dir++; - continue; - } - sleep(sec -is); - } - if (fchdir(wdir) == -1) - strerr_warn2(WARN, "unable to switch to starting directory: ", &strerr_sys); - close(wdir); - if (rc > 100) rc =100; - _exit(rc); -} diff --git a/src/svwaitup.check b/src/svwaitup.check deleted file mode 100755 index a1be802..0000000 --- a/src/svwaitup.check +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh -rm -rf "${ctmp}" - -svwaitup -echo $? -svwaitup -V -echo $? - -mkdir "${ctmp}" -echo '#!/bin/sh' >"${ctmp}"/run -echo 'echo starting' >>"${ctmp}"/run -echo 'exec sleep 14' >>"${ctmp}"/run -chmod 700 "${ctmp}"/run -runsv "${ctmp}" & -sleep 1 -test -r "${ctmp}"/supervise/stat || sleep 2 -svwaitup "${ctmp}" -echo $? -cat "${ctmp}"/supervise/stat -svwaitup -s2 "${ctmp}" -echo $? -cat "${ctmp}"/supervise/stat -runsvctrl exit "${ctmp}" -wait -echo $? -chpst -2 svwaitup -s2 "${ctmp}" -echo $? -rm -rf "${ctmp}" diff --git a/src/svwaitup.dist b/src/svwaitup.dist deleted file mode 100644 index 692990f..0000000 --- a/src/svwaitup.dist +++ /dev/null @@ -1,14 +0,0 @@ -usage: svwaitup [-v] [-s 1..600] service ... - -1 -$Id$ -usage: svwaitup [-v] [-s 1..600] service ... - -1 -starting -0 -run -0 -run -0 -1