Skip to content
Snippets Groups Projects
Commit 37e682d1 authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

allow to pass -P option to disable/enable subcommand.

Do not warn the user about this feature. It only used on very specific case like module migration process.
Badly used, this features can easily broke the sanity of the system state
parent c7b9978f
No related branches found
No related tags found
No related merge requests found
......@@ -315,7 +315,7 @@ extern int service_resolve_read_cdb(cdb *c, resolve_service_t *res) ;
extern void service_resolve_write(resolve_service_t *res) ;
extern void service_resolve_write_tmp(resolve_service_t *res, char const *dst, uint8_t force) ;
extern int service_resolve_write_cdb(cdbmaker *c, resolve_service_t *sres) ;
extern void service_enable_disable(graph_t *g, unsigned int idx, resolve_service_t *ares, unsigned int areslen, uint8_t action, visit_t *visit) ;
extern void service_enable_disable(graph_t *g, unsigned int idx, resolve_service_t *ares, unsigned int areslen, uint8_t action, visit_t *visit, uint8_t propagate) ;
/* avoid circular dependencies by prototyping the ss_state_t instead
* of calling the state.h header file*/
typedef struct ss_state_s ss_state_t, *ss_state_t_ref ;
......
......@@ -231,9 +231,9 @@ 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 "hfSI"
#define OPTS_ENABLE "hfSIP"
#define OPTS_ENABLE_LEN (sizeof OPTS_ENABLE - 1)
#define OPTS_DISABLE "hSFR"
#define OPTS_DISABLE "hSFRP"
#define OPTS_DISABLE_LEN (sizeof OPTS_DISABLE - 1)
#define OPTS_START "hP"
#define OPTS_START_LEN (sizeof OPTS_START - 1)
......
......@@ -37,7 +37,7 @@ int ssexec_disable(int argc, char const *const *argv, ssexec_t *info)
log_flow() ;
uint32_t flag = 0 ;
uint8_t stop = 0 ;
uint8_t stop = 0, propagate = 1 ;
int n = 0, e = 1 ;
size_t pos = 0 ;
graph_t graph = GRAPH_ZERO ;
......@@ -81,6 +81,11 @@ int ssexec_disable(int argc, char const *const *argv, ssexec_t *info)
log_1_warn("options -F is deprecated -- use instead 66 remove <service>") ;
break ;
case 'P' :
propagate = 0 ;
break ;
default :
log_usage(info->usage, "\n", info->help) ;
}
......@@ -105,20 +110,27 @@ int ssexec_disable(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?") ;
service_enable_disable(&graph, aresid, ares, areslen, 0, visit) ;
service_enable_disable(&graph, aresid, ares, areslen, 0, visit, propagate) ;
if (!sastr_add_string(&sa, argv[n]))
log_dieu(LOG_EXIT_SYS, "add string") ;
}
if (stop && sa.len) {
size_t len = sastr_nelement(&sa) ;
int nargc = 2 + len ;
int nargc = 3 + len ;
char const *prog = PROG ;
char const *newargv[nargc] ;
unsigned int m = 0 ;
char const *help = info->help ;
char const *usage = info->usage ;
info->help = help_stop ;
info->usage = usage_stop ;
newargv[m++] = "stop" ;
newargv[m++] = "-u" ;
FOREACH_SASTR(&sa, pos)
......@@ -126,8 +138,12 @@ int ssexec_disable(int argc, char const *const *argv, ssexec_t *info)
newargv[m] = 0 ;
PROG = "stop" ;
e = ssexec_stop(nargc, newargv, info) ;
e = ssexec_stop(m, newargv, info) ;
PROG = prog ;
info->help = help ;
info->usage = usage ;
goto end ;
}
e = 0 ;
......
......@@ -58,7 +58,7 @@ 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 ;
uint8_t force = 0, conf = 0, start = 0, propagate = 1 ;
int n = 0, e = 1 ;
size_t pos = 0 ;
graph_t graph = GRAPH_ZERO ;
......@@ -105,6 +105,11 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
start = 1 ;
break ;
case 'P' :
propagate = 0 ;
break ;
default :
log_usage(info->usage, "\n", info->help) ;
}
......@@ -132,7 +137,8 @@ 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?") ;
service_enable_disable(&graph, aresid, ares, areslen, 1, visit) ;
if (propagate)
service_enable_disable(&graph, aresid, ares, areslen, 1, visit, propagate) ;
if (!sastr_add_string(&sa, argv[n]))
log_dieu(LOG_EXIT_SYS, "add string") ;
......@@ -141,19 +147,29 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
if (start && sa.len) {
size_t len = sastr_nelement(&sa) ;
int nargc = 1 + len ;
int nargc = 2 + len ;
char const *prog = PROG ;
char const *newargv[nargc] ;
unsigned int m = 0 ;
char const *help = info->help ;
char const *usage = info->usage ;
info->help = help_start ;
info->usage = usage_start ;
newargv[m++] = "start" ;
FOREACH_SASTR(&sa, pos)
newargv[m++] = sa.s + pos ;
newargv[m] = 0 ;
PROG = "start" ;
e = ssexec_start(nargc, newargv, info) ;
e = ssexec_start(m, newargv, info) ;
PROG = prog ;
info->help = help ;
info->usage = usage ;
goto end ;
}
e = 0 ;
......
......@@ -26,7 +26,7 @@
#include <66/utils.h>
#include <66/enum.h>
static void service_enable_disable_deps(graph_t *g, unsigned int idx, resolve_service_t *ares, unsigned int areslen, uint8_t action, visit_t *visit)
static void service_enable_disable_deps(graph_t *g, unsigned int idx, resolve_service_t *ares, unsigned int areslen, uint8_t action, visit_t *visit, uint8_t propagate)
{
log_flow() ;
......@@ -47,7 +47,7 @@ static void service_enable_disable_deps(graph_t *g, unsigned int idx, resolve_se
log_die(LOG_EXIT_USER, "service: ", name, " not available -- did you parse it?") ;
if (visit[aresid] == VISIT_WHITE)
service_enable_disable(g, aresid, ares, areslen, action, visit) ;
service_enable_disable(g, aresid, ares, areslen, action, visit, propagate) ;
}
}
......@@ -56,7 +56,7 @@ static void service_enable_disable_deps(graph_t *g, unsigned int idx, resolve_se
/** @action -> 0 disable
* @action -> 1 enable */
void service_enable_disable(graph_t *g, unsigned int idx, resolve_service_t *ares, unsigned int areslen, uint8_t action, visit_t *visit)
void service_enable_disable(graph_t *g, unsigned int idx, resolve_service_t *ares, unsigned int areslen, uint8_t action, visit_t *visit, uint8_t propagate)
{
log_flow() ;
......@@ -67,7 +67,8 @@ void service_enable_disable(graph_t *g, unsigned int idx, resolve_service_t *are
if (!state_messenger(res, STATE_FLAGS_ISENABLED, !action ? STATE_FLAGS_FALSE : STATE_FLAGS_TRUE))
log_dieusys(LOG_EXIT_SYS, "send message to state of: ", res->sa.s + res->name) ;
service_enable_disable_deps(g, idx, ares, areslen, action, visit) ;
if (propagate)
service_enable_disable_deps(g, idx, ares, areslen, action, visit, propagate) ;
/** the logger must be disabled to avoid to start it
* with the 66 tree start <tree> command */
......@@ -112,7 +113,7 @@ void service_enable_disable(graph_t *g, unsigned int idx, resolve_service_t *are
if (!state_messenger(&ares[aresid], STATE_FLAGS_ISENABLED, !action ? STATE_FLAGS_FALSE : STATE_FLAGS_TRUE))
log_dieusys(LOG_EXIT_SYS, "send message to state of: ", res->sa.s + res->name) ;
service_enable_disable_deps(g, aresid, ares, areslen, action, visit) ;
service_enable_disable_deps(g, aresid, ares, areslen, action, visit, propagate) ;
visit[aresid] = VISIT_GRAY ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment