From faf6055b0f3c2e122bc1999126e48a29064a691e Mon Sep 17 00:00:00 2001
From: obarun <eric@obarun.org>
Date: Fri, 27 Jan 2023 19:46:27 +1100
Subject: [PATCH] combime 66 all and 66 tree in one tool

---
 src/66/66.c                     | 14 +++++---------
 src/include/66/ssexec.h         | 13 +++++++------
 src/lib66/exec/deps-lib/deps    |  2 ++
 src/lib66/exec/ssexec_help.c    | 24 +++++++++++++++++++-----
 src/lib66/exec/ssexec_scanctl.c |  1 -
 5 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/src/66/66.c b/src/66/66.c
index dc1f8974..5cfd5161 100644
--- a/src/66/66.c
+++ b/src/66/66.c
@@ -119,7 +119,6 @@ int main(int argc, char const *const *argv)
     if (!set_ownersysdir(&info.base, info.owner))
         log_dieusys(LOG_EXIT_SYS, "set owner directory") ;
 
-
     if (!strcmp(argv[1], "boot")) {
 
         PROG = "boot" ;
@@ -182,11 +181,11 @@ int main(int argc, char const *const *argv)
         PROG = "all" ;
         nargv[n++] = PROG ;
         info.prog = PROG ;
-        info.help = help_all ;
-        info.usage = usage_all ;
-        func = &ssexec_all ;
+        info.help = help_treectl ;
+        info.usage = usage_treectl ;
+        func = &ssexec_treectl ;
 
-        auto_strings(opts, main, OPTS_ALL) ;
+        auto_strings(opts, main, OPTS_TREECTL) ;
 
     } else if (!strcmp(argv[1], "env")) {
 
@@ -281,10 +280,7 @@ int main(int argc, char const *const *argv)
 
         PROG = "tree" ;
         nargv[n++] = PROG ;
-        info.prog = PROG ;
-        info.help = help_tree ;
-        info.usage = usage_tree ;
-        func = &ssexec_tree ;
+        func = &ssexec_tree_wrapper ;
 
         auto_strings(opts, main, OPTS_TREE) ;
 
diff --git a/src/include/66/ssexec.h b/src/include/66/ssexec.h
index 9a0adf40..66917082 100644
--- a/src/include/66/ssexec.h
+++ b/src/include/66/ssexec.h
@@ -110,7 +110,7 @@ extern ssexec_func_t ssexec_start ;
 extern ssexec_func_t ssexec_stop ;
 extern ssexec_func_t ssexec_svctl ;
 extern ssexec_func_t ssexec_env ;
-extern ssexec_func_t ssexec_all ;
+extern ssexec_func_t ssexec_treectl ;
 extern ssexec_func_t ssexec_tree ;
 extern ssexec_func_t ssexec_reconfigure ;
 extern ssexec_func_t ssexec_reload ;
@@ -122,6 +122,7 @@ extern ssexec_func_t ssexec_inservice ;
 extern ssexec_func_t ssexec_boot ;
 extern ssexec_func_t ssexec_scanctl ;
 extern ssexec_func_t ssexec_scandir ;
+extern ssexec_func_t ssexec_tree_wrapper ;
 
 extern char const *usage_parse ;
 extern char const *help_parse ;
@@ -139,8 +140,8 @@ extern char const *usage_init ;
 extern char const *help_init ;
 extern char const *usage_env ;
 extern char const *help_env ;
-extern char const *usage_all ;
-extern char const *help_all ;
+extern char const *usage_treectl ;
+extern char const *help_treectl ;
 extern char const *usage_tree ;
 extern char const *help_tree ;
 extern char const *usage_reconfigure ;
@@ -185,9 +186,9 @@ extern char const *usage_66 ;
 #define OPTS_SVCTL_LEN (sizeof OPTS_SVCTL - 1)
 #define OPTS_ENV "c:s:VLr:e:i:"
 #define OPTS_ENV_LEN (sizeof OPTS_ENV - 1)
-#define OPTS_ALL "f"
-#define OPTS_ALL_LEN (sizeof OPTS_ALL - 1)
-#define OPTS_TREE "na:d:cS:EDRC:o:"
+#define OPTS_TREECTL "f"
+#define OPTS_TREECTL_LEN (sizeof OPTS_TREECTL - 1)
+#define OPTS_TREE "co:EDRnadC:S:"
 #define OPTS_TREE_LEN (sizeof OPTS_TREE - 1)
 #define OPTS_INRESOLVE ""
 #define OPTS_INRESOLVE_LEN (sizeof OPTS_INRESOLVE - 1)
diff --git a/src/lib66/exec/deps-lib/deps b/src/lib66/exec/deps-lib/deps
index 05aff2c0..831144d8 100644
--- a/src/lib66/exec/deps-lib/deps
+++ b/src/lib66/exec/deps-lib/deps
@@ -21,6 +21,8 @@ ssexec_start.o
 ssexec_stop.o
 ssexec_svctl.o
 ssexec_tree.o
+ssexec_treectl.o
+ssexec_tree_wrapper.o
 -ls6
 -loblibs
 -lskarnet
diff --git a/src/lib66/exec/ssexec_help.c b/src/lib66/exec/ssexec_help.c
index 4e264c4b..ab9ad8e5 100644
--- a/src/lib66/exec/ssexec_help.c
+++ b/src/lib66/exec/ssexec_help.c
@@ -127,9 +127,9 @@ char const *help_env =
 "   -e: edit the file with editor\n"
 ;
 
-char const *usage_all = "66 all [ -h ] [ -z ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -f ] up|down|unsupervise" ;
+char const *usage_treectl = "66 treectl [ -h ] [ -z ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -f ] up|down|unsupervise" ;
 
-char const *help_all =
+char const *help_treectl =
 "\n"
 "options:\n"
 "   -h: print this help\n"
@@ -166,15 +166,29 @@ char const *help_tree =
 "   clone=: make a clone of tree\n"
 "   noseed: do not use seed file to build the tree\n"
 ;
+*/
+char const *usage_tree = "66 tree [ -h ] [ -z ] [ -v verbosity ] [ -T timeout ] [ -l live ] create|admin|remove|enable|disable|current|up|down|unsupervise [ -f ] [ -o depends=:... ] tree" ;
 
-char const *usage_treectl = "66 treectl [ -h ] [ -z ] [ -v verbosity ] tree" ;
-
-char const *help_treectl =
+char const *help_tree =
 "\n"
 "options:\n"
 "   -h: print this help\n"
 "   -z: use color\n"
 "   -v: increase/decrease verbosity\n"
+"   -T: timeout\n"
+"   -f: fork the process\n"
+"   -o: colon separated list of options\n"
+
+"\n"
+"valid fields for -o options are:\n"
+"\n"
+"   depends=: comma separated list of dependencies for tree or none\n"
+"   requiredby=: comma separated list of trees required by tree or none\n"
+"   groups=: add tree to the specified groups\n"
+"   allow=: comma separated list of account to allow at tree\n"
+"   deny=: comma separated list of account to deny at tree\n"
+"   clone=: make a clone of tree\n"
+"   noseed: do not use seed file to build the tree\n"
 ;
 
 char const *usage_reconfigure = "66 reconfigure [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] [ -P ] service(s)" ;
diff --git a/src/lib66/exec/ssexec_scanctl.c b/src/lib66/exec/ssexec_scanctl.c
index cc0d9978..d706a21a 100644
--- a/src/lib66/exec/ssexec_scanctl.c
+++ b/src/lib66/exec/ssexec_scanctl.c
@@ -150,7 +150,6 @@ static void scandir_up(char const *scandir, unsigned int timeout, unsigned int n
     newup[m++] = scandir ;
     newup[m++] = 0 ;
 
-    //log_info("Starts scandir ",scandir," ...") ;
     xexec_ae(newup[0], newup, envp) ;
 }
 
-- 
GitLab