diff --git a/src/include/66/ssexec.h b/src/include/66/ssexec.h index d1ddb69f7e9dad259008241111f980ffc9b26708..cea8af4092f81802a162ce07611f0c180cadd312 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 382ed068d88ebc1bf5921c2e5c7e767d16e997fe..c439302eb690fed0ffb16864c85638d0b7bf91fd 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 0d2c65d4bf3ee0674c01a1edc4723db94b7f9863..c5f21446c42f1a56795fdc8d206fb96c11bd0622 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" ;