From 256c8a0cf9b4590aca1ce968a8f44d689f7e3cca Mon Sep 17 00:00:00 2001
From: obarun <eric@obarun.org>
Date: Sat, 16 Jan 2021 18:54:23 +1100
Subject: [PATCH] repeat tool interface at help call

---
 src/66/66-boot.c                |  4 +---
 src/66/66-hpr.c                 |  7 +++----
 src/66/66-inresolve.c           |  6 ++----
 src/66/66-inservice.c           |  6 ++----
 src/66/66-instate.c             |  6 ++----
 src/66/66-intree.c              |  4 +---
 src/66/66-parser.c              |  5 +----
 src/66/66-scanctl.c             |  5 +----
 src/66/66-scandir.c             |  5 +----
 src/66/66-shutdown.c            |  6 +++---
 src/66/66-shutdownd.c           |  5 +----
 src/66/66-tree.c                |  5 +----
 src/66/66-update.c              |  7 +++----
 src/extra-tools/66-echo.c       |  5 ++---
 src/extra-tools/execl-envfile.c |  4 +---
 src/lib66/ssexec_help.c         |  9 ---------
 src/lib66/ssexec_main.c         | 10 +++++-----
 17 files changed, 30 insertions(+), 69 deletions(-)

diff --git a/src/66/66-boot.c b/src/66/66-boot.c
index 9f4f2a2b..f7c0089a 100644
--- a/src/66/66-boot.c
+++ b/src/66/66-boot.c
@@ -33,7 +33,6 @@
 #include <oblibs/environ.h>
 #include <oblibs/sastr.h>
 
-#include <skalibs/buffer.h>
 #include <skalibs/djbunix.h>
 #include <skalibs/stralloc.h>
 #include <skalibs/types.h>
@@ -94,7 +93,6 @@ static void sulogin(char const *msg,char const *arg)
 static inline void info_help (void)
 {
   static char const *help =
-"66-boot <options>\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -107,7 +105,7 @@ static inline void info_help (void)
 "   -b: banner to display\n"
 ;
 
- if (buffer_putsflush(buffer_1, help) < 0) sulogin("","") ;
+    log_info(USAGE,"\n",help) ;
 }
 
 static int read_line(stralloc *dst, char const *line)
diff --git a/src/66/66-hpr.c b/src/66/66-hpr.c
index a7082144..65ee7d72 100644
--- a/src/66/66-hpr.c
+++ b/src/66/66-hpr.c
@@ -30,7 +30,6 @@
 #include <skalibs/sig.h>
 #include <skalibs/tai.h>
 #include <skalibs/djbunix.h>
-#include <skalibs/buffer.h>
 
 #include <66/hpr.h>
 #include <66/config.h>
@@ -55,7 +54,6 @@ char const *live = 0 ;
 static inline void info_help (void)
 {
   static char const *help =
-"66-hpr <options>\n"
 "\n"
 "options :\n"
 "   -H: print this help\n"
@@ -70,9 +68,10 @@ static inline void info_help (void)
 "   -w: only write wtmp shutdown entry\n"
 "   -W: do not send a wall message\n"
 ;
-    if (buffer_putsflush(buffer_1, help) < 0)
-        log_dieusys(LOG_EXIT_SYS, "write to stdout") ;
+
+    log_info(USAGE,"\n",help) ;
 }
+
 int main (int argc, char const *const *argv)
 {
     int what = 0 ;
diff --git a/src/66/66-inresolve.c b/src/66/66-inresolve.c
index ff231f5f..81f89bfc 100644
--- a/src/66/66-inresolve.c
+++ b/src/66/66-inresolve.c
@@ -21,10 +21,10 @@
 #include <oblibs/obgetopt.h>
 #include <oblibs/types.h>
 
-#include <skalibs/buffer.h>
 #include <skalibs/types.h>
 #include <skalibs/stralloc.h>
 #include <skalibs/lolstdio.h>
+#include <skalibs/buffer.h>
 
 #include <66/resolve.h>
 #include <66/info.h>
@@ -41,7 +41,6 @@ static char fields[INFO_NKEY][INFO_FIELD_MAXLEN] = {{ 0 }} ;
 static inline void info_help (void)
 {
   static char const *help =
-"66-inresolve <options> service \n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -50,8 +49,7 @@ static inline void info_help (void)
 "   -l: prints information of the associated logger if exist\n"
 ;
 
- if (buffer_putsflush(buffer_1, help) < 0)
-    log_dieusys(LOG_EXIT_SYS, "write to stdout") ;
+    log_info(USAGE,"\n",help) ;
 }
 
 static void info_display_string(char const *field,char const *str)
diff --git a/src/66/66-inservice.c b/src/66/66-inservice.c
index 87358235..9bcdc3e1 100644
--- a/src/66/66-inservice.c
+++ b/src/66/66-inservice.c
@@ -31,8 +31,8 @@
 #include <skalibs/genalloc.h>
 #include <skalibs/lolstdio.h>
 #include <skalibs/bytestr.h>
-#include <skalibs/buffer.h>
 #include <skalibs/djbunix.h>
+#include <skalibs/buffer.h>
 
 #include <66/info.h>
 #include <66/utils.h>
@@ -109,7 +109,6 @@ info_opts_map_t const opts_sv_table[] =
 static inline void info_help (void)
 {
   static char const *help =
-"66-inservice <options> service \n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -145,8 +144,7 @@ static inline void info_help (void)
 "   logfile: displays the contents of the log file\n"
 ;
 
- if (buffer_putsflush(buffer_1, help) < 0)
-    log_dieusys(LOG_EXIT_SYS, "write to stdout") ;
+    log_info(USAGE,"\n",help) ;
 }
 
 char *print_nlog(char *str, int n)
diff --git a/src/66/66-instate.c b/src/66/66-instate.c
index cd116842..73cc87c8 100644
--- a/src/66/66-instate.c
+++ b/src/66/66-instate.c
@@ -21,10 +21,10 @@
 #include <oblibs/obgetopt.h>
 #include <oblibs/types.h>
 
-#include <skalibs/buffer.h>
 #include <skalibs/types.h>
 #include <skalibs/stralloc.h>
 #include <skalibs/lolstdio.h>
+#include <skalibs/buffer.h>
 
 #include <66/resolve.h>
 #include <66/info.h>
@@ -42,7 +42,6 @@ static char fields[INFO_NKEY][INFO_FIELD_MAXLEN] = {{ 0 }} ;
 static inline void info_help (void)
 {
   static char const *help =
-"66-instate <options> service \n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -51,8 +50,7 @@ static inline void info_help (void)
 "   -l: prints information of the associated logger if exist\n"
 ;
 
- if (buffer_putsflush(buffer_1, help) < 0)
-    log_dieusys(LOG_EXIT_SYS, "write to stdout") ;
+    log_info(USAGE,"\n",help) ;
 }
 
 static void info_display_string(char const *field,char const *str)
diff --git a/src/66/66-intree.c b/src/66/66-intree.c
index 97ebc572..c8e8019c 100644
--- a/src/66/66-intree.c
+++ b/src/66/66-intree.c
@@ -85,7 +85,6 @@ info_opts_map_t const opts_tree_table[] =
 static inline void info_help (void)
 {
   static char const *help =
-"66-intree <options> tree \n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -110,8 +109,7 @@ static inline void info_help (void)
 "   contents: displays the contents of the tree\n"
 ;
 
- if (buffer_putsflush(buffer_1, help) < 0)
-    log_dieusys(LOG_EXIT_SYS, "write to stdout") ;
+    log_info(USAGE,"\n",help) ;
 }
 
 static int info_cmpnsort(stralloc *sa)
diff --git a/src/66/66-parser.c b/src/66/66-parser.c
index 8abcd22e..ca40cb50 100644
--- a/src/66/66-parser.c
+++ b/src/66/66-parser.c
@@ -25,7 +25,6 @@
 #include <oblibs/string.h>
 #include <oblibs/sastr.h>
 
-#include <skalibs/buffer.h>
 #include <skalibs/stralloc.h>
 #include <skalibs/djbunix.h>
 
@@ -38,7 +37,6 @@
 static inline void info_help (void)
 {
   static char const *help =
-"66-parser <options> service destination\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -48,8 +46,7 @@ static inline void info_help (void)
 "   -I: do not import modified configuration files from previous version\n"
 ;
 
- if (buffer_putsflush(buffer_1, help) < 0)
-    log_dieusys(LOG_EXIT_SYS, "write to stdout") ;
+    log_info(USAGE,"\n",help) ;
 }
 
 static void check_dir(char const *dir,uint8_t force,int main)
diff --git a/src/66/66-scanctl.c b/src/66/66-scanctl.c
index fcdb5067..0575077b 100644
--- a/src/66/66-scanctl.c
+++ b/src/66/66-scanctl.c
@@ -20,7 +20,6 @@
 #include <oblibs/string.h>
 #include <oblibs/environ.h>
 
-#include <skalibs/buffer.h>
 #include <skalibs/stralloc.h>
 #include <skalibs/types.h>
 #include <skalibs/djbunix.h>
@@ -36,7 +35,6 @@ static char TMPENV[MAXENV + 1] ;
 static inline void info_help (void)
 {
   static char const *help =
-"66-scanctl <options> signal\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -49,8 +47,7 @@ static inline void info_help (void)
 "   -o: handles scandir of owner\n"
 ;
 
- if (buffer_putsflush(buffer_1, help) < 0)
-    log_dieusys(LOG_EXIT_SYS, "write to stdout") ;
+    log_info(USAGE,"\n",help) ;
 }
 
 static inline unsigned int lookup (char const *const *table, char const *signal)
diff --git a/src/66/66-scandir.c b/src/66/66-scandir.c
index 73845a87..799ff93a 100644
--- a/src/66/66-scandir.c
+++ b/src/66/66-scandir.c
@@ -26,7 +26,6 @@
 #include <oblibs/string.h>
 #include <oblibs/environ.h>
 
-#include <skalibs/buffer.h>
 #include <skalibs/stralloc.h>
 #include <skalibs/djbunix.h>
 #include <skalibs/types.h>
@@ -71,7 +70,6 @@ static unsigned int CATCH_LOG = SS_BOOT_CATCH_LOG ;
 static inline void info_help (void)
 {
   static char const *help =
-"66-scandir <options> create|remove\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -86,8 +84,7 @@ static inline void info_help (void)
 "   -o: handles owner scandir\n"
 ;
 
-    if (buffer_putsflush(buffer_1, help) < 0)
-        log_dieusys(LOG_EXIT_SYS, "write to stdout") ;
+    log_info(USAGE,"\n",help) ;
 }
 
 static inline unsigned int lookup (char const *const *table, char const *signal)
diff --git a/src/66/66-shutdown.c b/src/66/66-shutdown.c
index 26797ffc..9bc6cec9 100644
--- a/src/66/66-shutdown.c
+++ b/src/66/66-shutdown.c
@@ -55,7 +55,6 @@ static char const *live = 0 ;
 static inline void info_help (void)
 {
   static char const *help =
-"66-shutdown <options> time [message] or 66-shutdown -c [ message ]\n"
 "\n"
 "options :\n"
 "   -H: print this help\n"
@@ -71,9 +70,10 @@ static inline void info_help (void)
 "   -t: grace time between the SIGTERM and the SIGKILL\n"
 "   -c: cancel planned shutdown\n"
 ;
-    if (buffer_putsflush(buffer_1, help) < 0)
-        log_dieusys(LOG_EXIT_SYS, "write to stdout") ;
+
+    log_info(USAGE,"\n",help) ;
 }
+
 /* shutdown 01:23: date/time format parsing */
 
 static inline void add_one_day (struct tm *tm)
diff --git a/src/66/66-shutdownd.c b/src/66/66-shutdownd.c
index 916a2268..1d3e776e 100644
--- a/src/66/66-shutdownd.c
+++ b/src/66/66-shutdownd.c
@@ -35,7 +35,6 @@
 #include <skalibs/types.h>
 #include <skalibs/allreadwrite.h>
 #include <skalibs/bytestr.h>
-#include <skalibs/buffer.h>
 #include <skalibs/sgetopt.h>
 #include <skalibs/sig.h>
 #include <skalibs/tai.h>
@@ -68,7 +67,6 @@ static int nologger = 0 ;
 static inline void info_help (void)
 {
   static char const *help =
-"66-shutdownd <options>\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -79,8 +77,7 @@ static inline void info_help (void)
 "   -c: the catch-all logger do not exist\n"
 ;
 
-    if (buffer_putsflush(buffer_1, help) < 0)
-        log_dieusys(LOG_EXIT_SYS, "write to stdout") ;
+    log_info(USAGE,"\n",help) ;
 }
 
 static void restore_console (void)
diff --git a/src/66/66-tree.c b/src/66/66-tree.c
index 3542326c..57edcb62 100644
--- a/src/66/66-tree.c
+++ b/src/66/66-tree.c
@@ -29,7 +29,6 @@
 
 #include <skalibs/stralloc.h>
 #include <skalibs/djbunix.h>
-#include <skalibs/buffer.h>
 #include <skalibs/bytestr.h>//byte_count
 
 #include <66/config.h>
@@ -52,7 +51,6 @@ static char const *cleantree = 0 ;
 static inline void info_help (void)
 {
   static char const *help =
-"66-tree <options> tree\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -71,8 +69,7 @@ static inline void info_help (void)
 "   -U: unsupervise the tree\n"
 ;
 
- if (buffer_putsflush(buffer_1, help) < 0)
-    log_dieusys(111,"write to stdout") ;
+    log_info(USAGE,"\n",help) ;
 }
 
 static void cleanup(void)
diff --git a/src/66/66-update.c b/src/66/66-update.c
index 60c3a975..c79f43db 100644
--- a/src/66/66-update.c
+++ b/src/66/66-update.c
@@ -25,7 +25,6 @@
 #include <oblibs/files.h>
 
 #include <skalibs/stralloc.h>
-#include <skalibs/buffer.h>
 #include <skalibs/sgetopt.h>
 #include <skalibs/djbunix.h>
 #include <skalibs/unix-transactional.h>
@@ -48,8 +47,9 @@ static uint8_t DRYRUN = 0 ;
 static char *drun = "dry run do: " ;
 static inline void info_help (void)
 {
+    DEFAULT_MSG = 0 ;
+
   static char const *help =
-"66-update <options> tree(s)\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -61,8 +61,7 @@ static inline void info_help (void)
 "if no tree is given, all trees will be processed.\n"
 ;
 
- if (buffer_putsflush(buffer_1, help) < 0)
-    log_dieusys(LOG_EXIT_SYS, "write to stdout") ;
+    log_info(USAGE,"\n",help) ;
 }
 
 static void cleanup(void)
diff --git a/src/extra-tools/66-echo.c b/src/extra-tools/66-echo.c
index d484a955..85878e16 100644
--- a/src/extra-tools/66-echo.c
+++ b/src/extra-tools/66-echo.c
@@ -26,15 +26,14 @@
 static inline void info_help (void)
 {
   static char const *help =
-"66-echo <options> args\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
 "   -n: do not output a trailing newline\n"
 "   -s: use as character separator\n"
 ;
-    if (buffer_putsflush(buffer_1, help) < 0)
-        log_dieusys(LOG_EXIT_SYS, "write to stdout") ;
+
+    log_info(USAGE,"\n",help) ;
 }
 
 int main (int argc, char const *const *argv)
diff --git a/src/extra-tools/execl-envfile.c b/src/extra-tools/execl-envfile.c
index 976f3925..a7265f24 100644
--- a/src/extra-tools/execl-envfile.c
+++ b/src/extra-tools/execl-envfile.c
@@ -38,15 +38,13 @@
 static inline void info_help (void)
 {
   static char const *help =
-"execl-envfile <options> src prog\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
 "   -l: loose\n"
 ;
 
- if (buffer_putsflush(buffer_1, help) < 0)
-    log_dieusys(LOG_EXIT_SYS, "write to stdout") ;
+    log_info(USAGE,"\n",help) ;
 }
 
 void clean_n_unexport(stralloc *modifs, stralloc *dst, stralloc *src,char const *file)
diff --git a/src/lib66/ssexec_help.c b/src/lib66/ssexec_help.c
index f30fc149..ffec6776 100644
--- a/src/lib66/ssexec_help.c
+++ b/src/lib66/ssexec_help.c
@@ -17,7 +17,6 @@
 char const *usage_enable = "66-enable [ -h ] [ -z ] [ -v verbosity ] [ - l live ] [ -t tree ] [ -f|F ] [ -I ] [ -S ] service(s)" ;
 
 char const *help_enable =
-"66-enable <options> service(s)\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -34,7 +33,6 @@ char const *help_enable =
 char const *usage_dbctl = "66-dbctl [ -h ] [ -z ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -u | d | r ] service(s)" ;
 
 char const *help_dbctl =
-"66-dbctl <options> tree\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -51,7 +49,6 @@ char const *help_dbctl =
 char const *usage_disable = "66-disable [ -h ] [ -z ] [ -v verbosity ] [ - l live ] [ -t tree ] [ -S ] [ -F ] [ -R ] service(s)" ;
 
 char const *help_disable =
-"66-disable <options> service(s)\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -67,7 +64,6 @@ char const *help_disable =
 char const *usage_init = "66-init [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -t tree ] classic|database|both" ;
 
 char const *help_init =
-"66-init <options> classic|database|both\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -80,7 +76,6 @@ char const *help_init =
 char const *usage_start = "66-start [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] [ -r | R ] service(s)" ;
 
 char const *help_start =
-"66-start <options> service(s)\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -96,7 +91,6 @@ char const *help_start =
 char const *usage_stop = "66-stop [ -h ] [ -z ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -u ] [ -X ] [ -K ] service(s)" ;
 
 char const *help_stop =
-"66-stop <options> service(s)\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -113,7 +107,6 @@ char const *help_stop =
 char const *usage_svctl = "66-svctl [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] [ -n death ] [ -u | d | r | K | X ] service(s)" ;
 
 char const *help_svctl =
-"66-svctl <options> tree\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -133,7 +126,6 @@ char const *help_svctl =
 char const *usage_env = "66-env [ -h ] [ -z ] [ -v verbosity ] [ -t tree ] [ -c version ] [ -s version ] [ -V|L ] [ -r key=value ] [ -i src,dst ] [ -e ] service" ;
 
 char const *help_env =
-"66-env <options> service\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
@@ -152,7 +144,6 @@ char const *help_env =
 char const *usage_all = "66-all [ -h ] [ -z ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -f ] up|down|unsupervise" ;
 
 char const *help_all =
-"66-all <options> up|down|unsupervise\n"
 "\n"
 "options :\n"
 "   -h: print this help\n"
diff --git a/src/lib66/ssexec_main.c b/src/lib66/ssexec_main.c
index 615480e2..17f303fe 100644
--- a/src/lib66/ssexec_main.c
+++ b/src/lib66/ssexec_main.c
@@ -16,7 +16,6 @@
 #include <oblibs/log.h>
 #include <oblibs/string.h>
 
-#include <skalibs/buffer.h>
 #include <skalibs/sgetopt.h>
 #include <skalibs/types.h>
 
@@ -64,12 +63,13 @@ void set_ssinfo(ssexec_t *info)
     if(r < 0) log_die(LOG_EXIT_SYS,"scandir: ",info->scandir.s," must be an absolute path") ;
 }
 
-static inline void info_help (char const *help)
+static inline void info_help (char const *help,char const *usage)
 {
     log_flow() ;
 
-    if (buffer_putsflush(buffer_1, help) < 0)
-        log_dieusys(LOG_EXIT_SYS, "write to stdout") ;
+    DEFAULT_MSG = 0 ;
+
+    log_info(usage,"\n",help) ;
 }
 
 int ssexec_main(int argc, char const *const *argv,char const *const *envp,ssexec_func_t *func, ssexec_t *info)
@@ -93,7 +93,7 @@ int ssexec_main(int argc, char const *const *argv,char const *const *envp,ssexec
             if (opt == -1) break ;
             switch (opt)
             {
-                case 'h' :  info_help(info->help); return 0 ;
+                case 'h' :  info_help(info->help,info->usage); return 0 ;
                 case 'v' :  if (!uint0_scan(l.arg, &VERBOSITY)) log_usage(info->usage) ;
                             info->opt_verbo = 1 ;
                             break ;
-- 
GitLab