commit b2649594fa5f2c0a1c7d006cee06fc87059e73bd
parent 733f305bd79e2913a291f519efa73e161c0c83c0
Author: Gerrit Pape <pape@smarden.org>
Date: Mon, 10 Jan 2005 19:35:51 +0000
* chpst.c: typo.
* svwaitdown.c: minimum timeout is 1 second; service directories no longer
must start with /.
* svwaitup.c: minimum uptime of services is 1 second; service directories
no longer must start with /; print number of seconds a service is up if
verbose.
* man/svwaitdown.8, man/svwaitup.8: adapt.
Diffstat:
6 files changed, 71 insertions(+), 56 deletions(-)
diff --git a/man/svwaitdown.8 b/man/svwaitdown.8
@@ -1,6 +1,6 @@
.TH svwaitdown 8
.SH NAME
-svwaitdown \- waits for services controlled by runsv(8) or supervise(8) to be down
+svwaitdown \- waits for services controlled by runsv(8) to be down
.SH SYNOPSIS
.B svwaitdown
[
@@ -14,9 +14,7 @@ svwaitdown \- waits for services controlled by runsv(8) or supervise(8) to be do
.I services
.SH DESCRIPTION
.I services
-consists of one or more arguments. Each
-.I service
-directory must start with a slash.
+consists of one or more arguments, each argument naming a service directory.
.P
.B svwaitdown
sends each
@@ -26,9 +24,7 @@ down.
The
.I services
given at the command line must be controlled by
-.BR runsv (8),
-or
-.BR supervise (8).
+.BR runsv (8).
.P
.B svwaitdown
blocks, limited by a
@@ -39,7 +35,8 @@ are down or reports errors.
.SH OPTIONS
.TP
.B \-v
-verbose. Print verbose messages to stderr.
+verbose.
+Print verbose messages to stderr.
.TP
.B \-t \fIsec
Set the timeout for waiting for
@@ -48,10 +45,11 @@ to become down to
.I sec
seconds.
.I sec
-must be between 2 and 6000. Default is 600 (10 minutes).
+must be between 1 and 6000. Default is 600 (10 minutes).
.TP
.B \-k
-Kill. If the timeout is reached before all
+Kill.
+If the timeout is reached before all
.I services
are down, tell the
.BR runsv (8)
@@ -60,7 +58,8 @@ processes to send the
a KILL signal.
.TP
.B \-x
-Exit. Send each
+Exit.
+Send each
.I service
the ``exit'' command additionally to the ``down'' command, and wait for the
corresponding
@@ -77,10 +76,8 @@ are down.
If a
.I service
is usually controlled by
-.B runsv (8)
-or
-.BR supervise (8),
-but no supervisor process is currently running,
+.B runsv (8),
+but no supervisor process is currently running in the directory,
.B svwaitdown
treats this
.I service
@@ -94,7 +91,7 @@ increases the exit code by one and exits non zero.
The maximum is 100.
.P
.B svwaitdown
-returns 111 if the timeout
+returns 111 on error, or if the timeout
.I sec
was reached.
.SH SEE ALSO
@@ -110,7 +107,6 @@ runsvdir(8),
runsvchdir(8),
utmpset(8)
.P
- http://smarden.org/runit/
- http://cr.yp.to/daemontools.html
+http://smarden.org/runit/
.SH AUTHOR
Gerrit Pape <pape@smarden.org>
diff --git a/man/svwaitup.8 b/man/svwaitup.8
@@ -1,6 +1,6 @@
.TH svwaitup 8
.SH NAME
-svwaitup \- waits for services controlled by runsv(8) or supervise(8) to be up
+svwaitup \- waits for services controlled by runsv(8) to be up
.SH SYNOPSIS
.B svwaitup
[
@@ -13,22 +13,18 @@ svwaitup \- waits for services controlled by runsv(8) or supervise(8) to be up
.I services
.SH DESCRIPTION
.I services
-consist of one or more arguments.
-Each
-.I service
-directory must start with a slash.
+consists of one or more arguments, each argument naming a service directory.
.P
.B svwaitup
checks each
.I service
given at the command line for being at least the specified number of seconds
.I sec
-up. The
+up.
+The
.I services
given at the command line must be controlled by
-.BR runsv (8),
-or
-.BR supervise (8).
+.BR runsv (8).
.P
.B svwaitup
blocks until all
@@ -41,7 +37,8 @@ was checking or reports errors.
.SH OPTIONS
.TP
.B \-v
-verbose. Print verbose messages to stderr.
+verbose.
+Print verbose messages to stderr.
.TP
.B \-s \fIsec
Set the minimum number of seconds each
@@ -50,7 +47,7 @@ has to be up to
.I sec
seconds.
.I sec
-must be between 2 and 600.
+must be between 1 and 600.
Default is 2.
.SH EXIT CODES
.B svwaitup
@@ -65,7 +62,8 @@ If
.B svwaitup
exits 0, it does not guarantee that all
.I services
-are actually running. A
+are actually running.
+A
.I service
could have crashed immediatly after
.B svwaitup
@@ -102,7 +100,6 @@ runsvdir(8),
runsvchdir(8),
utmpset(8)
.P
- http://smarden.org/runit/
- http://cr.yp.to/daemontools.html
+http://smarden.org/runit/
.SH AUTHOR
Gerrit Pape <pape@smarden.org>
diff --git a/package/CHANGES b/package/CHANGES
@@ -1,3 +1,10 @@
+ * chpst.c: typo.
+ * svwaitdown.c: minimum timeout is 1 second; service directories no longer
+ must start with /.
+ * svwaitup.c: minimum uptime of services is 1 second; service directories
+ no longer must start with /; print number of seconds a service is up if
+ verbose.
+ * man/svwaitdown.8, man/svwaitup.8: adapt.
* doc/runscripts.html: add contributed run scripts (thx Stefan Karrmann,
Kevin Berry, Karl Chen).
diff --git a/src/chpst.c b/src/chpst.c
@@ -97,7 +97,7 @@ void edir(const char *dirname) {
int i;
if (! (wdir =open_read(".")))
- fatal("unable to open current working direcotry");
+ fatal("unable to open current working directory");
if (chdir(dirname)) fatal2("unable to switch to directory", dirname);
if (! (dir =opendir("."))) fatal2("unable to open directory", dirname);
for (;;) {
diff --git a/src/svwaitdown.c b/src/svwaitdown.c
@@ -8,9 +8,9 @@
#include "buffer.h"
#define FATAL "svwaitdown: fatal: "
-#define WARNING "svwaitdown: warning: "
+#define WARN "svwaitdown: warning: "
#define INFO "svwaitdown: "
-#define USAGE " [-v] [-t 2..6000] service ..."
+#define USAGE " [-v] [-t 1..6000] service ..."
#define VERSION "$Id$"
@@ -18,12 +18,12 @@ const char *progname;
const char * const *dir;
unsigned int rc =0;
-void usage() { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
-
+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(WARNING, s1, s2, e);
+ 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;
@@ -31,6 +31,7 @@ int main(int argc, const char * const *argv) {
int verbose =0;
int doexit =0;
int dokill =0;
+ int wdir;
int fd;
char status[20];
int r;
@@ -44,7 +45,7 @@ int main(int argc, const char * const *argv) {
switch(opt) {
case 't':
scan_ulong(optarg, &sec);
- if ((sec < 2) || (sec > 6000)) usage();
+ if ((sec < 1) || (sec > 6000)) usage();
break;
case 'x':
doexit =1;
@@ -64,8 +65,12 @@ int main(int argc, const char * const *argv) {
argv +=optind;
if (! argv || ! *argv) usage();
+ if (! (wdir =open_read(".")))
+ fatal("unable to open current working directory");
+
for (dir =argv; *dir; ++dir) {
- if (*dir[0] != '/') continue; /* bummer */
+ 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)) {
@@ -77,10 +82,7 @@ int main(int argc, const char * const *argv) {
tai_now(&start);
while (*dir) {
- if (*dir[0] != '/') {
- warn(*dir, ": service directory must start with a slash.", 0);
- continue;
- }
+ if (fchdir(wdir) == -1) fatal("unable to switch to starting directory");
if (chdir(*dir) == -1) {
warn(*dir, ": unable to change directory: ", &strerr_sys);
continue;
@@ -167,6 +169,9 @@ int main(int argc, const char * const *argv) {
}
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/svwaitup.c b/src/svwaitup.c
@@ -6,23 +6,24 @@
#include "open.h"
#include "tai.h"
#include "buffer.h"
+#include "fmt.h"
#define FATAL "svwaitup: fatal: "
-#define WARNING "svwaitup: warning: "
+#define WARN "svwaitup: warning: "
#define INFO "svwaitup: "
-#define USAGE " [-v] [-s 2..600] service ..."
+#define USAGE " [-v] [-s 1..600] service ..."
const char *progname;
unsigned long sec =2;
unsigned int rc =0;
const char * const *dir;
-void usage() { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
-
+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(WARNING, s1, s2, e);
+ 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;
@@ -31,17 +32,19 @@ int main(int argc, const char * const *argv) {
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 < 2) || (sec > 600)) usage();
+ if ((sec < 1) || (sec > 600)) usage();
break;
case 'v':
verbose =1;
@@ -55,12 +58,13 @@ int main(int argc, const char * const *argv) {
argv +=optind;
if (! argv || ! *argv) usage();
+ if (! (wdir =open_read(".")))
+ fatal("unable to open current working directory");
+
dir =argv;
while (*dir) {
- if (*dir[0] != '/') {
- warn(*dir, ": service directory must start with a slash.", 0);
- continue;
- }
+ 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;
@@ -105,12 +109,18 @@ int main(int argc, const char * const *argv) {
if (is >= sec) {
/* ok */
- if (verbose) strerr_warn3(INFO, *dir, ": is up.", 0);
+ 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);
}