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

keep previous state of enabled flag

parent d335a3a5
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@
#include <oblibs/log.h>
#include <oblibs/types.h>
#include <oblibs/graph.h>
#include <oblibs/sastr.h>
#include <oblibs/stack.h>
#include <oblibs/string.h>
#include <skalibs/sgetopt.h>
......@@ -39,14 +39,19 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
int r, e = 0 ;
uint32_t flag = 0 ;
uint8_t siglen = 0 ;
uint8_t siglen = 0, issupervised = 0 ;
graph_t graph = GRAPH_ZERO ;
unsigned int areslen = 0, list[SS_MAX_SERVICE + 1], visit[SS_MAX_SERVICE + 1], nservice = 0, n = 0 ;
unsigned int areslen = 0, list[SS_MAX_SERVICE + 1], visit[SS_MAX_SERVICE + 1], tostate[SS_MAX_SERVICE + 1], ntostate = 0, nservice = 0, n = 0 ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ;
ss_state_t sta = STATE_ZERO ;
resolve_service_t res = RESOLVE_SERVICE_ZERO ;
resolve_wrapper_t_ref wres = resolve_set_struct(DATA_SERVICE, &res) ;
_init_stack_(stk, argc * SS_MAX_SERVICE_NAME) ;
memset(list, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
memset(visit, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
memset(tostate, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
FLAGS_SET(flag, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_TOPARSE|STATE_FLAGS_WANTUP) ;
{
......@@ -90,21 +95,33 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
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") ;
log_die(LOG_EXIT_USER, "service: ", argv[n], " not available -- did you parse it?") ;
if (!state_messenger(&ares[aresid], STATE_FLAGS_TOPARSE, STATE_FLAGS_TRUE))
log_dieusys(LOG_EXIT_SYS, "send message to state of: ", argv[n]) ;
if (!state_read(&sta, &ares[aresid]))
log_dieu(LOG_EXIT_SYS, "read state file of: ", argv[n]) ;
r = service_is_g(argv[n], STATE_FLAGS_ISSUPERVISED) ;
if (r < 0)
log_dieusys(LOG_EXIT_SYS, "get information of service: ", argv[n], " -- please make a bug report") ;
sta.isparsed = STATE_FLAGS_FALSE ;
if (!r || r == STATE_FLAGS_FALSE) {
/* only parse it again */
if (!state_write(&sta, &ares[aresid]))
log_dieusys(LOG_EXIT_SYS, "write status file of: ", argv[n]) ;
/** need to reverse the previous state change to
* for current live service.*/
tostate[ntostate++] = aresid ;
issupervised = sta.issupervised == STATE_FLAGS_TRUE ? 1 : 0 ;
if (ares[aresid].enabled)
if (!stack_add_g(&stk, argv[n]))
log_dieu(LOG_EXIT_SYS, "add string") ;
if (!issupervised) {
/* only force to parse it again */
continue ;
} else {
/** services of group boot cannot be restarted, the changes will appear only at
* next reboot.*/
r = tree_ongroups(ares[aresid].sa.s + ares[aresid].path.home, ares[aresid].sa.s + ares[aresid].treename, TREE_GROUPS_BOOT) ;
if (r < 0)
......@@ -113,7 +130,7 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
if (r)
continue ;
graph_compute_visit(argv[n], visit, list, &graph, &nservice, 1) ;
graph_compute_visit(ares, aresid, visit, list, &graph, &nservice, 1) ;
}
}
......@@ -123,10 +140,10 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
if (nservice && r) {
/** We need to search in every tree to stop the service
* if the user has specified a specific tree. Therefore, remove
* the -t option for the stop process and re-enable it
* for the parse and start processes. */
/** User may request for a specific tree with the -t options.
* The tree specified may be different from the actual one.
* So, remove the -t option for the stop process and use it again
* for the parse and start process. */
char tree[info->treename.len + 1] ;
auto_strings(tree, info->treename.s) ;
......@@ -152,6 +169,7 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
for (n = 0 ; n < nservice ; n++) {
char *name = graph.data.s + genalloc_s(graph_hash_t,&graph.hash)[list[n]].vertex ;
/** the stop process will handle logger. Remove those from the list.*/
if (get_rstrlen_until(name,SS_LOG_SUFFIX) < 0)
newargv[m++] = name ;
}
......@@ -177,6 +195,20 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
for (n = 0 ; n < argc ; n++)
sanitize_source(argv[n], info) ;
for (n = 0 ; n < ntostate ; n++) {
/** live of the service still exist.
* Reverse to the previous state of the isparsed flag. */
if (state_read_remote(&sta, ares[tostate[n]].sa.s + ares[tostate[n]].live.statedir)) {
sta.isparsed = STATE_FLAGS_TRUE ;
if (!state_write_remote(&sta, ares[tostate[n]].sa.s + ares[tostate[n]].live.statedir))
log_warnusys("write status file of: ", ares[tostate[n]].sa.s + ares[tostate[n]].live.statedir) ;
}
}
if (nservice && r) {
unsigned int m = 0 ;
......@@ -211,7 +243,42 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
info->usage = usage ;
}
if (stk.len) {
/** enable again the service if it was enabled */
unsigned int m = 0 ;
int nargc = 2 + stk.count ;
char const *prog = PROG ;
char const *newargv[nargc] ;
char const *help = info->help ;
char const *usage = info->usage ;
info->help = help_enable ;
info->usage = usage_enable ;
newargv[m++] = "enable" ;
n = 0 ;
FOREACH_STK(&stk, n) {
char *name = stk.s + n ;
if (get_rstrlen_until(name,SS_LOG_SUFFIX) < 0)
newargv[m++] = name ;
}
newargv[m] = 0 ;
PROG= "enable" ;
e = ssexec_enable(m, newargv, info) ;
PROG = prog ;
info->help = help ;
info->usage = usage ;
}
freed:
resolve_free(wres) ;
service_resolve_array_free(ares, areslen) ;
graph_free_all(&graph) ;
......
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