diff --git a/src/include/66/service.h b/src/include/66/service.h index e0bd87873b3a27ffdf85b890e6c44e06b4b4bfaf..eb16dccca01d5cf859c7f32987fb288b3714c259 100644 --- a/src/include/66/service.h +++ b/src/include/66/service.h @@ -358,6 +358,7 @@ extern int service_resolve_modify_field(resolve_service_t *res, resolve_service_ extern int service_resolve_read_cdb(cdb *c, resolve_service_t *res) ; extern int service_resolve_write(resolve_service_t *res) ; extern int service_resolve_write_cdb(cdbmaker *c, resolve_service_t *sres) ; +extern void service_enable_disable(graph_t *g, char const *base, char const *sv, uint8_t action) ; /** Master */ extern int service_resolve_master_copy(resolve_service_master_t *dst, resolve_service_master_t *mres) ; diff --git a/src/lib66/exec/ssexec_enable.c b/src/lib66/exec/ssexec_enable.c index 6090009ba991b989b18745ec91e5dabd1dc56634..73b617dce32c265afc997ebb3fbbd74610dccbf2 100644 --- a/src/lib66/exec/ssexec_enable.c +++ b/src/lib66/exec/ssexec_enable.c @@ -16,39 +16,20 @@ #include <stdint.h> #include <oblibs/log.h> -#include <oblibs/string.h> -#include <oblibs/sastr.h> #include <oblibs/types.h> +#include <oblibs/sastr.h> +#include <oblibs/string.h> -#include <skalibs/stralloc.h> #include <skalibs/sgetopt.h> +#include <skalibs/stralloc.h> -#include <66/graph.h> #include <66/constants.h> -#include <66/sanitize.h> -#include <66/state.h> -#include <66/service.h> #include <66/ssexec.h> - -typedef enum visit_e visit ; -enum visit_e -{ - SS_WHITE = 0, - SS_GRAY, - SS_BLACK -} ; - -static void visit_init(visit *v, size_t len) -{ - log_flow() ; - - size_t pos = 0 ; - for (; pos < len; pos++) - v[pos] = SS_WHITE ; - -} - -void service_enable_disable(graph_t *g, char const *base, char const *name, uint8_t action) ; +#include <66/graph.h> +#include <66/service.h> +#include <66/config.h> +#include <66/state.h> +#include <66/resolve.h> static void check_identifier(char const *name) { @@ -61,58 +42,8 @@ static void check_identifier(char const *name) if (!strcmp(name,"service@")) log_die(LOG_EXIT_USER,"service@ as service name is a reserved name") ; } -void service_enable_disable_deps(graph_t *g, char const *base, char const *sv, uint8_t action) -{ - log_flow() ; - - size_t pos = 0, element = 0 ; - stralloc sa = STRALLOC_ZERO ; - - if (graph_matrix_get_edge_g_sa(&sa, g, sv, action ? 0 : 1, 0) < 0) - log_dieu(LOG_EXIT_SYS, "get ", action ? "dependencies" : "required by" ," of: ", sv) ; - - size_t len = sastr_nelement(&sa) ; - visit v[len] ; - - visit_init(v, len) ; - - if (sa.len) { - - FOREACH_SASTR(&sa, pos) { - - if (v[element] == SS_WHITE) { - - char *name = sa.s + pos ; - - service_enable_disable(g, base, name, action) ; - - v[element] = SS_GRAY ; - } - element++ ; - } - } - - stralloc_free(&sa) ; -} - -/** @action -> 0 disable - * @action -> 1 enable */ -void service_enable_disable(graph_t *g, char const *base, char const *name, uint8_t action) -{ - log_flow() ; - - if (!state_messenger(base, name, STATE_FLAGS_ISENABLED, !action ? STATE_FLAGS_FALSE : STATE_FLAGS_TRUE)) - log_dieusys(LOG_EXIT_SYS, "send message to state of: ", name) ; - - service_enable_disable_deps(g, base, name, action) ; - - log_info(!action ? "Disabled" : "Enabled"," successfully service: ", name) ; - -} - static void parse_it(char const *name, uint8_t force, uint8_t conf, ssexec_t *info) { - int argc = 4 + (force ? 1 : 0) + (conf ? 1 : 0) ; int m = 0 ; char const *prog = PROG ; @@ -207,13 +138,7 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info) for (n = 0 ; n < argc ; n++) { - service_enable_disable(&graph, info->base.s, argv[n], 1) ; - - int aresid = service_resolve_array_search(ares, areslen, argv[n]) ; - if (aresid < 0) - log_die(LOG_EXIT_USER, "service: ", argv[n], " not available -- please make a bug report") ; - - char *treename = ares[aresid].sa.s + ares[aresid].treename ; + service_enable_disable(&graph, info->base.s, argv[n], 1) ; if (!sastr_add_string(&sa, argv[n])) log_dieu(LOG_EXIT_SYS, "add string") ; @@ -221,8 +146,7 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info) if (start && sa.len) { - size_t len = sastr_len(&sa) ; - pos = 0 ; + size_t len = sastr_nelement(&sa) ; int nargc = 1 + len ; char const *prog = PROG ; char const *newargv[nargc] ; diff --git a/src/lib66/service/deps-lib/deps b/src/lib66/service/deps-lib/deps index e1ef2f070cda5a258bdd5cf8489142476bce52f9..26051bc8acaf966fc3664475e06776b24d4e8457 100644 --- a/src/lib66/service/deps-lib/deps +++ b/src/lib66/service/deps-lib/deps @@ -1,4 +1,5 @@ service_cmp_basedir.o +service_enable_disable.o service_endof_dir.o service_frontend_path.o service_frontend_src.o diff --git a/src/lib66/service/service_enable_disable.c b/src/lib66/service/service_enable_disable.c new file mode 100644 index 0000000000000000000000000000000000000000..bdc47cbf92928b8044e2df86656947494b8d715f --- /dev/null +++ b/src/lib66/service/service_enable_disable.c @@ -0,0 +1,92 @@ +/* + * service_enable_disable.c + * + * Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org> + * + * All rights reserved. + * + * This file is part of Obarun. It is subject to the license terms in + * the LICENSE file found in the top-level directory of this + * distribution. + * This file may not be copied, modified, propagated, or distributed + * except according to the terms contained in the LICENSE file./ + */ + +#include <stdint.h> + +#include <oblibs/log.h> +#include <oblibs/graph.h> +#include <oblibs/sastr.h> + +#include <skalibs/stralloc.h> + +#include <66/service.h> +#include <66/graph.h> +#include <66/state.h> + +typedef enum visit_service_e visit_service_t ; +enum visit_service_e +{ + SS_WHITE = 0, + SS_GRAY, + SS_BLACK +} ; + +static void visit_init(visit_service_t *v, size_t len) +{ + log_flow() ; + + size_t pos = 0 ; + for (; pos < len; pos++) + v[pos] = SS_WHITE ; + +} + +static void service_enable_disable_deps(graph_t *g, char const *base, char const *sv, uint8_t action) +{ + log_flow() ; + + size_t pos = 0, element = 0 ; + stralloc sa = STRALLOC_ZERO ; + + if (graph_matrix_get_edge_g_sa(&sa, g, sv, action ? 0 : 1, 0) < 0) + log_dieu(LOG_EXIT_SYS, "get ", action ? "dependencies" : "required by" ," of: ", sv) ; + + size_t len = sastr_nelement(&sa) ; + visit_service_t v[len] ; + + visit_init(v, len) ; + + if (sa.len) { + + FOREACH_SASTR(&sa, pos) { + + if (v[element] == SS_WHITE) { + + char *name = sa.s + pos ; + + service_enable_disable(g, base, name, action) ; + + v[element] = SS_GRAY ; + } + element++ ; + } + } + + stralloc_free(&sa) ; +} + +/** @action -> 0 disable + * @action -> 1 enable */ +void service_enable_disable(graph_t *g, char const *base, char const *name, uint8_t action) +{ + log_flow() ; + + if (!state_messenger(base, name, STATE_FLAGS_ISENABLED, !action ? STATE_FLAGS_FALSE : STATE_FLAGS_TRUE)) + log_dieusys(LOG_EXIT_SYS, "send message to state of: ", name) ; + + service_enable_disable_deps(g, base, name, action) ; + + log_info(!action ? "Disabled" : "Enabled"," successfully service: ", name) ; + +}