From 08ff9196c501ed130d0577463f3c4a8de4e8814a Mon Sep 17 00:00:00 2001
From: obarun <eric@obarun.org>
Date: Fri, 16 Jun 2023 16:55:04 +1100
Subject: [PATCH] remove -I -f option to enable.

This option come from previous behavior. It not the role of enable process
to deal with parse option.
Also, this change allow user to quickly switch between trees without the need
to force a parse process.
The necessary field at resolve file of the service is now handled by enable
process.
---
 src/include/66/ssexec.h        |  2 +-
 src/lib66/exec/ssexec_enable.c | 77 +++++++++++++---------------------
 src/lib66/exec/ssexec_help.c   |  4 +-
 3 files changed, 30 insertions(+), 53 deletions(-)

diff --git a/src/include/66/ssexec.h b/src/include/66/ssexec.h
index d1ddb69f..cea8af40 100644
--- a/src/include/66/ssexec.h
+++ b/src/include/66/ssexec.h
@@ -231,7 +231,7 @@ extern char const *help_halt ;
 #define OPTS_PARSE_LEN (sizeof OPTS_PARSE - 1)
 #define OPTS_INIT "h"
 #define OPTS_INIT_LEN (sizeof OPTS_INIT - 1)
-#define OPTS_ENABLE "hfSIP"
+#define OPTS_ENABLE "hSP"
 #define OPTS_ENABLE_LEN (sizeof OPTS_ENABLE - 1)
 #define OPTS_DISABLE "hSFRP"
 #define OPTS_DISABLE_LEN (sizeof OPTS_DISABLE - 1)
diff --git a/src/lib66/exec/ssexec_enable.c b/src/lib66/exec/ssexec_enable.c
index 382ed068..c439302e 100644
--- a/src/lib66/exec/ssexec_enable.c
+++ b/src/lib66/exec/ssexec_enable.c
@@ -12,43 +12,33 @@
  * except according to the terms contained in the LICENSE file./
  */
 
-#include <string.h>
 #include <stdint.h>
 
 #include <oblibs/log.h>
-#include <oblibs/types.h>
-#include <oblibs/sastr.h>
-#include <oblibs/string.h>
+#include <oblibs/types.h> // FLAGS
 
-#include <skalibs/sgetopt.h>
-#include <skalibs/stralloc.h>
+#include <oblibs/stack.h>
 
-#include <66/constants.h>
+#include <skalibs/sgetopt.h>
 #include <66/ssexec.h>
-#include <66/graph.h>
 #include <66/service.h>
-#include <66/config.h>
 #include <66/state.h>
-#include <66/resolve.h>
-#include <66/utils.h>
+#include <66/graph.h>
+#include <66/config.h>
 
-static void parse_it(char const *name, uint8_t force, uint8_t conf, ssexec_t *info)
+static void parse_it(char const *name, ssexec_t *info)
 {
-    int argc = 4 + (force ? 1 : 0) + (conf ? 1 : 0) ;
+    int argc = 3 ;
     int m = 0 ;
     char const *prog = PROG ;
     char const *newargv[argc] ;
 
     newargv[m++] = "parse" ;
-    if (force)
-        newargv[m++] = "-f" ;
-    if (conf)
-        newargv[m++] = "-I" ;
     newargv[m++] = name ;
-    newargv[m++] = 0 ;
+    newargv[m] = 0 ;
 
     PROG = "parse" ;
-    if (ssexec_parse(argc, newargv, info))
+    if (ssexec_parse(m, newargv, info))
         log_dieu(LOG_EXIT_SYS, "parse service: ", name) ;
     PROG = prog ;
 }
@@ -58,11 +48,10 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
     log_flow() ;
 
     uint32_t flag = 0 ;
-    uint8_t force = 0, conf = 0, start = 0, propagate = 1 ;
+    uint8_t start = 0, propagate = 1 ;
     int n = 0, e = 1 ;
     size_t pos = 0 ;
     graph_t graph = GRAPH_ZERO ;
-    stralloc sa = STRALLOC_ZERO ;
 
     unsigned int areslen = 0 ;
     resolve_service_t ares[SS_MAX_SERVICE + 1] ;
@@ -87,19 +76,6 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
                     info_help(info->help, info->usage) ;
                     return 0 ;
 
-                case 'f' :
-
-                    /** only rewrite the service itself */
-                    if (force)
-                        log_usage(info->usage, "\n", info->help) ;
-                    force = 1 ;
-                    break ;
-
-                case 'I' :
-
-                    conf = 1 ;
-                    break ;
-
                 case 'S' :
 
                     start = 1 ;
@@ -120,9 +96,11 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
     if (argc < 1)
         log_usage(info->usage, "\n", info->help) ;
 
+    _init_stack_(stk, argc * SS_MAX_TREENAME) ;
+
     for(; n < argc ; n++) {
         name_isvalid(argv[n]) ;
-        parse_it(argv[n], force, conf, info) ;
+        parse_it(argv[n], info) ;
     }
 
     /** build the graph of the entire system */
@@ -137,16 +115,23 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
         if (aresid < 0)
             log_die(LOG_EXIT_USER, "service: ", argv[n], " not available -- did you parse it?") ;
 
-        if (propagate)
-            service_enable_disable(&graph, aresid, ares, areslen, 1, visit, propagate) ;
+        service_enable_disable(&graph, aresid, ares, areslen, 1, visit, propagate) ;
 
-        if (!sastr_add_string(&sa, argv[n]))
+        if (info->opt_tree)
+            service_switch_tree(&ares[aresid], info->base.s, info->treename.s) ;
+
+        if (!stack_add_g(&stk, argv[n]))
             log_dieu(LOG_EXIT_SYS, "add string") ;
     }
 
-    if (start && sa.len) {
+    service_resolve_array_free(ares, areslen) ;
+    graph_free_all(&graph) ;
+
+    e = 0 ;
+
+    if (start && stk.len) {
 
-        size_t len = sastr_nelement(&sa) ;
+        size_t len = stack_count_element(&stk) ;
         int nargc = 2 + len ;
         char const *prog = PROG ;
         char const *newargv[nargc] ;
@@ -159,8 +144,8 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
         info->usage = usage_start ;
 
         newargv[m++] = "start" ;
-        FOREACH_SASTR(&sa, pos)
-            newargv[m++] = sa.s + pos ;
+        FOREACH_STK(&stk, pos)
+            newargv[m++] = stk.s + pos ;
         newargv[m] = 0 ;
 
         PROG = "start" ;
@@ -169,15 +154,9 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
 
         info->help = help ;
         info->usage = usage ;
-
-        goto end ;
     }
-    e = 0 ;
 
-    end:
-        stralloc_free(&sa) ;
-        service_resolve_array_free(ares, areslen) ;
-        graph_free_all(&graph) ;
+
 
     return e ;
 }
diff --git a/src/lib66/exec/ssexec_help.c b/src/lib66/exec/ssexec_help.c
index 0d2c65d4..c5f21446 100644
--- a/src/lib66/exec/ssexec_help.c
+++ b/src/lib66/exec/ssexec_help.c
@@ -76,15 +76,13 @@ char const *help_boot =
 "   -b: banner to display\n"
 ;
 
-char const *usage_enable = "66 enable [ -h ] [ -f ] [ -I ] [ -S ] service..." ;
+char const *usage_enable = "66 enable [ -h ] [ -S ] service..." ;
 
 char const *help_enable =
 "\nactivate services at the next boot\n"
 "\n"
 "options:\n"
 "   -h: print this help\n"
-"   -f: force to overwrite the service(s)\n"
-"   -I: do not import modified configuration files from previous version\n"
 "   -S: enable and start the service\n"
 ;
 
-- 
GitLab