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

switch service graph construction to hash map, add parse_append_logger function

parent 9fbb254d
No related branches found
No related tags found
No related merge requests found
Showing
with 1355 additions and 223 deletions
...@@ -25,10 +25,9 @@ ...@@ -25,10 +25,9 @@
#include <66/hash.h> #include <66/hash.h>
extern void graph_build_tree(graph_t *g, struct resolve_hash_tree_s **htres, char const *base, resolve_tree_master_enum_t field) ; extern void graph_build_tree(graph_t *g, struct resolve_hash_tree_s **htres, char const *base, resolve_tree_master_enum_t field) ;
extern void graph_build_service(graph_t *g, resolve_service_t *ares, unsigned int *areslen, ssexec_t *info, uint32_t flag) ; extern void graph_build_service(graph_t *g, struct resolve_hash_s **hres, ssexec_t *info, uint32_t flag) ;
extern int graph_compute_dependencies(graph_t *g, char const *vertex, char const *edge, uint8_t requiredby) ; extern int graph_compute_dependencies(graph_t *g, char const *vertex, char const *edge, uint8_t requiredby) ;
extern void graph_compute_visit(resolve_service_t *ares, unsigned int aresid, unsigned int *visit, unsigned int *list, graph_t *graph, unsigned int *nservice, uint8_t requiredby) ; extern void graph_compute_visit(struct resolve_hash_s hres, unsigned int *visit, unsigned int *list, graph_t *graph, unsigned int *nservice, uint8_t requiredby) ;
extern int graph_build_service_bytree(graph_t *g, char const *tree, uint8_t what, uint8_t is_supervised) ; extern int graph_build_service_bytree(graph_t *g, char const *tree, uint8_t what, uint8_t is_supervised) ;
extern int graph_build_service_bytree_from_src(graph_t *g, char const *src, uint8_t what) ; extern int graph_build_service_bytree_from_src(graph_t *g, char const *src, uint8_t what) ;
......
This diff is collapsed.
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#define SS_MODULE_REQUIREDBY "/requiredby" #define SS_MODULE_REQUIREDBY "/requiredby"
#define SS_MODULE_REQUIREDBY_LEN (sizeof SS_MODULE_REQUIREDBY - 1) #define SS_MODULE_REQUIREDBY_LEN (sizeof SS_MODULE_REQUIREDBY - 1)
extern void parse_module(resolve_service_t *res, resolve_service_t *ares, unsigned int *areslen, ssexec_t *info, uint8_t force) ; extern void parse_module(resolve_service_t *res, struct resolve_hash_s **hres, ssexec_t *info, uint8_t force) ;
extern void parse_module_check_dir(char const *src,char const *dir) ; extern void parse_module_check_dir(char const *src,char const *dir) ;
extern void parse_module_check_name(char const *src, char const *name) ; extern void parse_module_check_name(char const *src, char const *name) ;
......
...@@ -47,9 +47,10 @@ extern void parse_cleanup(resolve_service_t *res, char const *tmpdir, uint8_t fo ...@@ -47,9 +47,10 @@ extern void parse_cleanup(resolve_service_t *res, char const *tmpdir, uint8_t fo
/** main */ /** main */
extern void start_parser(char const *sv, ssexec_t *info, uint8_t disable_module, char const *directory_forced) ; extern void start_parser(char const *sv, ssexec_t *info, uint8_t disable_module, char const *directory_forced) ;
extern void parse_service(char const *sv, ssexec_t *info, uint8_t force, uint8_t conf) ; extern void parse_service(struct resolve_hash_s **href, char const *sv, ssexec_t *info, uint8_t force, uint8_t conf) ;
extern int parse_frontend(char const *sv, resolve_service_t *ares, unsigned int *areslen, ssexec_t *info, uint8_t force, uint8_t conf, char const *forced_directory, char const *main, char const *inns, char const *intree) ; extern int parse_frontend(char const *sv, struct resolve_hash_s **hres, ssexec_t *info, uint8_t force, uint8_t conf, char const *forced_directory, char const *main, char const *inns, char const *intree) ;
extern int parse_interdependences(char const *service, char const *list, unsigned int listlen, resolve_service_t *ares, unsigned int *areslen, ssexec_t *info, uint8_t force, uint8_t conf, char const *forced_directory, char const *main, char const *inns, char const *intree) ; extern int parse_interdependences(char const *service, char const *list, unsigned int listlen, struct resolve_hash_s **hres, ssexec_t *info, uint8_t force, uint8_t conf, char const *forced_directory, char const *main, char const *inns, char const *intree) ;
extern void parse_append_logger(struct resolve_hash_s **hres, resolve_service_t *res, ssexec_t *info) ;
/** split */ /** split */
extern int parse_section(stralloc *secname, char const *str, size_t *pos) ; extern int parse_section(stralloc *secname, char const *str, size_t *pos) ;
...@@ -74,13 +75,19 @@ extern int parse_clean_list(stralloc *sa, char const *str) ; ...@@ -74,13 +75,19 @@ extern int parse_clean_list(stralloc *sa, char const *str) ;
extern int parse_clean_line(char *str) ; extern int parse_clean_line(char *str) ;
extern int parse_mandatory(resolve_service_t *res) ; extern int parse_mandatory(resolve_service_t *res) ;
extern void parse_error(int ierr, int idsec, int idkey) ; extern void parse_error(int ierr, int idsec, int idkey) ;
extern void parse_rename_interdependences(resolve_service_t *res, char const *prefix, resolve_service_t *ares, unsigned int *areslen) ; extern void parse_rename_interdependences(resolve_service_t *res, char const *prefix, struct resolve_hash_s **hres, ssexec_t *info) ;
extern void parse_db_migrate(resolve_service_t *res, ssexec_t *info) ; extern void parse_db_migrate(resolve_service_t *res, ssexec_t *info) ;
/** module */ /** module */
extern void parse_module(resolve_service_t *res, resolve_service_t *ares, unsigned int *areslen, ssexec_t *info, uint8_t force) ; extern void parse_module(resolve_service_t *res, struct resolve_hash_s **hres, ssexec_t *info, uint8_t force) ;
/** resolve */ /** resolve */
extern void parse_compute_resolve(unsigned int idx, resolve_service_t *ares, unsigned int *areslen, ssexec_t *info) ; extern void parse_compute_resolve(resolve_service_t *res, ssexec_t *info) ;
extern uint32_t compute_src_servicedir(resolve_wrapper_t_ref wres, ssexec_t *info) ;
extern uint32_t compute_live_servicedir(resolve_wrapper_t_ref wres, ssexec_t *info) ;
extern uint32_t compute_status(resolve_wrapper_t_ref wres, ssexec_t *info) ;
extern uint32_t compute_scan_dir(resolve_wrapper_t_ref wres, ssexec_t *info) ;
extern uint32_t compute_state_dir(resolve_wrapper_t_ref wres, ssexec_t *info, char const *folder) ;
extern uint32_t compute_pipe_service(resolve_wrapper_t_ref wres, ssexec_t *info, char const *name) ;
#endif #endif
...@@ -27,7 +27,7 @@ extern void sanitize_source(char const *name, ssexec_t *info, uint32_t flag) ; ...@@ -27,7 +27,7 @@ extern void sanitize_source(char const *name, ssexec_t *info, uint32_t flag) ;
extern int sanitize_fdholder(resolve_service_t *res, ss_state_t *sta, uint32_t flag, uint8_t init) ; extern int sanitize_fdholder(resolve_service_t *res, ss_state_t *sta, uint32_t flag, uint8_t init) ;
extern int sanitize_livestate(resolve_service_t *res, ss_state_t *sta) ; extern int sanitize_livestate(resolve_service_t *res, ss_state_t *sta) ;
extern int sanitize_scandir(resolve_service_t *res, ss_state_t *sta) ; extern int sanitize_scandir(resolve_service_t *res, ss_state_t *sta) ;
extern void sanitize_init(unsigned int *alist, unsigned int alen, graph_t *g, resolve_service_t *ares, unsigned int areslen) ; extern void sanitize_init(unsigned int *alist, unsigned int alen, graph_t *g, struct resolve_hash_s **hres) ;
extern void sanitize_graph(ssexec_t *info) ; extern void sanitize_graph(ssexec_t *info) ;
/** @Return 0 the service is already written /** @Return 0 the service is already written
* @Return 1 the service will be overwritten * @Return 1 the service will be overwritten
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <66/ssexec.h> #include <66/ssexec.h>
#include <66/resolve.h> #include <66/resolve.h>
#include <66/hash.h>
typedef struct resolve_service_addon_path_s resolve_service_addon_path_t, *resolve_service_addon_path_t_ref ; typedef struct resolve_service_addon_path_s resolve_service_addon_path_t, *resolve_service_addon_path_t_ref ;
struct resolve_service_addon_path_s struct resolve_service_addon_path_s
...@@ -302,6 +303,15 @@ enum resolve_service_enum_e ...@@ -302,6 +303,15 @@ enum resolve_service_enum_e
} ; } ;
struct resolve_hash_s {
char name[SS_MAX_SERVICE_NAME + 1] ; // name as key
uint8_t visit ;
resolve_service_t res ;
UT_hash_handle hh ;
} ;
#define RESOLVE_HASH_ZERO { 0, 0, RESOLVE_SERVICE_ZERO, NULL }
extern resolve_field_table_t resolve_service_field_table[] ; extern resolve_field_table_t resolve_service_field_table[] ;
extern int service_cmp_basedir(char const *dir) ; extern int service_cmp_basedir(char const *dir) ;
...@@ -310,8 +320,6 @@ extern int service_frontend_path(stralloc *sasrc,char const *sv, uid_t owner,cha ...@@ -310,8 +320,6 @@ extern int service_frontend_path(stralloc *sasrc,char const *sv, uid_t owner,cha
extern int service_frontend_src(stralloc *sasrc, char const *name, char const *src, char const **exclude) ; extern int service_frontend_src(stralloc *sasrc, char const *name, char const *src, char const **exclude) ;
extern int service_is_g(char const *name, uint32_t flag) ; extern int service_is_g(char const *name, uint32_t flag) ;
extern int service_get_treename(char *atree, char const *name, uint32_t flag) ; extern int service_get_treename(char *atree, char const *name, uint32_t flag) ;
extern void service_resolve_array_free(resolve_service_t *ares, unsigned int areslen) ;
extern int service_resolve_array_search(resolve_service_t *ares, unsigned int areslen, char const *name) ;
extern int service_resolve_copy(resolve_service_t *dst, resolve_service_t *res) ; extern int service_resolve_copy(resolve_service_t *dst, resolve_service_t *res) ;
extern int service_resolve_get_field_tosa(stralloc *sa, resolve_service_t *res, resolve_service_enum_t field) ; extern int service_resolve_get_field_tosa(stralloc *sa, resolve_service_t *res, resolve_service_enum_t field) ;
extern int service_resolve_modify_field(resolve_service_t *res, resolve_service_enum_t field, char const *data) ; extern int service_resolve_modify_field(resolve_service_t *res, resolve_service_enum_t field, char const *data) ;
...@@ -319,7 +327,7 @@ extern int service_resolve_read_cdb(cdb *c, resolve_service_t *res) ; ...@@ -319,7 +327,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(resolve_service_t *res) ;
extern void service_resolve_write_remote(resolve_service_t *res, char const *dst, uint8_t force) ; extern void service_resolve_write_remote(resolve_service_t *res, char const *dst, uint8_t force) ;
extern int service_resolve_write_cdb(cdbmaker *c, resolve_service_t *sres) ; 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, unsigned int *visit, uint8_t propagate, ssexec_t *info) ; extern void service_enable_disable(graph_t *g, struct resolve_hash_s *hash, struct resolve_hash_s **hres, uint8_t action, uint8_t propagate, ssexec_t *info) ;
extern void service_switch_tree(resolve_service_t *res, char const *base, char const *totreename, ssexec_t *info) ; extern void service_switch_tree(resolve_service_t *res, char const *base, char const *totreename, ssexec_t *info) ;
extern void service_db_migrate(resolve_service_t *old, resolve_service_t *new, char const *base, uint8_t requiredby) ; extern void service_db_migrate(resolve_service_t *old, resolve_service_t *new, char const *base, uint8_t requiredby) ;
/* avoid circular dependencies by prototyping the ss_state_t instead /* avoid circular dependencies by prototyping the ss_state_t instead
...@@ -327,9 +335,14 @@ extern void service_db_migrate(resolve_service_t *old, resolve_service_t *new, c ...@@ -327,9 +335,14 @@ extern void service_db_migrate(resolve_service_t *old, resolve_service_t *new, c
typedef struct ss_state_s ss_state_t, *ss_state_t_ref ; typedef struct ss_state_s ss_state_t, *ss_state_t_ref ;
/** Graph */ /** Graph */
extern void service_graph_g(char const *slist, size_t slen, graph_t *graph, resolve_service_t *ares, unsigned int *areslen, ssexec_t *info, uint32_t flag) ; extern void service_graph_g(char const *slist, size_t slen, graph_t *graph, struct resolve_hash_s **hres, ssexec_t *info, uint32_t flag) ;
extern void service_graph_collect(graph_t *g, char const *alist, size_t alen, resolve_service_t *ares, unsigned int *areslen, ssexec_t *info, uint32_t flag) ; extern void service_graph_collect(graph_t *g, char const *alist, size_t alen, struct resolve_hash_s **hres, ssexec_t *info, uint32_t flag) ;
extern void service_graph_build(graph_t *g, resolve_service_t *ares, unsigned int areslen, uint32_t flag) ; extern void service_graph_build(graph_t *g, struct resolve_hash_s **hres, uint32_t flag) ;
/** Hash */
extern int hash_add(struct resolve_hash_s **hres, char const *name, resolve_service_t res) ;
extern struct resolve_hash_s *hash_search(struct resolve_hash_s **hres, char const *name) ;
extern int hash_count(struct resolve_hash_s **hres) ;
extern void hash_free(struct resolve_hash_s **hres) ;
#endif #endif
...@@ -40,7 +40,7 @@ struct pidservice_s ...@@ -40,7 +40,7 @@ struct pidservice_s
{ {
int pipe[2] ; int pipe[2] ;
pid_t pid ; pid_t pid ;
int aresid ; // id at array ares resolve_service_t *res ; // resolve of service through hash
unsigned int vertex ; // id at graph_hash_t struct unsigned int vertex ; // id at graph_hash_t struct
uint8_t state ; uint8_t state ;
int nedge ; int nedge ;
...@@ -54,7 +54,7 @@ struct pidservice_s ...@@ -54,7 +54,7 @@ struct pidservice_s
#define PIDSERVICE_ZERO { \ #define PIDSERVICE_ZERO { \
.pipe[0] = -1, \ .pipe[0] = -1, \
.pipe[1] = -1, \ .pipe[1] = -1, \
.aresid = -1, \ .res = NULL, \
.vertex = -1, \ .vertex = -1, \
.state = 0, \ .state = 0, \
.nedge = 0, \ .nedge = 0, \
...@@ -63,13 +63,13 @@ struct pidservice_s ...@@ -63,13 +63,13 @@ struct pidservice_s
.notif = { 0 } \ .notif = { 0 } \
} }
extern void svc_init_array(unsigned int *list, unsigned int listlen, pidservice_t *apids, graph_t *g, resolve_service_t *ares, unsigned int areslen, ssexec_t *info, uint8_t requiredby, uint32_t flag) ; extern void svc_init_array(unsigned int *list, unsigned int listlen, pidservice_t *apids, graph_t *g, struct resolve_hash_s **hres, ssexec_t *info, uint8_t requiredby, uint32_t flag) ;
extern int svc_launch(pidservice_t *apids, unsigned int napid, uint8_t what, graph_t *graph, resolve_service_t *ares, unsigned int areslen, ssexec_t *info, char const *rise, uint8_t rise_opt, uint8_t msg, char const *signal, uint8_t propagate) ; extern int svc_launch(pidservice_t *apids, unsigned int napid, uint8_t what, graph_t *graph, struct resolve_hash_s **hres, ssexec_t *info, char const *rise, uint8_t rise_opt, uint8_t msg, char const *signal, uint8_t propagate) ;
extern int svc_compute_ns(resolve_service_t *ares, unsigned int areslen, unsigned int aresid, uint8_t what, ssexec_t *info, char const *updown, uint8_t opt_updown, uint8_t reloadmsg,char const *data, uint8_t propagate, pidservice_t *apids, unsigned int napids) ; extern int svc_compute_ns(resolve_service_t *res, uint8_t what, ssexec_t *info, char const *updown, uint8_t opt_updown, uint8_t reloadmsg,char const *data, uint8_t propagate, pidservice_t *apids, unsigned int napids) ;
extern int svc_scandir_ok (char const *dir) ; extern int svc_scandir_ok (char const *dir) ;
extern int svc_scandir_send(char const *scandir,char const *signal) ; extern int svc_scandir_send(char const *scandir,char const *signal) ;
extern int svc_send_wait(char const *const *list, unsigned int nservice, char **sig, unsigned int siglen, ssexec_t *info) ; extern int svc_send_wait(char const *const *list, unsigned int nservice, char **sig, unsigned int siglen, ssexec_t *info) ;
extern void svc_unsupervise(unsigned int *alist, unsigned int alen, graph_t *g, resolve_service_t *ares, unsigned int areslen, ssexec_t *info) ; extern void svc_unsupervise(unsigned int *alist, unsigned int alen, graph_t *g, struct resolve_hash_s **hres, ssexec_t *info) ;
extern void svc_send_fdholder(char const *socket, char const *signal) ; extern void svc_send_fdholder(char const *socket, char const *signal) ;
#endif #endif
...@@ -18,10 +18,8 @@ ...@@ -18,10 +18,8 @@
#include <oblibs/log.h> #include <oblibs/log.h>
#include <oblibs/types.h> #include <oblibs/types.h>
#include <oblibs/string.h> #include <oblibs/string.h>
#include <oblibs/sastr.h>
#include <skalibs/sgetopt.h> #include <skalibs/sgetopt.h>
#include <skalibs/stralloc.h>
#include <66/constants.h> #include <66/constants.h>
#include <66/ssexec.h> #include <66/ssexec.h>
...@@ -40,15 +38,12 @@ int ssexec_disable(int argc, char const *const *argv, ssexec_t *info) ...@@ -40,15 +38,12 @@ int ssexec_disable(int argc, char const *const *argv, ssexec_t *info)
int n = 0, e = 1 ; int n = 0, e = 1 ;
size_t pos = 0 ; size_t pos = 0 ;
graph_t graph = GRAPH_ZERO ; graph_t graph = GRAPH_ZERO ;
stralloc sa = STRALLOC_ZERO ; struct resolve_hash_s *hres = NULL ;
struct resolve_hash_s tostop[argc] ;
unsigned int areslen = 0 ; memset(tostop, 0, sizeof(struct resolve_hash_s) * argc) ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ;
unsigned int visit[SS_MAX_SERVICE + 1] ;
memset(visit, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
FLAGS_SET(flag, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_WANTUP) ; FLAGS_SET(flag, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_WANTUP) ;
{ {
subgetopt l = SUBGETOPT_ZERO ; subgetopt l = SUBGETOPT_ZERO ;
...@@ -95,27 +90,28 @@ int ssexec_disable(int argc, char const *const *argv, ssexec_t *info) ...@@ -95,27 +90,28 @@ int ssexec_disable(int argc, char const *const *argv, ssexec_t *info)
log_usage(info->usage, "\n", info->help) ; log_usage(info->usage, "\n", info->help) ;
/** build the graph of the entire system */ /** build the graph of the entire system */
graph_build_service(&graph, ares, &areslen, info, flag) ; graph_build_service(&graph, &hres, info, flag) ;
if (!graph.mlen) if (!graph.mlen)
log_die(LOG_EXIT_USER, "services selection is not available -- try to parse it first") ; log_die(LOG_EXIT_USER, "services selection is not available -- try to parse it first") ;
for (; n < argc ; n++) { for (; n < argc ; n++) {
int aresid = service_resolve_array_search(ares, areslen, argv[n]) ; struct resolve_hash_s *hash = hash_search(&hres, argv[n]) ;
if (aresid < 0) if (hash == NULL)
log_die(LOG_EXIT_USER, "service: ", argv[n], " not available -- did you parse it?") ; log_die(LOG_EXIT_USER, "service: ", argv[n], " not available -- did you parse it?") ;
service_enable_disable(&graph, aresid, ares, areslen, 0, visit, propagate, info) ; service_enable_disable(&graph, hash, &hres, 0, propagate, info) ;
if (!sastr_add_string(&sa, argv[n])) tostop[n] = *hash ;
log_dieu(LOG_EXIT_SYS, "add string") ;
} }
if (stop && sa.len) { graph_free_all(&graph) ;
e = 0 ;
if (stop && n) {
size_t len = sastr_nelement(&sa) ; int nargc = 3 + n ;
int nargc = 3 + len ;
char const *prog = PROG ; char const *prog = PROG ;
char const *newargv[nargc] ; char const *newargv[nargc] ;
unsigned int m = 0 ; unsigned int m = 0 ;
...@@ -128,8 +124,8 @@ int ssexec_disable(int argc, char const *const *argv, ssexec_t *info) ...@@ -128,8 +124,8 @@ int ssexec_disable(int argc, char const *const *argv, ssexec_t *info)
newargv[m++] = "stop" ; newargv[m++] = "stop" ;
newargv[m++] = "-u" ; newargv[m++] = "-u" ;
FOREACH_SASTR(&sa, pos) for (; pos < n ; pos++)
newargv[m++] = sa.s + pos ; newargv[m++] = tostop[pos].name ;
newargv[m] = 0 ; newargv[m] = 0 ;
PROG = "stop" ; PROG = "stop" ;
...@@ -138,15 +134,9 @@ int ssexec_disable(int argc, char const *const *argv, ssexec_t *info) ...@@ -138,15 +134,9 @@ int ssexec_disable(int argc, char const *const *argv, ssexec_t *info)
info->help = help ; info->help = help ;
info->usage = usage ; info->usage = usage ;
goto end ;
} }
e = 0 ;
end: hash_free(&hres) ;
stralloc_free(&sa) ;
service_resolve_array_free(ares, areslen) ;
graph_free_all(&graph) ;
return e ; return e ;
} }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include <oblibs/log.h> #include <oblibs/log.h>
#include <oblibs/types.h> // FLAGS #include <oblibs/types.h> // FLAGS
#include <oblibs/stack.h>
#include <skalibs/sgetopt.h> #include <skalibs/sgetopt.h>
...@@ -37,14 +36,12 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info) ...@@ -37,14 +36,12 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
int n = 0, e = 1 ; int n = 0, e = 1 ;
size_t pos = 0 ; size_t pos = 0 ;
graph_t graph = GRAPH_ZERO ; graph_t graph = GRAPH_ZERO ;
struct resolve_hash_s *hres = NULL ;
struct resolve_hash_s tostart[argc] ;
unsigned int areslen = 0 ; memset(tostart, 0, sizeof(struct resolve_hash_s) * argc) ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ;
unsigned int visit[SS_MAX_SERVICE + 1] ;
memset(visit, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
FLAGS_SET(flag, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_WANTUP) ; FLAGS_SET(flag, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_WANTUP) ;
{ {
subgetopt l = SUBGETOPT_ZERO ; subgetopt l = SUBGETOPT_ZERO ;
...@@ -80,52 +77,46 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info) ...@@ -80,52 +77,46 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
if (argc < 1) if (argc < 1)
log_usage(info->usage, "\n", info->help) ; log_usage(info->usage, "\n", info->help) ;
_init_stack_(stk, argc * SS_MAX_TREENAME) ;
for(; n < argc ; n++) for(; n < argc ; n++)
sanitize_source(argv[n], info, flag) ; sanitize_source(argv[n], info, flag) ;
/** build the graph of the entire system */ /** build the graph of the entire system */
graph_build_service(&graph, ares, &areslen, info, flag) ; graph_build_service(&graph, &hres, info, flag) ;
if (!graph.mlen) if (!graph.mlen)
log_die(LOG_EXIT_USER, "services selection is not available -- please make a bug report") ; log_die(LOG_EXIT_USER, "services selection is not available -- please make a bug report") ;
for (n = 0 ; n < argc ; n++) { for (n = 0 ; n < argc ; n++) {
int aresid = service_resolve_array_search(ares, areslen, argv[n]) ; struct resolve_hash_s *hash = hash_search(&hres, argv[n]) ;
if (aresid < 0) if (hash == NULL)
log_die(LOG_EXIT_USER, "service: ", argv[n], " not available -- did you parse it?") ; log_die(LOG_EXIT_USER, "service: ", argv[n], " not available -- did you parse it?") ;
service_enable_disable(&graph, aresid, ares, areslen, 1, visit, propagate, info) ; service_enable_disable(&graph, hash, &hres, 1, propagate, info) ;
if (info->opt_tree) { if (info->opt_tree) {
service_switch_tree(&ares[aresid], info->base.s, info->treename.s, info) ; service_switch_tree(&hash->res, info->base.s, info->treename.s, info) ;
if (ares[aresid].logger.want && ares[aresid].type == TYPE_CLASSIC) { if (hash->res.logger.want && hash->res.type == TYPE_CLASSIC) {
int logid = service_resolve_array_search(ares, areslen, ares[aresid].sa.s + ares[aresid].logger.name) ; struct resolve_hash_s *log = hash_search(&hres, hash->res.sa.s + hash->res.logger.name) ;
if (logid < 0) if (log == NULL)
log_die(LOG_EXIT_USER, "service: ", ares[aresid].sa.s + ares[aresid].logger.name, " not available -- please make a bug report") ; log_die(LOG_EXIT_USER, "service: ", hash->res.sa.s + hash->res.logger.name, " not available -- please make a bug report") ;
service_switch_tree(&ares[logid], info->base.s, info->treename.s, info) ; service_switch_tree(&log->res, info->base.s, info->treename.s, info) ;
} }
} }
if (!stack_add_g(&stk, argv[n])) tostart[n] = *hash ;
log_dieu(LOG_EXIT_SYS, "add string") ;
} }
service_resolve_array_free(ares, areslen) ;
graph_free_all(&graph) ; graph_free_all(&graph) ;
e = 0 ; e = 0 ;
if (start && stk.len) { if (start && n) {
size_t len = stack_count_element(&stk) ; int nargc = 2 + n ;
int nargc = 2 + len ;
char const *prog = PROG ; char const *prog = PROG ;
char const *newargv[nargc] ; char const *newargv[nargc] ;
unsigned int m = 0 ; unsigned int m = 0 ;
...@@ -137,8 +128,8 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info) ...@@ -137,8 +128,8 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
info->usage = usage_start ; info->usage = usage_start ;
newargv[m++] = "start" ; newargv[m++] = "start" ;
FOREACH_STK(&stk, pos) for (; pos < n ; pos++)
newargv[m++] = stk.s + pos ; newargv[m++] = tostart[pos].name ;
newargv[m] = 0 ; newargv[m] = 0 ;
PROG = "start" ; PROG = "start" ;
...@@ -149,5 +140,7 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info) ...@@ -149,5 +140,7 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
info->usage = usage ; info->usage = usage ;
} }
hash_free(&hres) ;
return e ; return e ;
} }
...@@ -113,13 +113,15 @@ int ssexec_parse(int argc, char const *const *argv, ssexec_t *info) ...@@ -113,13 +113,15 @@ int ssexec_parse(int argc, char const *const *argv, ssexec_t *info)
* service can be a directory name. In this case * service can be a directory name. In this case
* we parse all services inside. */ * we parse all services inside. */
size_t pos = 0 ; size_t pos = 0 ;
struct resolve_hash_s *hres = NULL ;
FOREACH_SASTR(&sa, pos) FOREACH_SASTR(&sa, pos)
parse_service(sa.s + pos, info, force, conf) ; parse_service(&hres, sa.s + pos, info, force, conf) ;
}
sanitize_graph(info) ; hash_free(&hres) ;
}
stralloc_free(&sa) ; stralloc_free(&sa) ;
sanitize_graph(info) ;
return 0 ; return 0 ;
} }
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <oblibs/log.h> #include <oblibs/log.h>
#include <oblibs/types.h> #include <oblibs/types.h>
#include <oblibs/graph.h> #include <oblibs/graph.h>
#include <oblibs/stack.h>
#include <oblibs/string.h> #include <oblibs/string.h>
#include <skalibs/sgetopt.h> #include <skalibs/sgetopt.h>
...@@ -32,7 +31,6 @@ ...@@ -32,7 +31,6 @@
#include <66/service.h> #include <66/service.h>
#include <66/constants.h> #include <66/constants.h>
#include <66/tree.h> #include <66/tree.h>
#include <skalibs/djbunix.h>
int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info) int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
{ {
...@@ -42,17 +40,17 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info) ...@@ -42,17 +40,17 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
uint32_t flag = 0 ; uint32_t flag = 0 ;
uint8_t siglen = 0, issupervised = 0 ; uint8_t siglen = 0, issupervised = 0 ;
graph_t graph = GRAPH_ZERO ; graph_t graph = GRAPH_ZERO ;
struct resolve_hash_s *hres = NULL ;
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_ref pres = 0 ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ; struct resolve_hash_s tostate[argc] ;
struct resolve_hash_s toenable[argc] ;
unsigned int list[SS_MAX_SERVICE + 1], visit[SS_MAX_SERVICE + 1], ntostate = 0, ntoenable = 0, nservice = 0, n = 0 ;
ss_state_t sta = STATE_ZERO ; 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(list, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
memset(visit, 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)) ; memset(tostate, 0, argc * sizeof(struct resolve_hash_s)) ;
memset(toenable, 0, argc * sizeof(struct resolve_hash_s)) ;
FLAGS_SET(flag, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_TOPARSE|STATE_FLAGS_WANTUP) ; FLAGS_SET(flag, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_TOPARSE|STATE_FLAGS_WANTUP) ;
{ {
...@@ -87,38 +85,38 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info) ...@@ -87,38 +85,38 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
log_usage(info->usage, "\n", info->help) ; log_usage(info->usage, "\n", info->help) ;
/** build the graph of the entire system */ /** build the graph of the entire system */
graph_build_service(&graph, ares, &areslen, info, flag) ; graph_build_service(&graph, &hres, info, flag) ;
if (!graph.mlen) if (!graph.mlen)
log_die(LOG_EXIT_USER, "services selection is not available -- have you already parsed a service?") ; log_die(LOG_EXIT_USER, "services selection is not available -- have you already parsed a service?") ;
for (; n < argc ; n++) { for (; n < argc ; n++) {
int aresid = service_resolve_array_search(ares, areslen, argv[n]) ; struct resolve_hash_s *hash = hash_search(&hres, argv[n]) ;
if (aresid < 0) if (hash == NULL)
log_die(LOG_EXIT_USER, "service: ", argv[n], " not available -- did you parse it?") ; log_die(LOG_EXIT_USER, "service: ", argv[n], " not available -- did you parse it?") ;
char status[strlen(ares[aresid].sa.s + ares[aresid].path.servicedir) + SS_STATE_LEN + 1] ; pres = &hash->res ;
char status[strlen(pres->sa.s + pres->path.servicedir) + SS_STATE_LEN + 1] ;
auto_strings(status, ares[aresid].sa.s + ares[aresid].path.servicedir, SS_STATE) ; auto_strings(status, pres->sa.s + pres->path.servicedir, SS_STATE) ;
if (!state_read(&sta, &ares[aresid])) if (!state_read(&sta, pres))
log_dieu(LOG_EXIT_SYS, "read state file of: ", argv[n]) ; log_dieu(LOG_EXIT_SYS, "read state file of: ", argv[n]) ;
sta.toparse = STATE_FLAGS_TRUE ; sta.toparse = STATE_FLAGS_TRUE ;
if (!state_write(&sta, &ares[aresid])) if (!state_write(&sta, pres))
log_dieusys(LOG_EXIT_SYS, "write status file of: ", argv[n]) ; log_dieusys(LOG_EXIT_SYS, "write status file of: ", argv[n]) ;
/** need to reverse the previous state change to /** need to reverse the previous state change to
* for current live service.*/ * for current live service.*/
tostate[ntostate++] = aresid ; tostate[ntostate++] = *hash ;
issupervised = sta.issupervised == STATE_FLAGS_TRUE ? 1 : 0 ; issupervised = sta.issupervised == STATE_FLAGS_TRUE ? 1 : 0 ;
if (ares[aresid].enabled && !ares[aresid].inns) if (pres->enabled && !pres->inns)
if (!stack_add_g(&stk, argv[n])) toenable[ntoenable++] = *hash ;
log_dieu(LOG_EXIT_SYS, "add string") ;
if (!issupervised) { if (!issupervised) {
/* only force to parse it again */ /* only force to parse it again */
...@@ -131,7 +129,7 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info) ...@@ -131,7 +129,7 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
/** services of group boot cannot be restarted, the changes will appear only at /** services of group boot cannot be restarted, the changes will appear only at
* next reboot.*/ * next reboot.*/
r = tree_ongroups(ares[aresid].sa.s + ares[aresid].path.home, ares[aresid].sa.s + ares[aresid].treename, TREE_GROUPS_BOOT) ; r = tree_ongroups(pres->sa.s + pres->path.home, pres->sa.s + pres->treename, TREE_GROUPS_BOOT) ;
if (r < 0) if (r < 0)
log_dieu(LOG_EXIT_SYS, "get groups of service: ", argv[n]) ; log_dieu(LOG_EXIT_SYS, "get groups of service: ", argv[n]) ;
...@@ -139,7 +137,7 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info) ...@@ -139,7 +137,7 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
if (r) if (r)
continue ; continue ;
graph_compute_visit(ares, aresid, visit, list, &graph, &nservice, 1) ; graph_compute_visit(*hash, visit, list, &graph, &nservice, 1) ;
} }
} }
...@@ -208,12 +206,12 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info) ...@@ -208,12 +206,12 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
/** live of the service still exist. /** live of the service still exist.
* Reverse to the previous state of the toparse flag. */ * Reverse to the previous state of the toparse flag. */
if (state_read_remote(&sta, ares[tostate[n]].sa.s + ares[tostate[n]].live.statedir)) { if (state_read_remote(&sta, tostate[n].res.sa.s + tostate[n].res.live.statedir)) {
sta.toparse = STATE_FLAGS_FALSE ; sta.toparse = STATE_FLAGS_FALSE ;
if (!state_write_remote(&sta, ares[tostate[n]].sa.s + ares[tostate[n]].live.statedir)) if (!state_write_remote(&sta, tostate[n].res.sa.s + tostate[n].res.live.statedir))
log_warnusys("write status file of: ", ares[tostate[n]].sa.s + ares[tostate[n]].live.statedir) ; log_warnusys("write status file of: ", tostate[n].res.sa.s + tostate[n].res.live.statedir) ;
} }
} }
...@@ -251,11 +249,11 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info) ...@@ -251,11 +249,11 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
info->usage = usage ; info->usage = usage ;
} }
if (stk.len) { if (ntoenable) {
/** enable again the service if it was enabled */ /** enable again the service if it was enabled */
unsigned int m = 0 ; unsigned int m = 0 ;
int nargc = 2 + stk.count ; int nargc = 2 + ntoenable ;
char const *prog = PROG ; char const *prog = PROG ;
char const *newargv[nargc] ; char const *newargv[nargc] ;
...@@ -268,10 +266,10 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info) ...@@ -268,10 +266,10 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
newargv[m++] = "enable" ; newargv[m++] = "enable" ;
n = 0 ; n = 0 ;
FOREACH_STK(&stk, n) { for (; n < ntoenable ; n++) {
char *name = stk.s + n ; char *name = toenable[n].name ;
if (get_rstrlen_until(name,SS_LOG_SUFFIX) < 0) if (get_rstrlen_until(name,SS_LOG_SUFFIX) < 0)
newargv[m++] = name ; newargv[m++] = name ;
} }
...@@ -286,10 +284,8 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info) ...@@ -286,10 +284,8 @@ int ssexec_reconfigure(int argc, char const *const *argv, ssexec_t *info)
} }
freed: freed:
resolve_free(wres) ; hash_free(&hres) ;
service_resolve_array_free(ares, areslen) ;
graph_free_all(&graph) ; graph_free_all(&graph) ;
return e ; return e ;
} }
...@@ -37,9 +37,8 @@ int ssexec_reload(int argc, char const *const *argv, ssexec_t *info) ...@@ -37,9 +37,8 @@ int ssexec_reload(int argc, char const *const *argv, ssexec_t *info)
uint32_t flag = 0 ; uint32_t flag = 0 ;
uint8_t siglen = 2 ; uint8_t siglen = 2 ;
graph_t graph = GRAPH_ZERO ; graph_t graph = GRAPH_ZERO ;
struct resolve_hash_s *hres = NULL ;
unsigned int areslen = 0, m = 0 ; unsigned int m = 0 ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ;
FLAGS_SET(flag, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_WANTUP) ; FLAGS_SET(flag, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_WANTUP) ;
...@@ -105,20 +104,20 @@ int ssexec_reload(int argc, char const *const *argv, ssexec_t *info) ...@@ -105,20 +104,20 @@ int ssexec_reload(int argc, char const *const *argv, ssexec_t *info)
} }
/** build the graph of the entire system */ /** build the graph of the entire system */
graph_build_service(&graph, ares, &areslen, info, flag) ; graph_build_service(&graph, &hres, info, flag) ;
if (!graph.mlen) if (!graph.mlen)
log_die(LOG_EXIT_USER, "services selection is not available -- please make a bug report") ; log_die(LOG_EXIT_USER, "services selection is not available -- please make a bug report") ;
for (n = 0 ; n < argc ; n++) { for (n = 0 ; n < argc ; n++) {
int aresid = service_resolve_array_search(ares, areslen, argv[n]) ; struct resolve_hash_s *hash = hash_search(&hres, argv[n]) ;
if (aresid < 0) if (hash == NULL)
log_die(LOG_EXIT_USER, "service: ", *argv, " not available -- did you pars it?") ; log_die(LOG_EXIT_USER, "service: ", *argv, " not available -- did you pars it?") ;
if (ares[aresid].type == TYPE_ONESHOT) { if (hash->res.type == TYPE_ONESHOT) {
nargc++ ; nargc++ ;
nargv[m++] = ares[aresid].sa.s + ares[aresid].name ; nargv[m++] = hash->res.sa.s + hash->res.name ;
} }
} }
...@@ -171,7 +170,7 @@ int ssexec_reload(int argc, char const *const *argv, ssexec_t *info) ...@@ -171,7 +170,7 @@ int ssexec_reload(int argc, char const *const *argv, ssexec_t *info)
} }
err: err:
service_resolve_array_free(ares, areslen) ; hash_free(&hres) ;
graph_free_all(&graph) ; graph_free_all(&graph) ;
return r ; return r ;
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <66/constants.h> #include <66/constants.h>
#include <66/svc.h> #include <66/svc.h>
#include <66/utils.h> #include <66/utils.h>
#include <66/hash.h>
static void auto_remove(char const *path) static void auto_remove(char const *path)
{ {
...@@ -46,7 +47,7 @@ static void auto_remove(char const *path) ...@@ -46,7 +47,7 @@ static void auto_remove(char const *path)
log_dieusys(LOG_EXIT_SYS, "remove directory: ", path) ; log_dieusys(LOG_EXIT_SYS, "remove directory: ", path) ;
} }
static void remove_deps(resolve_service_t *res, resolve_service_t *ares, unsigned int *areslen, stralloc *sa, ssexec_t *info) static void remove_deps(resolve_service_t *res, struct resolve_hash_s **hres, stralloc *sa, ssexec_t *info)
{ {
if (!res->dependencies.nrequiredby) if (!res->dependencies.nrequiredby)
...@@ -82,10 +83,12 @@ static void remove_deps(resolve_service_t *res, resolve_service_t *ares, unsigne ...@@ -82,10 +83,12 @@ static void remove_deps(resolve_service_t *res, resolve_service_t *ares, unsigne
if (!sastr_add_string(sa, stk.s + pos)) if (!sastr_add_string(sa, stk.s + pos))
log_dieusys(LOG_EXIT_SYS, "add service: ", stk.s + pos, " to selection") ; log_dieusys(LOG_EXIT_SYS, "add service: ", stk.s + pos, " to selection") ;
ares[(*areslen)++] = dres ; log_trace("add service: ", stk.s + pos, " to the service selection") ;
if (!hash_add(hres, stk.s + pos, dres))
log_dieu(LOG_EXIT_SYS, "append service selection with: ", stk.s + pos) ;
if (dres.dependencies.nrequiredby) if (dres.dependencies.nrequiredby)
remove_deps(&dres, ares, areslen, sa, info) ; remove_deps(&dres, hres, sa, info) ;
} }
free(wres) ; free(wres) ;
...@@ -109,9 +112,10 @@ static void remove_service(resolve_service_t *res, ssexec_t *info) ...@@ -109,9 +112,10 @@ static void remove_service(resolve_service_t *res, ssexec_t *info)
resolve_wrapper_t_ref lwres = resolve_set_struct(DATA_SERVICE, &lres) ; resolve_wrapper_t_ref lwres = resolve_set_struct(DATA_SERVICE, &lres) ;
r = resolve_read_g(lwres, info->base.s, res->sa.s + res->logger.name) ; r = resolve_read_g(lwres, info->base.s, res->sa.s + res->logger.name) ;
if (r <= 0) if (r <= 0) {
log_dieusys(LOG_EXIT_SYS, "read resolve file of: ", res->sa.s + res->logger.name) ; log_warnusys("read resolve file of: ", res->sa.s + res->logger.name, " -- ignoring it") ;
goto end ;
}
auto_remove(lres.sa.s + lres.path.servicedir) ; auto_remove(lres.sa.s + lres.path.servicedir) ;
auto_remove(lres.sa.s + lres.logger.destination) ; auto_remove(lres.sa.s + lres.logger.destination) ;
...@@ -130,7 +134,7 @@ static void remove_service(resolve_service_t *res, ssexec_t *info) ...@@ -130,7 +134,7 @@ static void remove_service(resolve_service_t *res, ssexec_t *info)
resolve_free(lwres) ; resolve_free(lwres) ;
} }
end:
auto_strings(sym, res->sa.s + res->path.home, SS_SYSTEM, SS_RESOLVE, SS_SERVICE, "/", res->sa.s + res->name) ; auto_strings(sym, res->sa.s + res->path.home, SS_SYSTEM, SS_RESOLVE, SS_SERVICE, "/", res->sa.s + res->name) ;
log_trace("remove symlink: ", sym) ; log_trace("remove symlink: ", sym) ;
...@@ -150,10 +154,10 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info) ...@@ -150,10 +154,10 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info)
size_t pos = 0 ; size_t pos = 0 ;
uint32_t flag = 0 ; uint32_t flag = 0 ;
uint8_t siglen = 0 ; uint8_t siglen = 0 ;
unsigned int areslen = 0 ;
ss_state_t ste = STATE_ZERO ; ss_state_t ste = STATE_ZERO ;
stralloc sa = STRALLOC_ZERO ; stralloc sa = STRALLOC_ZERO ;
resolve_wrapper_t_ref wres = 0 ; resolve_wrapper_t_ref wres = 0 ;
struct resolve_hash_s *hres = NULL, *c, *tmp ;
FLAGS_SET(flag, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_ISSUPERVISED|STATE_FLAGS_TOUNSUPERVISE|STATE_FLAGS_WANTDOWN) ; FLAGS_SET(flag, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_ISSUPERVISED|STATE_FLAGS_TOUNSUPERVISE|STATE_FLAGS_WANTDOWN) ;
...@@ -189,9 +193,6 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info) ...@@ -189,9 +193,6 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info)
if (argc < 1) if (argc < 1)
log_usage(info->usage, "\n", info->help) ; log_usage(info->usage, "\n", info->help) ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ;
memset(ares, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
for(; pos < argc ; pos++) { for(; pos < argc ; pos++) {
resolve_service_t res = RESOLVE_SERVICE_ZERO ; resolve_service_t res = RESOLVE_SERVICE_ZERO ;
...@@ -220,10 +221,12 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info) ...@@ -220,10 +221,12 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info)
log_dieusys(LOG_EXIT_SYS, "add service: ", argv[pos], " to selection") ; log_dieusys(LOG_EXIT_SYS, "add service: ", argv[pos], " to selection") ;
} }
ares[areslen++] = res ; log_trace("add service: ", argv[pos], " to the service selection") ;
if (!hash_add(&hres, argv[pos], res))
log_dieu(LOG_EXIT_SYS, "append service selection with: ", argv[pos]) ;
if (!siglen) if (!siglen)
remove_deps(&res, ares, &areslen, &sa, info) ; remove_deps(&res, &hres, &sa, info) ;
} }
r = svc_scandir_ok(info->scandir.s) ; r = svc_scandir_ok(info->scandir.s) ;
...@@ -263,18 +266,18 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info) ...@@ -263,18 +266,18 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info)
info->usage = usage ; info->usage = usage ;
} }
for (pos = 0 ; pos < areslen ; pos++) { HASH_ITER(hh, hres, c, tmp) {
remove_service(&ares[pos], info) ; remove_service(&c->res, info) ;
if (ares[pos].type == TYPE_MODULE) { if (c->res.type == TYPE_MODULE) {
if (ares[pos].dependencies.ncontents) { if (c->res.dependencies.ncontents) {
size_t pos = 0 ; size_t pos = 0 ;
resolve_service_t mres = RESOLVE_SERVICE_ZERO ; resolve_service_t mres = RESOLVE_SERVICE_ZERO ;
resolve_wrapper_t_ref mwres = resolve_set_struct(DATA_SERVICE, &mres) ; resolve_wrapper_t_ref mwres = resolve_set_struct(DATA_SERVICE, &mres) ;
_init_stack_(stk, strlen(ares[pos].sa.s + ares[pos].dependencies.contents)) ; _init_stack_(stk, strlen(c->res.sa.s + c->res.dependencies.contents)) ;
if (!stack_clean_string_g(&stk, c->res.sa.s + c->res.dependencies.contents)) if (!stack_clean_string_g(&stk, c->res.sa.s + c->res.dependencies.contents))
log_dieu(LOG_EXIT_SYS, "convert string") ; log_dieu(LOG_EXIT_SYS, "convert string") ;
...@@ -282,8 +285,10 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info) ...@@ -282,8 +285,10 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info)
FOREACH_STK(&stk, pos) { FOREACH_STK(&stk, pos) {
r = resolve_read_g(mwres, info->base.s, stk.s + pos) ; r = resolve_read_g(mwres, info->base.s, stk.s + pos) ;
if (r <= 0) if (r <= 0) {
log_dieusys(LOG_EXIT_SYS, "read resolve file of: ", stk.s + pos) ; log_warnusys("read resolve file of: ", stk.s + pos) ;
continue ;
}
remove_service(&mres, info) ; remove_service(&mres, info) ;
} }
...@@ -296,7 +301,7 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info) ...@@ -296,7 +301,7 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info)
if (!info->owner) { if (!info->owner) {
auto_strings(dir, SS_SERVICE_ADMDIR, ares[pos].sa.s + ares[pos].name) ; auto_strings(dir, SS_SERVICE_ADMDIR, c->res.sa.s + c->res.name) ;
} else { } else {
...@@ -305,7 +310,7 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info) ...@@ -305,7 +310,7 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info)
size_t dirlen = strlen(dir) ; size_t dirlen = strlen(dir) ;
auto_strings(dir + dirlen, SS_SERVICE_USERDIR, ares[pos].sa.s + ares[pos].name) ; auto_strings(dir + dirlen, SS_SERVICE_USERDIR, c->res.sa.s + c->res.name) ;
} }
auto_remove(dir) ; auto_remove(dir) ;
...@@ -313,7 +318,7 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info) ...@@ -313,7 +318,7 @@ int ssexec_remove(int argc, char const *const *argv, ssexec_t *info)
} }
stralloc_free(&sa) ; stralloc_free(&sa) ;
service_resolve_array_free(ares, areslen) ; hash_free(&hres) ;
free(wres) ; free(wres) ;
return 0 ; return 0 ;
......
...@@ -38,9 +38,7 @@ int ssexec_restart(int argc, char const *const *argv, ssexec_t *info) ...@@ -38,9 +38,7 @@ int ssexec_restart(int argc, char const *const *argv, ssexec_t *info)
uint32_t flag = 0 ; uint32_t flag = 0 ;
uint8_t siglen = 3 ; uint8_t siglen = 3 ;
graph_t graph = GRAPH_ZERO ; graph_t graph = GRAPH_ZERO ;
struct resolve_hash_s *hres = NULL ;
unsigned int areslen = 0 ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ;
ss_state_t sta = STATE_ZERO ; ss_state_t sta = STATE_ZERO ;
FLAGS_SET(flag, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_TORESTART|STATE_FLAGS_WANTUP) ; FLAGS_SET(flag, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_TORESTART|STATE_FLAGS_WANTUP) ;
...@@ -81,18 +79,18 @@ int ssexec_restart(int argc, char const *const *argv, ssexec_t *info) ...@@ -81,18 +79,18 @@ int ssexec_restart(int argc, char const *const *argv, ssexec_t *info)
log_diesys(LOG_EXIT_SYS,"scandir: ", info->scandir.s, " is not running") ; log_diesys(LOG_EXIT_SYS,"scandir: ", info->scandir.s, " is not running") ;
/** build the graph of the entire system */ /** build the graph of the entire system */
graph_build_service(&graph, ares, &areslen, info, flag) ; graph_build_service(&graph, &hres, info, flag) ;
if (!graph.mlen) if (!graph.mlen)
log_die(LOG_EXIT_USER, "services selection is not available -- have you already parsed a service?") ; log_die(LOG_EXIT_USER, "services selection is not available -- have you already parsed a service?") ;
for (n = 0 ; n < argc ; n++) { for (n = 0 ; n < argc ; n++) {
int aresid = service_resolve_array_search(ares, areslen, argv[n]) ; struct resolve_hash_s *hash = hash_search(&hres, argv[n]) ;
if (aresid < 0) if (hash == NULL)
log_die(LOG_EXIT_USER, "service: ", *argv, " not available -- did you parse it?") ; log_die(LOG_EXIT_USER, "service: ", *argv, " not available -- did you parse it?") ;
if (!state_read(&sta, &ares[aresid])) if (!state_read(&sta, &hash->res))
log_dieu(LOG_EXIT_SYS, "read state file of: ", argv[n]) ; log_dieu(LOG_EXIT_SYS, "read state file of: ", argv[n]) ;
if (sta.issupervised == STATE_FLAGS_FALSE) if (sta.issupervised == STATE_FLAGS_FALSE)
...@@ -117,7 +115,7 @@ int ssexec_restart(int argc, char const *const *argv, ssexec_t *info) ...@@ -117,7 +115,7 @@ int ssexec_restart(int argc, char const *const *argv, ssexec_t *info)
r = svc_send_wait(argv, argc, sig, siglen, info) ; r = svc_send_wait(argv, argc, sig, siglen, info) ;
service_resolve_array_free(ares, areslen) ; hash_free(&hres) ;
graph_free_all(&graph) ; graph_free_all(&graph) ;
return r ; return r ;
......
...@@ -54,17 +54,14 @@ int ssexec_signal(int argc, char const *const *argv, ssexec_t *info) ...@@ -54,17 +54,14 @@ int ssexec_signal(int argc, char const *const *argv, ssexec_t *info)
int r ; int r ;
uint8_t what = 1, requiredby = 0, propagate = 1 ; uint8_t what = 1, requiredby = 0, propagate = 1 ;
graph_t graph = GRAPH_ZERO ; graph_t graph = GRAPH_ZERO ;
unsigned int napid = 0 ; unsigned int napid = 0 ;
char updown[4] = "-w \0" ; char updown[4] = "-w \0" ;
uint8_t opt_updown = 0 ; uint8_t opt_updown = 0 ;
char data[DATASIZE + 1] = "-" ; char data[DATASIZE + 1] = "-" ;
unsigned int datalen = 1 ; unsigned int datalen = 1 ;
uint8_t reloadmsg = 0 ; uint8_t reloadmsg = 0 ;
struct resolve_hash_s *hres = NULL ;
unsigned int areslen = 0, list[SS_MAX_SERVICE + 1], visit[SS_MAX_SERVICE + 1] ; unsigned int list[SS_MAX_SERVICE + 1], visit[SS_MAX_SERVICE + 1] ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ;
/* /*
* STATE_FLAGS_TOPROPAGATE = 0 * STATE_FLAGS_TOPROPAGATE = 0
...@@ -175,20 +172,21 @@ int ssexec_signal(int argc, char const *const *argv, ssexec_t *info) ...@@ -175,20 +172,21 @@ int ssexec_signal(int argc, char const *const *argv, ssexec_t *info)
log_diesys(LOG_EXIT_SYS,"scandir: ", info->scandir.s," is not running") ; log_diesys(LOG_EXIT_SYS,"scandir: ", info->scandir.s," is not running") ;
/** build the graph of the entire system.*/ /** build the graph of the entire system.*/
graph_build_service(&graph, ares, &areslen, info, gflag) ; graph_build_service(&graph, &hres, info, gflag) ;
if (!graph.mlen) if (!graph.mlen)
log_die(LOG_EXIT_USER, "services selection is not supervised -- initiate its first") ; log_die(LOG_EXIT_USER, "services selection is not supervised -- initiate its first") ;
for (; *argv ; argv++) { for (; *argv ; argv++) {
int aresid = service_resolve_array_search(ares, areslen, *argv) ;
struct resolve_hash_s *hash = hash_search(&hres, *argv) ;
/** The service may not be supervised, for example serviceB depends on /** The service may not be supervised, for example serviceB depends on
* serviceA and serviceB was unsupervised by the user. So it will be ignored * serviceA and serviceB was unsupervised by the user. So it will be ignored
* by the function graph_build_service. In this case, the service does not * by the function graph_build_service. In this case, the service does not
* exist at array. * exist at array.
* *
* At stop process, just ignore it as it already down anyway */ * At stop process, just ignore it as it already down anyway */
if (aresid < 0) { if (hash == NULL) {
if (what && data[1] != 'r' || data[1] != 'h') { if (what && data[1] != 'r' || data[1] != 'h') {
log_warn("service: ", *argv, " is already stopped or unsupervised -- ignoring it") ; log_warn("service: ", *argv, " is already stopped or unsupervised -- ignoring it") ;
continue ; continue ;
...@@ -196,17 +194,17 @@ int ssexec_signal(int argc, char const *const *argv, ssexec_t *info) ...@@ -196,17 +194,17 @@ int ssexec_signal(int argc, char const *const *argv, ssexec_t *info)
log_die(LOG_EXIT_USER, "service: ", *argv, " not available -- did you parse it?") ; log_die(LOG_EXIT_USER, "service: ", *argv, " not available -- did you parse it?") ;
} }
} }
graph_compute_visit(ares, aresid, visit, list, &graph, &napid, requiredby) ; graph_compute_visit(*hash, visit, list, &graph, &napid, requiredby) ;
} }
pidservice_t apids[napid] ; pidservice_t apids[napid] ;
svc_init_array(list, napid, apids, &graph, ares, areslen, info, requiredby, gflag) ; svc_init_array(list, napid, apids, &graph, &hres, info, requiredby, gflag) ;
r = svc_launch(apids, napid, what, &graph, ares, areslen, info, updown, opt_updown, reloadmsg, data, propagate) ; r = svc_launch(apids, napid, what, &graph, &hres, info, updown, opt_updown, reloadmsg, data, propagate) ;
graph_free_all(&graph) ; graph_free_all(&graph) ;
service_resolve_array_free(ares, areslen) ; hash_free(&hres) ;
return r ; return r ;
} }
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <oblibs/sastr.h> #include <oblibs/sastr.h>
#include <skalibs/sgetopt.h> #include <skalibs/sgetopt.h>
#include <skalibs/genalloc.h>
#include <66/ssexec.h> #include <66/ssexec.h>
#include <66/config.h> #include <66/config.h>
...@@ -29,18 +30,19 @@ ...@@ -29,18 +30,19 @@
#include <66/sanitize.h> #include <66/sanitize.h>
#include <66/service.h> #include <66/service.h>
#include <66/enum.h> #include <66/enum.h>
#include <66/hash.h>
int ssexec_start(int argc, char const *const *argv, ssexec_t *info) int ssexec_start(int argc, char const *const *argv, ssexec_t *info)
{ {
log_flow() ; log_flow() ;
int n = 0 ;
uint32_t flag = 0 ; uint32_t flag = 0 ;
graph_t graph = GRAPH_ZERO ; graph_t graph = GRAPH_ZERO ;
uint8_t siglen = 3 ; uint8_t siglen = 3 ;
unsigned int list[SS_MAX_SERVICE + 1], visit[SS_MAX_SERVICE + 1], nservice = 0 ;
int n = 0 ; struct resolve_hash_s *hres = NULL ;
unsigned int areslen = 0, list[SS_MAX_SERVICE + 1], visit[SS_MAX_SERVICE + 1], nservice = 0 ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ;
memset(list, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ; memset(list, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
memset(visit, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ; memset(visit, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
...@@ -90,25 +92,24 @@ int ssexec_start(int argc, char const *const *argv, ssexec_t *info) ...@@ -90,25 +92,24 @@ int ssexec_start(int argc, char const *const *argv, ssexec_t *info)
sanitize_source(argv[n], info, flag) ; sanitize_source(argv[n], info, flag) ;
/** build the graph of the entire system */ /** build the graph of the entire system */
graph_build_service(&graph, ares, &areslen, info, flag) ; graph_build_service(&graph, &hres, info, flag) ;
if (!graph.mlen) if (!graph.mlen)
log_die(LOG_EXIT_USER, "services selection is not available -- please make a bug report") ; log_die(LOG_EXIT_USER, "services selection is not available -- please make a bug report") ;
for (n = 0 ; n < argc ; n++) { for (n = 0 ; n < argc ; n++) {
int aresid = service_resolve_array_search(ares, areslen, argv[n]) ; struct resolve_hash_s *hash = hash_search(&hres, argv[n]) ;
if (aresid < 0) if (hash == NULL)
log_die(LOG_EXIT_USER, "service: ", argv[n], " not available -- did you parse it?") ; log_die(LOG_EXIT_USER, "service: ", argv[n], " not available -- did you parse it?") ;
graph_compute_visit(ares, aresid, visit, list, &graph, &nservice, 0) ; graph_compute_visit(*hash, visit, list, &graph, &nservice, 0) ;
} }
/** initiate services at the corresponding scandir */ /** initiate services at the corresponding scandir */
sanitize_init(list, nservice, &graph, ares, areslen) ; sanitize_init(list, nservice, &graph, &hres) ;
service_resolve_array_free(ares, areslen) ;
hash_free(&hres) ;
graph_free_all(&graph) ; graph_free_all(&graph) ;
char *sig[siglen] ; char *sig[siglen] ;
......
...@@ -322,16 +322,13 @@ static void info_display_requiredby(char const *field, resolve_service_t *res) ...@@ -322,16 +322,13 @@ static void info_display_requiredby(char const *field, resolve_service_t *res)
size_t padding = 1 ; size_t padding = 1 ;
int r ; int r ;
graph_t graph = GRAPH_ZERO ; graph_t graph = GRAPH_ZERO ;
struct resolve_hash_s *hres = NULL ;
unsigned int areslen = 0 ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ;
stralloc deps = STRALLOC_ZERO ; stralloc deps = STRALLOC_ZERO ;
if (NOFIELD) padding = info_display_field_name(field) ; if (NOFIELD) padding = info_display_field_name(field) ;
else { field = 0 ; padding = 0 ; } else { field = 0 ; padding = 0 ; }
graph_build_service(&graph, ares, &areslen, pinfo, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_WANTUP) ; graph_build_service(&graph, &hres, pinfo, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_WANTUP) ;
if (!graph.mlen) if (!graph.mlen)
log_die(LOG_EXIT_USER, "services selection is not available -- please make a bug report") ; log_die(LOG_EXIT_USER, "services selection is not available -- please make a bug report") ;
...@@ -391,6 +388,7 @@ static void info_display_requiredby(char const *field, resolve_service_t *res) ...@@ -391,6 +388,7 @@ static void info_display_requiredby(char const *field, resolve_service_t *res)
} }
freed: freed:
graph_free_all(&graph) ; graph_free_all(&graph) ;
hash_free(&hres) ;
stralloc_free(&deps) ; stralloc_free(&deps) ;
} }
...@@ -399,16 +397,14 @@ static void info_display_deps(char const *field, resolve_service_t *res) ...@@ -399,16 +397,14 @@ static void info_display_deps(char const *field, resolve_service_t *res)
int r ; int r ;
size_t padding = 1 ; size_t padding = 1 ;
graph_t graph = GRAPH_ZERO ; graph_t graph = GRAPH_ZERO ;
struct resolve_hash_s *hres = NULL ;
unsigned int areslen = 0 ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ;
stralloc deps = STRALLOC_ZERO ; stralloc deps = STRALLOC_ZERO ;
if (NOFIELD) padding = info_display_field_name(field) ; if (NOFIELD) padding = info_display_field_name(field) ;
else { field = 0 ; padding = 0 ; } else { field = 0 ; padding = 0 ; }
graph_build_service(&graph, ares, &areslen, pinfo, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_WANTUP) ; graph_build_service(&graph, &hres, pinfo, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_WANTUP) ;
if (!graph.mlen) if (!graph.mlen)
log_die(LOG_EXIT_USER, "services selection is not available -- please make a bug report") ; log_die(LOG_EXIT_USER, "services selection is not available -- please make a bug report") ;
...@@ -468,6 +464,7 @@ static void info_display_deps(char const *field, resolve_service_t *res) ...@@ -468,6 +464,7 @@ static void info_display_deps(char const *field, resolve_service_t *res)
freed: freed:
graph_free_all(&graph) ; graph_free_all(&graph) ;
hash_free(&hres) ;
stralloc_free(&deps) ; stralloc_free(&deps) ;
} }
...@@ -504,9 +501,7 @@ static void info_display_contents(char const *field, resolve_service_t *res) ...@@ -504,9 +501,7 @@ static void info_display_contents(char const *field, resolve_service_t *res)
size_t padding = 1 ; size_t padding = 1 ;
graph_t graph = GRAPH_ZERO ; graph_t graph = GRAPH_ZERO ;
stralloc sa = STRALLOC_ZERO ; stralloc sa = STRALLOC_ZERO ;
struct resolve_hash_s *hres = NULL ;
unsigned int areslen = 0 ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ;
if (NOFIELD) padding = info_display_field_name(field) ; if (NOFIELD) padding = info_display_field_name(field) ;
else { field = 0 ; padding = 0 ; } else { field = 0 ; padding = 0 ; }
...@@ -517,7 +512,7 @@ static void info_display_contents(char const *field, resolve_service_t *res) ...@@ -517,7 +512,7 @@ static void info_display_contents(char const *field, resolve_service_t *res)
if (!sastr_clean_string(&sa, res->sa.s + res->dependencies.contents)) if (!sastr_clean_string(&sa, res->sa.s + res->dependencies.contents))
log_dieu(LOG_EXIT_SYS, "clean string") ; log_dieu(LOG_EXIT_SYS, "clean string") ;
service_graph_g(sa.s, sa.len, &graph, ares, &areslen, pinfo, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_WANTUP) ; service_graph_g(sa.s, sa.len, &graph, &hres, pinfo, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_WANTUP) ;
if (!graph.mlen) if (!graph.mlen)
log_die(LOG_EXIT_USER, "services selection is not available -- please make a bug report") ; log_die(LOG_EXIT_USER, "services selection is not available -- please make a bug report") ;
...@@ -564,7 +559,7 @@ static void info_display_contents(char const *field, resolve_service_t *res) ...@@ -564,7 +559,7 @@ static void info_display_contents(char const *field, resolve_service_t *res)
freed: freed:
graph_free_all(&graph) ; graph_free_all(&graph) ;
service_resolve_array_free(ares, areslen) ; hash_free(&hres) ;
stralloc_free(&sa) ; stralloc_free(&sa) ;
} }
......
...@@ -41,9 +41,8 @@ int ssexec_stop(int argc, char const *const *argv, ssexec_t *info) ...@@ -41,9 +41,8 @@ int ssexec_stop(int argc, char const *const *argv, ssexec_t *info)
graph_t graph = GRAPH_ZERO ; graph_t graph = GRAPH_ZERO ;
uint8_t siglen = 3 ; uint8_t siglen = 3 ;
int e = 0 ; int e = 0 ;
struct resolve_hash_s *hres = NULL ;
unsigned int areslen = 0, list[SS_MAX_SERVICE + 1], visit[SS_MAX_SERVICE + 1], nservice = 0, pos = 0, idx = 0 ; unsigned int list[SS_MAX_SERVICE + 1], visit[SS_MAX_SERVICE + 1], nservice = 0, pos = 0, idx = 0 ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ;
memset(list, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ; memset(list, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
memset(visit, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ; memset(visit, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
...@@ -99,25 +98,24 @@ int ssexec_stop(int argc, char const *const *argv, ssexec_t *info) ...@@ -99,25 +98,24 @@ int ssexec_stop(int argc, char const *const *argv, ssexec_t *info)
log_diesys(LOG_EXIT_SYS,"scandir: ", info->scandir.s," is not running") ; log_diesys(LOG_EXIT_SYS,"scandir: ", info->scandir.s," is not running") ;
/** build the graph of the entire system */ /** build the graph of the entire system */
graph_build_service(&graph, ares, &areslen, info, flag) ; graph_build_service(&graph, &hres, info, flag) ;
if (!graph.mlen) if (!graph.mlen)
log_die(LOG_EXIT_USER, "services selection is not available -- did you start it first?") ; log_die(LOG_EXIT_USER, "services selection is not available -- did you start it first?") ;
for (; pos < argc ; pos++) { for (; pos < argc ; pos++) {
int aresid = service_resolve_array_search(ares, areslen, argv[pos]) ;
/** The service may not be supervised, so it will be ignored by the /** The service may not be supervised, so it will be ignored by the
* function graph_build_service. In this case, the service does not * function graph_build_service. In this case, the service does not
* exist at array. * exist at array.
* *
* This the stop process, just ignore it as it already down anyway */ * This the stop process, just ignore it as it already down anyway */
if (aresid < 0) { struct resolve_hash_s *hash = hash_search(&hres, argv[pos]) ;
if (hash == NULL) {
log_warn("service: ", argv[pos], " is already stopped or unsupervised -- ignoring it") ; log_warn("service: ", argv[pos], " is already stopped or unsupervised -- ignoring it") ;
continue ; continue ;
} }
graph_compute_visit(ares, aresid, visit, list, &graph, &nservice, 1) ; graph_compute_visit(*hash, visit, list, &graph, &nservice, 1) ;
} }
char *sig[siglen] ; char *sig[siglen] ;
...@@ -155,17 +153,17 @@ int ssexec_stop(int argc, char const *const *argv, ssexec_t *info) ...@@ -155,17 +153,17 @@ int ssexec_stop(int argc, char const *const *argv, ssexec_t *info)
fvisit[idx] = 1 ; fvisit[idx] = 1 ;
} }
int aresid = service_resolve_array_search(ares, areslen, name) ; struct resolve_hash_s *hash = hash_search(&hres, name) ;
if (aresid < 0) if (hash == NULL)
log_die(LOG_EXIT_USER, "service: ", name, " not available -- please make a bug report") ; log_die(LOG_EXIT_USER, "service: ", name, " not available -- please make a bug report") ;
/** the logger need to be stopped in case of unsupervise request */ /** the logger need to be stopped in case of unsupervise request */
if (FLAGS_ISSET(flag, STATE_FLAGS_TOUNSUPERVISE)) { if (FLAGS_ISSET(flag, STATE_FLAGS_TOUNSUPERVISE)) {
if (get_rstrlen_until(name, SS_LOG_SUFFIX) < 0 && ares[aresid].logger.want) { if (get_rstrlen_until(name, SS_LOG_SUFFIX) < 0 && hash->res.logger.want) {
nargv[nargc++] = ares[aresid].sa.s + ares[aresid].logger.name ; nargv[nargc++] = hash->res.sa.s + hash->res.logger.name ;
idx = graph_hash_vertex_get_id(&graph, ares[aresid].sa.s + ares[aresid].logger.name) ; idx = graph_hash_vertex_get_id(&graph, hash->res.sa.s + hash->res.logger.name) ;
if (!fvisit[idx]) { if (!fvisit[idx]) {
flist[fnservice++] = idx ; flist[fnservice++] = idx ;
fvisit[idx] = 1 ; fvisit[idx] = 1 ;
...@@ -179,9 +177,9 @@ int ssexec_stop(int argc, char const *const *argv, ssexec_t *info) ...@@ -179,9 +177,9 @@ int ssexec_stop(int argc, char const *const *argv, ssexec_t *info)
e = svc_send_wait(nargv, nargc, sig, siglen, info) ; e = svc_send_wait(nargv, nargc, sig, siglen, info) ;
if (FLAGS_ISSET(flag, STATE_FLAGS_TOUNSUPERVISE)) if (FLAGS_ISSET(flag, STATE_FLAGS_TOUNSUPERVISE))
svc_unsupervise(flist, fnservice, &graph, ares, areslen, info) ; svc_unsupervise(flist, fnservice, &graph, &hres, info) ;
service_resolve_array_free(ares, areslen) ; hash_free(&hres) ;
graph_free_all(&graph) ; graph_free_all(&graph) ;
return e ; return e ;
......
...@@ -40,9 +40,8 @@ static void doit(stralloc *sa, ssexec_t *info, uint8_t earlier) ...@@ -40,9 +40,8 @@ static void doit(stralloc *sa, ssexec_t *info, uint8_t earlier)
uint32_t flag = 0 ; uint32_t flag = 0 ;
graph_t graph = GRAPH_ZERO ; graph_t graph = GRAPH_ZERO ;
struct resolve_hash_s *hres = NULL ;
unsigned int areslen = 0, list[SS_MAX_SERVICE + 1], visit[SS_MAX_SERVICE + 1], nservice = 0, n = 0 ; unsigned int list[SS_MAX_SERVICE + 1], visit[SS_MAX_SERVICE + 1], nservice = 0, n = 0 ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ;
memset(list, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ; memset(list, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
memset(visit, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ; memset(visit, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
...@@ -52,15 +51,16 @@ static void doit(stralloc *sa, ssexec_t *info, uint8_t earlier) ...@@ -52,15 +51,16 @@ static void doit(stralloc *sa, ssexec_t *info, uint8_t earlier)
FLAGS_SET(flag, STATE_FLAGS_ISEARLIER) ; FLAGS_SET(flag, STATE_FLAGS_ISEARLIER) ;
/** build the graph of the entire system */ /** build the graph of the entire system */
graph_build_service(&graph, ares, &areslen, info, flag) ; graph_build_service(&graph, &hres, info, flag) ;
if (!graph.mlen) if (!graph.mlen)
log_die(LOG_EXIT_USER, "services selection is not available -- have you already parsed a service?") ; log_die(LOG_EXIT_USER, "services selection is not available -- have you already parsed a service?") ;
FOREACH_SASTR(sa, n) { FOREACH_SASTR(sa, n) {
int aresid = service_resolve_array_search(ares, areslen, sa->s + n) ; struct resolve_hash_s *hash ;
if (aresid < 0) { hash = hash_search(&hres, sa->s + n) ;
if (hash == NULL) {
if (earlier) { if (earlier) {
log_trace("ignoring none earlier service: ", sa->s + n) ; log_trace("ignoring none earlier service: ", sa->s + n) ;
...@@ -77,7 +77,7 @@ static void doit(stralloc *sa, ssexec_t *info, uint8_t earlier) ...@@ -77,7 +77,7 @@ static void doit(stralloc *sa, ssexec_t *info, uint8_t earlier)
if (earlier) { if (earlier) {
if (ares[aresid].earlier) { if (hash->res.earlier) {
list[nservice++] = idx ; list[nservice++] = idx ;
visit[idx] = 1 ; visit[idx] = 1 ;
...@@ -85,14 +85,14 @@ static void doit(stralloc *sa, ssexec_t *info, uint8_t earlier) ...@@ -85,14 +85,14 @@ static void doit(stralloc *sa, ssexec_t *info, uint8_t earlier)
} else { } else {
if (ares[aresid].enabled) { if (hash->res.enabled) {
list[nservice++] = idx ; list[nservice++] = idx ;
visit[idx] = 1 ; visit[idx] = 1 ;
} else { } else {
log_trace("ignoring not enabled service: ", ares[aresid].sa.s + ares[aresid].name) ; log_trace("ignoring not enabled service: ", hash->res.sa.s + hash->res.name) ;
} }
} }
...@@ -109,13 +109,14 @@ static void doit(stralloc *sa, ssexec_t *info, uint8_t earlier) ...@@ -109,13 +109,14 @@ static void doit(stralloc *sa, ssexec_t *info, uint8_t earlier)
char *name = graph.data.s + genalloc_s(graph_hash_t,&graph.hash)[l[pos]].vertex ; char *name = graph.data.s + genalloc_s(graph_hash_t,&graph.hash)[l[pos]].vertex ;
aresid = service_resolve_array_search(ares, areslen, name) ; struct resolve_hash_s *h ;
if (aresid < 0) h = hash_search(&hres, name) ;
if (hash == NULL)
log_die(LOG_EXIT_USER, "service: ", name, " not available -- did you parse it?") ; log_die(LOG_EXIT_USER, "service: ", name, " not available -- did you parse it?") ;
if (earlier) { if (earlier) {
if (ares[aresid].earlier) { if (h->res.earlier) {
list[nservice++] = l[pos] ; list[nservice++] = l[pos] ;
visit[l[pos]] = 1 ; visit[l[pos]] = 1 ;
...@@ -123,7 +124,7 @@ static void doit(stralloc *sa, ssexec_t *info, uint8_t earlier) ...@@ -123,7 +124,7 @@ static void doit(stralloc *sa, ssexec_t *info, uint8_t earlier)
} else { } else {
if (ares[aresid].enabled) { if (h->res.enabled) {
list[nservice++] = l[pos] ; list[nservice++] = l[pos] ;
visit[l[pos]] = 1 ; visit[l[pos]] = 1 ;
...@@ -134,9 +135,9 @@ static void doit(stralloc *sa, ssexec_t *info, uint8_t earlier) ...@@ -134,9 +135,9 @@ static void doit(stralloc *sa, ssexec_t *info, uint8_t earlier)
} }
} }
sanitize_init(list, nservice, &graph, ares, areslen) ; sanitize_init(list, nservice, &graph, &hres) ;
service_resolve_array_free(ares, areslen) ; hash_free(&hres) ;
graph_free_all(&graph) ; graph_free_all(&graph) ;
} }
......
...@@ -643,10 +643,6 @@ static int async_deps(struct resolve_hash_tree_s **htres, pidtree_t *apidt, unsi ...@@ -643,10 +643,6 @@ static int async_deps(struct resolve_hash_tree_s **htres, pidtree_t *apidt, unsi
if (!visit[pos]) { if (!visit[pos]) {
id = pidtree_get_id(apidt, id) ;
if (id < 0)
log_dieu(LOG_EXIT_SYS, "get apidtree id -- please make a bug report") ;
id = check_action(apidt, id, c, what) ; id = check_action(apidt, id, c, what) ;
if (id < 0) if (id < 0)
log_die(LOG_EXIT_SYS, "tree dependency: ", apidt[id].tres->sa.s + apidt[id].tres->name, " of: ", apidt[id].tres->sa.s + apidt[id].tres->name," crashed") ; log_die(LOG_EXIT_SYS, "tree dependency: ", apidt[id].tres->sa.s + apidt[id].tres->name, " of: ", apidt[id].tres->sa.s + apidt[id].tres->name," crashed") ;
......
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