[PATCH] sv.c: properly format status command's output on failure cases.

From: Gerrit Pape <pape_at_smarden.org>
Date: Fri, 1 Aug 2014 08:44:33 +0000

On Tue, Jul 29, 2014 at 03:11:11PM +0000, Gerrit Pape wrote:
> > $ sudo sv s foo
> > run: foo: (pid 4885) 526260s; run: log: (pid 875) 526517s
> > $ sudo sv s baz
> > run: baz: (pid 2337) 2983swarning: baz: unable to open supervise/ok:
> > file does not exist

> The warning actually should be fine and applies to the log service, but
> not how the output os formatted.

Here's a patch to improve the output format.


      * sv.c: properly format status command's output on failure cases.
---
 package/CHANGES |  1 +
 src/sv.c        | 20 ++++++++++++--------
 2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/package/CHANGES b/package/CHANGES
index 5779ec3..c747f8a 100644
--- a/package/CHANGES
+++ b/package/CHANGES
_at_@ -1,5 +1,6 @@
 2.1.2
 
+  * sv.c: properly format status command's output on failure cases.
   * runsv.c, sv.c: on exit, properly wait for log service to terminate.
   * man/runsv.8, man/sv.8: adapt.
   * sv.c: support optional LSB init script actions reload and
diff --git a/src/sv.c b/src/sv.c
index f3e7518..1afa3a3 100644
--- a/src/sv.c
+++ b/src/sv.c
_at_@ -42,6 +42,7 @@ unsigned int lsb;
 unsigned int verbose =0;
 unsigned long wait =7;
 unsigned int kll =0;
+unsigned int islog =0;
 struct taia tstart, tnow, tdiff;
 struct tai tstatus;
 
_at_@ -68,6 +69,7 @@ void fatal2(char *m1, char *m2) {
 void out(char *p, char *m1) {
   buffer_puts(buffer_1, p);
   buffer_puts(buffer_1, *service);
+  if (islog) buffer_puts(buffer_1, "/log");
   buffer_puts(buffer_1, ": ");
   buffer_puts(buffer_1, m1);
   if (errno) {
_at_@ -158,18 +160,20 @@ int status(char *unused) {
   rc =svstatus_get();
   switch(rc) { case -1: if (lsb) done(4); case 0: return(0); }
   rc =svstatus_print(*service);
+  islog =1;
   if (chdir("log") == -1) {
     if (errno != error_noent) {
-      outs("; log: "); outs(WARN);
-      outs("unable to change to log service directory: ");
-      outs(error_str(errno));
+      outs("; ");
+      warn("unable to change directory");
     }
+    else outs("\n");
   }
-  else
-    if (svstatus_get()) {
-      outs("; "); svstatus_print("log");
-    }
-  flush("\n");
+  else {
+    outs("; ");
+    if (svstatus_get()) { rc =svstatus_print("log"); outs("\n"); }
+  }
+  islog =0;
+  flush("");
   if (lsb) switch(rc) { case 1: done(0); case 2: done(3); case 0: done(4); }
   return(rc);
 }
Received on Fri Aug 01 2014 - 08:44:33 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:44:18 UTC