commit e8fce3d2cc5adda429ce09428adde4187e026454
parent e91c33fd2a066898fa5afb1a75638bb16fe78902
Author: Gerrit Pape <pape@smarden.org>
Date: Mon, 24 Jul 2006 21:01:36 +0000
* svlogd.c, fmt_ptime.*, man/svlogd.8: new option -ttt: prefix log
messages with sortable UTC timestamp YYYY-MM-DDTHH:MM:SS.xxxxx.
* runsv.c, runsv.8: give to arguments to ./finish: exit code and exit
status of ./run (mostly copied from pipe-tools' npt-supervise, thx
Laurent Bercot).
Diffstat:
7 files changed, 56 insertions(+), 15 deletions(-)
diff --git a/man/runsv.8 b/man/runsv.8
@@ -24,6 +24,17 @@ If ./run or ./finish exit immediately,
.B runsv
waits a second before starting ./finish or restarting ./run.
.P
+Two arguments are given to ./finish.
+The first one is ./run's exit code, or -1 if ./run didn't exit normally.
+The second one is the least significant byte of the exit status as
+determined by
+.BR waitpid (2);
+for instance it is 0 if ./run exited normally, and the signal number
+if ./run was terminated by a signal.
+If
+.B runsv
+cannot start ./run for some reason, the exit code is 111 and the status is 0.
+.P
If the file
.IR service /down
exists,
diff --git a/man/svlogd.8 b/man/svlogd.8
@@ -3,7 +3,7 @@
svlogd \- runit's service logging daemon
.SH SYNOPSIS
.B svlogd
-[\-ttv] [\-r
+[\-tttv] [\-r
.I c\fR] [\-R
.I xyz\fR] [\-l
.I len\fR] [\-b
@@ -368,6 +368,13 @@ the form YYYY-MM-DD_HH:MM:SS.xxxxx when writing to
.I log
or to standard error.
.TP
+.B \-ttt
+timestamp.
+Prefix each selected line with a human readable, sortable UTC timestamp of
+the form YYYY-MM-DDTHH:MM:SS.xxxxx when writing to
+.I log
+or to standard error.
+.TP
.B \-r \fIc
replace.
.I c
diff --git a/package/CHANGES b/package/CHANGES
@@ -1,3 +1,11 @@
+1.7.0
+
+ * svlogd.c, fmt_ptime.*, man/svlogd.8: new option -ttt: prefix log
+ messages with sortable UTC timestamp YYYY-MM-DDTHH:MM:SS.xxxxx.
+ * runsv.c, runsv.8: give to arguments to ./finish: exit code and exit
+ status of ./run (mostly copied from pipe-tools' npt-supervise, thx
+ Laurent Bercot).
+
1.6.0
Thu, 29 Jun 2006 07:52:35 +0000
* svlogd.c: cleanup *.t files possibly leftover by processor when
diff --git a/src/fmt_ptime.c b/src/fmt_ptime.c
@@ -2,7 +2,7 @@
#include "fmt_ptime.h"
#include "fmt.h"
-unsigned int fmt_ptime(char *s, struct taia *ta) {
+unsigned int fmt_ptime2(char *s, struct taia *ta, char sep) {
struct tm *t;
unsigned long u;
@@ -12,13 +12,21 @@ unsigned int fmt_ptime(char *s, struct taia *ta) {
fmt_ulong(s, 1900 +t->tm_year);
s[4] ='-'; fmt_uint0(&s[5], t->tm_mon +1, 2);
s[7] ='-'; fmt_uint0(&s[8], t->tm_mday, 2);
- s[10] ='_'; fmt_uint0(&s[11], t->tm_hour, 2);
+ s[10] =sep; fmt_uint0(&s[11], t->tm_hour, 2);
s[13] =':'; fmt_uint0(&s[14], t->tm_min, 2);
s[16] =':'; fmt_uint0(&s[17], t->tm_sec, 2);
s[19] ='.'; fmt_uint0(&s[20], ta->nano, 9);
return(25);
}
+unsigned int fmt_ptime(char *s, struct taia *ta) {
+ return(fmt_ptime2(s, ta, '_'));
+}
+
+unsigned int fmt_ptime_iso8601(char *s, struct taia *ta) {
+ return(fmt_ptime2(s, ta, 'T'));
+}
+
unsigned int fmt_taia(char *s, struct taia *t) {
static char hex[16] ="0123456789abcdef";
static char pack[TAIA_PACK];
diff --git a/src/fmt_ptime.h b/src/fmt_ptime.h
@@ -8,6 +8,7 @@
#include "taia.h"
extern unsigned int fmt_ptime(char *, struct taia *);
+extern unsigned int fmt_ptime_iso8601(char *, struct taia *);
extern unsigned int fmt_taia(char *, struct taia *);
#endif
diff --git a/src/runsv.c b/src/runsv.c
@@ -46,6 +46,7 @@ struct svdir {
int ctrl;
int want;
struct taia start;
+ int wstat;
int fdlock;
int fdcontrol;
int fdcontrolwrite;
@@ -260,15 +261,23 @@ void stopservice(struct svdir *s) {
void startservice(struct svdir *s) {
int p;
- char *run[2];
+ char *run[4];
+ char code[FMT_ULONG];
+ char stat[FMT_ULONG];
- if (s->state == S_FINISH)
+ if (s->state == S_FINISH) {
run[0] ="./finish";
+ code[fmt_ulong(code, wait_exitcode(s->wstat))] =0;
+ run[1] =wait_crashed(s->wstat) ? "-1" : code;
+ stat[fmt_ulong(stat, s->wstat & 0xff)] =0;
+ run[2] =stat;
+ run[3] =0;
+ }
else {
run[0] ="./run";
custom(s, 'u');
+ run[1] =0;
}
- run[1] =0;
if (s->pid != 0) stopservice(s); /* should never happen */
while ((p =fork()) == -1) {
@@ -539,6 +548,7 @@ int main(int argc, char **argv) {
if (child == svd[0].pid) {
svd[0].pid =0;
pidchanged =1;
+ svd[0].wstat =wstat;
svd[0].ctrl &=~C_TERM;
if (svd[0].state != S_FINISH)
if ((fd =open_read("finish")) != -1) {
diff --git a/src/svlogd.c b/src/svlogd.c
@@ -694,7 +694,7 @@ int main(int argc, const char **argv) {
if (buflen == 0) buflen =1024;
break;
case 't':
- if (++timestamp > 2) timestamp =2;
+ if (++timestamp > 3) timestamp =3;
break;
case 'v':
++verbose;
@@ -752,15 +752,11 @@ int main(int argc, const char **argv) {
if (! linelen && timestamp) {
taia_now(&now);
switch (timestamp) {
- case 1:
- stamp[fmt_taia(stamp, &now)] =' ';
- stamp[26] =0;
- break;
- case 2:
- stamp[fmt_ptime(stamp, &now)] =' ';
- stamp[26] =0;
- break;
+ case 1: fmt_taia(stamp, &now); break;
+ case 2: fmt_ptime(stamp, &now); break;
+ case 3: fmt_ptime_iso8601(stamp, &now); break;
}
+ stamp[25] =' '; stamp[26] =0;
}
if (ch == '\n') break;
if (repl) {