about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2019-12-31 13:23:46 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2019-12-31 13:23:46 +0000
commit75d32e29d7af2c82c3036ff7c357b3eaea136934 (patch)
treec10477aff692d5ed16e196cbae17ad1a43a0628f /src
parente21fdf5acc140f4c11059153ecf275d56ddc783f (diff)
downloads6-frontend-75d32e29d7af2c82c3036ff7c357b3eaea136934.tar.gz
s6-frontend-75d32e29d7af2c82c3036ff7c357b3eaea136934.tar.xz
s6-frontend-75d32e29d7af2c82c3036ff7c357b3eaea136934.zip
Doc typo fix, sv improvements
Diffstat (limited to 'src')
-rw-r--r--src/alias/s6-frontend-alias-sv.c149
1 files changed, 98 insertions, 51 deletions
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
     {