about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS3
-rw-r--r--doc/s6-frontend-alias-chpst.html2
-rw-r--r--src/alias/s6-frontend-alias-sv.c149
3 files changed, 102 insertions, 52 deletions
diff --git a/AUTHORS b/AUTHORS
index 7a708a1..065b553 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,2 +1,5 @@
 Main author:
   Laurent Bercot <ska-skaware@skarnet.org>
+
+Thanks to:
+  Colin Booth <colin@heliocat.net>
diff --git a/doc/s6-frontend-alias-chpst.html b/doc/s6-frontend-alias-chpst.html
index 8cfe011..73fbf9c 100644
--- a/doc/s6-frontend-alias-chpst.html
+++ b/doc/s6-frontend-alias-chpst.html
@@ -29,7 +29,7 @@ chainloading <a href="//skarnet.org/software/s6/">s6</a> commands.
 <h2> Interface </h2>
 
 <pre>
-     s6-frontend-alias-chpst [ -v ] [ -P ] [ -0 ] [ -1 ] [ -2 ] [ -u <em>user</em> ] [ -U <em>user</em> ] [ -b <em>argv0</em> ] [ -e <em>dir</em> ] [ -/ <em>root</em> ] [ -n <em>inc</em< ] [ -l|-L <em>lock</em> ] [ -m <em>bytes</em> ] [ -d <em>bytes</em> ] [ -o <em>n</em> ] [ -p <em>n</em> ] [ -f <em>bytes</em> ] [ -c <em>bytes</em> ] <em>prog...</em>
+     s6-frontend-alias-chpst [ -v ] [ -P ] [ -0 ] [ -1 ] [ -2 ] [ -u <em>user</em> ] [ -U <em>user</em> ] [ -b <em>argv0</em> ] [ -e <em>dir</em> ] [ -/ <em>root</em> ] [ -n <em>niceness</em> ] [ -l|-L <em>lock</em> ] [ -m <em>bytes</em> ] [ -d <em>bytes</em> ] [ -o <em>n</em> ] [ -p <em>n</em> ] [ -f <em>bytes</em> ] [ -c <em>bytes</em> ] <em>prog...</em>
 </pre>
 
 <p>
diff --git a/src/alias/s6-frontend-alias-sv.c b/src/alias/s6-frontend-alias-sv.c
index e6e0ec8..83ba177 100644
--- a/src/alias/s6-frontend-alias-sv.c
+++ b/src/alias/s6-frontend-alias-sv.c
@@ -9,6 +9,7 @@
 
 #include <skalibs/uint32.h>
 #include <skalibs/sgetopt.h>
+#include <skalibs/buffer.h>
 #include <skalibs/strerr2.h>
 #include <skalibs/djbunix.h>
 
@@ -86,8 +87,45 @@ static int complex_svc (char const *dir, char const *order, char waitfor, char c
 
 static int status (char const *dir, char const *const *envp)
 {
+  int e ;
   char const *argv[4] = { S6_EXTBINPREFIX "s6-svstat", "--", dir, 0 } ;
-  return spawnit(argv, envp) ;
+  size_t dirlen = strlen(dir) ;
+  buffer_puts(buffer_1, dir) ;
+  buffer_putsflush(buffer_1, ": ") ;
+  e = spawnit(argv, envp) ;
+  if (dirlen < 5 || strcmp(dir + dirlen - 4, "/log"))
+  {
+    struct stat st ;
+    char log[dirlen + 5] ;
+    memcpy(log, dir, dirlen) ;
+    memcpy(log + dirlen, "/log", 5) ;
+    if (stat(log, &st) < 0)
+    {
+      if (errno != ENOENT)
+      {
+        strerr_warnwu2sys("stat", log) ;
+        e = 1 ;
+      }
+    }
+    else if (S_ISDIR(st.st_mode))
+    {
+      argv[2] = log ;
+      buffer_puts(buffer_1, log) ;
+      buffer_putsflush(buffer_1, ": ") ;
+      e |= spawnit(argv, envp) ;
+    }
+  }
+  return e ;
+}
+
+static int action (char const *dir, char const *simple, char const *cplx, char waitchar, char const *const *envp)
+{
+  if (dowait)
+  {
+    int e = complex_svc(dir, cplx, waitchar, envp) ;
+    return e | status(dir, envp) ;
+  }
+  else return simple_svc(dir, simple, envp) ;
 }
 
 static int usr1_h (char const *dir, char const *const *envp)
@@ -107,33 +145,21 @@ static int alarm_h (char const *dir, char const *const *envp)
 
 static int cont_h (char const *dir, char const *const *envp)
 {
-  if (dowait)
-  {
-    complex_svc(dir, "-o", 'U', envp) ;
-    return status(dir, envp) ;
-  }
-  else return simple_svc(dir, "-c", envp) ;
+  return action(dir, "-c", "-o", 'U', envp) ;
 }
 
 static int down (char const *dir, char const *const *envp)
 {
-  if (dowait)
-  {
-    complex_svc(dir, "-d", 'D', envp) ;
-    return status(dir, envp) ;
-  }
-  else return simple_svc(dir, "-d", envp) ;
+  return action(dir, "-d", "-d", 'D', envp) ;
 }
 
 static int bail (char const *dir, char const *const *envp)
 {
+  int e ;
   warnnolog() ;
-  if (dowait)
-  {
-    complex_svc(dir, "-d", 'D', envp) ;
-    status(dir, envp) ;
-  }
-  return simple_svc(dir, "-xd", envp) ;
+  e = action(dir, "-xd", "-d", 'D', envp) ;
+  if (dowait) e |= simple_svc(dir, "-x", envp) ;
+  return e ;
 }
 
 static int hup_h (char const *dir, char const *const *envp)
@@ -153,12 +179,7 @@ static int kill_h (char const *dir, char const *const *envp)
 
 static int once (char const *dir, char const *const *envp)
 {
-  if (dowait)
-  {
-    complex_svc(dir, "-o", 'U', envp) ;
-    return status(dir, envp) ;
-  }
-  else return simple_svc(dir, "-o", envp) ;
+  return action(dir, "-o", "-o", 'U', envp) ;
 }
 
 static int pause_h (char const *dir, char const *const *envp)
@@ -173,26 +194,17 @@ static int quit_h (char const *dir, char const *const *envp)
 
 static int term_h (char const *dir, char const *const *envp)
 {
-  if (dowait)
-  {
-    complex_svc(dir, "-r", 'R', envp) ;
-    return status(dir, envp) ;
-  }
-  else return simple_svc(dir, "-t", envp) ;
+  return action(dir, "-t", "-r", 'R', envp) ;
 }
 
 static int up (char const *dir, char const *const *envp)
 {
-  if (dowait)
-  {
-    complex_svc(dir, "-u", 'U', envp) ;
-    return status(dir, envp) ;
-  }
-  else return simple_svc(dir, "-u", envp) ;
+  return action(dir, "-u", "-u", 'U', envp) ;
 }
 
 static int check (char const *dir, char const *const *envp)
 {
+  int e ;
   s6_svstatus_t svst ;
   char warg[3] = "-?" ;
   char fmt[2 + UINT32_FMT] = "-t" ;
@@ -200,8 +212,8 @@ static int check (char const *dir, char const *const *envp)
   fmt[2 + uint32_fmt(fmt + 2, 1000 * secs)] = 0 ;
   if (!s6_svstatus_read(dir, &svst)) return 1 ;
   warg[1] = svst.flagwantup ? 'U' : 'D' ;
-  spawnit(argv, envp) ;
-  return status(dir, envp) ;
+  e = spawnit(argv, envp) ;
+  return e | status(dir, envp) ;
 }
 
 static int lsb_reload (char const *dir, char const *const *envp)
@@ -212,28 +224,29 @@ static int lsb_reload (char const *dir, char const *const *envp)
 
 static int lsb_restart (char const *dir, char const *const *envp)
 {
-  complex_svc(dir, "-ru", 'U', envp) ;
-  return status(dir, envp) ;
+  int e = complex_svc(dir, "-ru", 'U', envp) ;
+  return e | status(dir, envp) ;
 }
 
 static int lsb_start (char const *dir, char const *const *envp)
 {
-  complex_svc(dir, "-u", 'U', envp) ;
-  return status(dir, envp) ;
+  int e = complex_svc(dir, "-u", 'U', envp) ;
+  return e | status(dir, envp) ;
 }
 
 static int lsb_stop (char const *dir, char const *const *envp)
 {
-  complex_svc(dir, "-d", 'D', envp) ;
-  return status(dir, envp) ;
+  int e = complex_svc(dir, "-d", 'D', envp) ;
+  return e | status(dir, envp) ;
 }
 
 static int lsb_shutdown (char const *dir, char const *const *envp)
 {
+  int e ;
   warnnolog() ;
-  complex_svc(dir, "-d", 'D', envp) ;
-  status(dir, envp) ;
-  return simple_svc(dir, "-x", envp) ;
+  e = complex_svc(dir, "-d", 'D', envp) ;
+  e |= status(dir, envp) ;
+  return e | simple_svc(dir, "-x", envp) ;
 }
 
 static int lsb_forcereload (char const *dir, char const *const *envp)
@@ -262,10 +275,11 @@ static int lsb_forceshutdown (char const *dir, char const *const *envp)
 
 static int lsb_tryrestart (char const *dir, char const *const *envp)
 {
+  int e = 0 ;
   s6_svstatus_t svst ;
   if (s6_svstatus_read(dir, &svst) && svst.flagwantup && svst.pid && !svst.flagfinishing)
-    complex_svc(dir, "-r", 'U', envp) ;    
-  return status(dir, envp) ;
+    e = complex_svc(dir, "-r", 'U', envp) ;    
+  return e | status(dir, envp) ;
 }
 
 static info_t const commands[] =
@@ -273,38 +287,70 @@ static info_t const commands[] =
   { .name = "1", .f = &usr1_h },
   { .name = "2", .f = &usr2_h },
   { .name = "a", .f = &alarm_h },
+  { .name = "al", .f = &alarm_h },
+  { .name = "ala", .f = &alarm_h },
+  { .name = "alar", .f = &alarm_h },
   { .name = "alarm", .f = &alarm_h },
   { .name = "c", .f = &cont_h },
   { .name = "check", .f = &check },
+  { .name = "co", .f = &cont_h },
+  { .name = "con", .f = &cont_h },
   { .name = "cont", .f = &cont_h },
   { .name = "d", .f = &down },
+  { .name = "do", .f = &down },
+  { .name = "dow", .f = &down },
   { .name = "down", .f = &down },
   { .name = "e", .f = &bail },
+  { .name = "ex", .f = &bail },
+  { .name = "exi", .f = &bail },
   { .name = "exit", .f = &bail },
   { .name = "force-reload", .f = &lsb_forcereload },
   { .name = "force-restart", .f = &lsb_forcerestart },
   { .name = "force-shutdown", .f = &lsb_forceshutdown },
   { .name = "force-stop", .f = &lsb_forcestop },
   { .name = "h", .f = &hup_h },
+  { .name = "hu", .f = &hup_h },
   { .name = "hup", .f = &hup_h },
   { .name = "i", .f = &int_h },
+  { .name = "in", .f = &int_h },
+  { .name = "int", .f = &int_h },
+  { .name = "inte", .f = &int_h },
+  { .name = "inter", .f = &int_h },
+  { .name = "interr", .f = &int_h },
+  { .name = "interru", .f = &int_h },
+  { .name = "interrup", .f = &int_h },
   { .name = "interrupt", .f = &int_h },
   { .name = "k", .f = &kill_h },
+  { .name = "ki", .f = &kill_h },
+  { .name = "kil", .f = &kill_h },
   { .name = "kill", .f = &kill_h },
   { .name = "o", .f = &once },
+  { .name = "on", .f = &once },
+  { .name = "onc", .f = &once },
   { .name = "once", .f = &once },
   { .name = "p", .f = &pause_h },
+  { .name = "pa", .f = &pause_h },
+  { .name = "pau", .f = &pause_h },
+  { .name = "paus", .f = &pause_h },
   { .name = "pause", .f = &pause_h },
   { .name = "q", .f = &quit_h },
+  { .name = "qu", .f = &quit_h },
+  { .name = "qui", .f = &quit_h },
   { .name = "quit", .f = &quit_h },
   { .name = "reload", .f = &lsb_reload },
   { .name = "restart", .f = &lsb_restart },
   { .name = "s", .f = &status },
   { .name = "shutdown", .f = &lsb_shutdown },
+  { .name = "st", .f = &status },
+  { .name = "sta", .f = &status },
   { .name = "start", .f = &lsb_start },
+  { .name = "stat", .f = &status },
+  { .name = "statu", .f = &status },
   { .name = "status", .f = &status },
   { .name = "stop", .f = &lsb_stop },
   { .name = "t", .f = &term_h },
+  { .name = "te", .f = &term_h },
+  { .name = "ter", .f = &term_h },
   { .name = "term", .f = &term_h },
   { .name = "try-restart", .f = &lsb_tryrestart },
   { .name = "u", .f = &up },
@@ -349,7 +395,8 @@ int main (int argc, char const *const *argv, char const *const *envp)
 
   for (argv++ ; *argv ; argv++)
   {
-    if ((argv[0][0] == '.' && (argv[0][1] == '/' || (argv[0][1] == '.' && argv[0][2] == '/'))) || argv[0][0] == '/')
+    if (!argv[0][0]) continue ;
+    if (argv[0][0] == '/' || argv[0][strlen(argv[0]) - 1] == '/' || (argv[0][0] == '.' && (!argv[0][1] || argv[0][1] == '/' || (argv[0][1] == '.' && (!argv[0][2] || argv[0][2] == '/')))))
       e += (*p->f)(*argv, envp) ;
     else
     {