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

prefix each interdependences of module by its name

parent 49575e7b
No related branches found
No related tags found
No related merge requests found
......@@ -33,16 +33,76 @@
#include <66/constants.h>
#include <66/instance.h>
#include <66/utils.h>
#include <66/parser.h>
#include <66/parse.h>
#include <66/sanitize.h>
static void convert_tomodule(resolve_service_t *res, char const *module)
{
resolve_wrapper_t_ref wres = resolve_set_struct(DATA_SERVICE, res) ;
stralloc sa = STRALLOC_ZERO ;
size_t pos = 0, mlen = strlen(module) ;
if (res->dependencies.ndepends) {
if (!sastr_clean_string(&sa, res->sa.s + res->dependencies.depends))
log_die_nomem("stralloc") ;
size_t len = (mlen + 1 + SS_MAX_TREENAME + 2) * res->dependencies.ndepends ;
char n[len] ;
memset(n, 0, len) ;
FOREACH_SASTR(&sa, pos) {
auto_strings(n + strlen(n), module, ":", sa.s + pos, " ") ;
}
n[strlen(n) - 1] = 0 ;
res->dependencies.depends = resolve_add_string(wres, n) ;
}
if (res->dependencies.nrequiredby) {
sa.len = 0 ;
if (!sastr_clean_string(&sa, res->sa.s + res->dependencies.requiredby))
log_die_nomem("stralloc") ;
size_t len = (mlen + 1 + SS_MAX_TREENAME + 2) * res->dependencies.nrequiredby ;
char n[len] ;
memset(n, 0, len) ;
pos = 0 ;
FOREACH_SASTR(&sa, pos) {
char n[mlen + 1 + strlen(sa.s + pos) + 1] ;
auto_strings(n + strlen(n), module, ":", sa.s + pos, " ") ;
}
n[strlen(n) - 1] = 0 ;
res->dependencies.requiredby = resolve_add_string(wres, n) ;
}
stralloc_free(&sa) ;
free(wres) ;
}
void parse_module(resolve_service_t *res, resolve_service_t *ares, unsigned int *areslen, ssexec_t *info, uint8_t force)
{
log_flow() ;
int r, insta = -1 ;
unsigned int residx = 0 ;
size_t pos = 0, pathlen = 0 ;
char *name = res->sa.s + res->name ;
char name[strlen(res->sa.s + res->name) + 1] ;
auto_strings(name,res->sa.s + res->name) ;
char *src = res->sa.s + res->path.frontend ;
char dirname[strlen(src) + 1] ;
char path[SS_MAX_PATH_LEN] ;
......@@ -58,15 +118,6 @@ void parse_module(resolve_service_t *res, resolve_service_t *ares, unsigned int
insta = instance_check(name) ;
instance_splitname_to_char(ainsta, name, insta, 0) ;
size_t prefixlen = strlen(name) ;
char prefix[prefixlen + 2] ;
instance_splitname_to_char(prefix, name, insta, 1) ;
auto_strings(prefix + strlen(prefix), "-") ;
prefixlen = strlen(prefix) ;
if (!getuid()) {
auto_strings(path, SS_SERVICE_ADMDIR, name) ;
......@@ -101,12 +152,14 @@ void parse_module(resolve_service_t *res, resolve_service_t *ares, unsigned int
} else {
/** Must reconfigure all services of the module */
if (force < 1) {
if (!force) {
log_warn("skip configuration of the module: ", name, " -- already configured") ;
goto deps ;
}
log_trace("remove directory: ", path) ;
if (!dir_rm_rf(path))
log_dieusys (LOG_EXIT_SYS, "remove: ", path) ;
......@@ -152,6 +205,7 @@ void parse_module(resolve_service_t *res, resolve_service_t *ares, unsigned int
list.len = 0 ;
char const *exclude[3] = { SS_MODULE_CONFIG_DIR + 1, SS_MODULE_SERVICE_INSTANCE + 1, 0 } ;
if (!sastr_dir_get_recursive(&list, t, exclude, S_IFREG, 1))
log_dieusys(LOG_EXIT_SYS, "get file(s) of module: ", name) ;
......@@ -166,8 +220,8 @@ void parse_module(resolve_service_t *res, resolve_service_t *ares, unsigned int
char *dname = ll + pos ;
char ainsta[pathlen + SS_MODULE_SERVICE_INSTANCE_LEN + 1 + SS_MAX_SERVICE_NAME + 1] ;
size_t namelen = strlen(dname) ;
char bname[namelen] ;
size_t dlen = strlen(dname) ;
char bname[dlen] ;
if (!ob_basename(bname,dname))
log_dieu(LOG_EXIT_SYS, "find basename of: ", dname) ;
......@@ -177,49 +231,51 @@ void parse_module(resolve_service_t *res, resolve_service_t *ares, unsigned int
dname = ainsta ;
}
if (!sastr_add_string(&list, bname))
log_die_nomem("stralloc") ;
if (!strcmp(name, bname))
log_die(LOG_EXIT_SYS, "cyclic call detected -- ", name, " call ", bname) ;
/** nothing to do with the exit code*/
parse_frontend(dname, ares, areslen, info, force, conf, &residx, path, bname) ;
char n[strlen(name) + 1 + strlen(bname) + 1] ;
wres = resolve_set_struct(DATA_SERVICE, &ares[residx]) ;
auto_strings(n, name, ":", bname) ;
ares[residx].inmodule = resolve_add_string(wres, name) ;
}
char deps[list.len] ;
if (!sastr_add_string(&list, n))
log_die_nomem("stralloc") ;
sastr_to_char(deps, &list) ;
parse_frontend(dname, ares, areslen, info, force, conf, path, bname, name) ;
}
llen = list.len ;
sastr_to_char(ll, &list) ;
list.len = 0 ;
/* rebuild the dependencies list incorporating the services defined inside
* the module.
for (pos = 0 ; pos < llen ; pos += strlen(ll + pos) + 1) {
if (res->dependencies.ndepends)
if (!sastr_clean_string(&list, res->sa.s + res->dependencies.depends))
log_dieu(LOG_EXIT_SYS, "clean string") ;
int aresid = service_resolve_array_search(ares, *areslen, ll + pos) ;
if (aresid < 0)
log_die(LOG_EXIT_USER, "service: ",ll + pos, " not available -- please make a bug report") ;
if (ares[aresid].dependencies.ndepends || ares[aresid].dependencies.nrequiredby)
convert_tomodule(&ares[aresid], name) ;
if (ares[aresid].logger.want && ares[aresid].type == TYPE_CLASSIC) {
res->dependencies.depends = parse_compute_list(wres, &list, &res->dependencies.ndepends, 0) ;
char n[strlen(ares[aresid].sa.s + ares[aresid].name) + SS_LOG_SUFFIX_LEN + 1] ;
list.len = 0 ;
*/
auto_strings(n, ares[aresid].sa.s + ares[aresid].name, SS_LOG_SUFFIX) ;
wres = resolve_set_struct(DATA_SERVICE, res) ;
if (!sastr_add_string(&list, n))
log_die_nomem("stralloc") ;
}
for (pos = 0 ; pos < llen ; pos += strlen(deps + pos) + 1)
if (!sastr_add_string(&list, deps + pos))
if (!sastr_add_string(&list, ll + pos))
log_die_nomem("stralloc") ;
}
wres = resolve_set_struct(DATA_SERVICE, res) ;
res->regex.contents = parse_compute_list(wres, &list, &res->regex.ncontents, 0) ;
res->dependencies.contents = parse_compute_list(wres, &list, &res->dependencies.ncontents, 0) ;
free(wres) ;
stralloc_free(&list) ;
......
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