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
/*
* service_resolve_array_free.c
*
* Copyright (c) 2018-2023 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 <skalibs/stralloc.h>
#include <66/service.h>
void service_resolve_array_free(resolve_service_t *ares, unsigned int areslen)
{
unsigned int pos = 0 ;
for (; pos < areslen ; pos++)
stralloc_free(&ares[pos].sa) ;
}
......@@ -28,7 +28,7 @@
#include <66/sanitize.h>
/** sares -> services ares */
int svc_compute_ns(resolve_service_t *sares, unsigned int sareslen, unsigned int saresid, uint8_t what, ssexec_t *info, char const *updown, uint8_t opt_updown, uint8_t reloadmsg,char const *data, uint8_t propagate, pidservice_t *handled, unsigned int nhandled)
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 *handled, unsigned int nhandled)
{
log_flow() ;
......@@ -39,12 +39,11 @@ int svc_compute_ns(resolve_service_t *sares, unsigned int sareslen, unsigned int
_init_stack_(stk, SS_MAX_SERVICE * SS_MAX_SERVICE_NAME) ;
unsigned int napid = 0 ;
unsigned int areslen = 0, list[SS_MAX_SERVICE + 1], visit[SS_MAX_SERVICE + 1] ;
resolve_service_t ares[SS_MAX_SERVICE + 1] ;
unsigned int list[SS_MAX_SERVICE + 1], visit[SS_MAX_SERVICE + 1] ;
struct resolve_hash_s *hash = NULL ;
memset(list, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
memset(visit, 0, (SS_MAX_SERVICE + 1) * sizeof(unsigned int)) ;
memset(ares, 0, (SS_MAX_SERVICE + 1) * sizeof(resolve_service_t)) ;
uint32_t gflag = STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_WANTUP ;
if (!propagate)
......@@ -56,18 +55,18 @@ int svc_compute_ns(resolve_service_t *sares, unsigned int sareslen, unsigned int
FLAGS_CLEAR(gflag, STATE_FLAGS_WANTUP) ;
}
if (sares[saresid].dependencies.ncontents) {
if (res->dependencies.ncontents) {
if (!stack_clean_string_g(&stk, res->sa.s + res->dependencies.contents))
log_dieu(LOG_EXIT_SYS, "clean string") ;
} else {
log_warn("empty ns: ", sares[saresid].sa.s + sares[saresid].name) ;
log_warn("empty ns: ", res->sa.s + res->name) ;
return 0 ;
}
/** build the graph of the ns */
service_graph_g(stk.s, stk.len, &graph, ares, &areslen, info, gflag) ;
service_graph_g(stk.s, stk.len, &graph, &hash, info, gflag) ;
if (!graph.mlen)
log_die(LOG_EXIT_USER, "services selection is not supervised -- initiate its first") ;
......@@ -76,28 +75,28 @@ int svc_compute_ns(resolve_service_t *sares, unsigned int sareslen, unsigned int
char const *name = stk.s + pos ;
int aresid = service_resolve_array_search(ares, areslen, name) ;
if (aresid < 0)
struct resolve_hash_s *h = hash_search(&hash, name) ;
if (h == NULL)
log_die(LOG_EXIT_USER, "service: ", name, " not available -- did you parse it?") ;
if (ares[aresid].earlier) {
log_warn("ignoring ealier service: ", ares[aresid].sa.s + ares[aresid].name) ;
if (h->res.earlier) {
log_warn("ignoring ealier service: ", h->res.sa.s + h->res.name) ;
continue ;
}
graph_compute_visit(ares, aresid, visit, list, &graph, &napid, requiredby) ;
graph_compute_visit(*h, visit, list, &graph, &napid, requiredby) ;
}
if (!what)
sanitize_init(list, napid, &graph, ares, areslen) ;
sanitize_init(list, napid, &graph, &hash) ;
pidservice_t apids[napid] ;
svc_init_array(list, napid, apids, &graph, ares, areslen, info, requiredby, gflag) ;
svc_init_array(list, napid, apids, &graph, &hash, 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, &hash, info, updown, opt_updown, reloadmsg, data, propagate) ;
hash_free(&hash) ;
graph_free_all(&graph) ;
service_resolve_array_free(ares, areslen) ;
return r ;
}
......@@ -42,7 +42,7 @@ static pidservice_t pidservice_init(unsigned int len)
return pids ;
}
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)
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)
{
log_flow() ;
......@@ -55,20 +55,20 @@ void svc_init_array(unsigned int *list, unsigned int listlen, pidservice_t *apid
char *name = g->data.s + genalloc_s(graph_hash_t,&g->hash)[list[pos]].vertex ;
pids.aresid = service_resolve_array_search(ares, areslen, name) ;
if (pids.aresid < 0)
log_dieu(LOG_EXIT_SYS,"find ares id of: ", name, " -- please make a bug reports") ;
struct resolve_hash_s *hash = hash_search(hres, name) ;
if (hash == NULL)
log_dieu(LOG_EXIT_SYS,"find hash id of: ", name, " -- please make a bug reports") ;
pids.res = &hash->res ;
if (FLAGS_ISSET(flag, STATE_FLAGS_TOPROPAGATE)) {
pids.nedge = graph_matrix_get_edge_g_sorted_list(pids.edge, g, name, requiredby, 1) ;
pids.nedge = graph_matrix_get_edge_g_sorted_list(pids.edge, g, name, requiredby, 0) ;
if (pids.nedge < 0)
log_dieu(LOG_EXIT_SYS,"get sorted ", requiredby ? "required by" : "dependency", " list of service: ", name) ;
pids.nnotif = graph_matrix_get_edge_g_sorted_list(pids.notif, g, name, !requiredby, 1) ;
pids.nnotif = graph_matrix_get_edge_g_sorted_list(pids.notif, g, name, !requiredby, 0) ;
if (pids.nnotif < 0)
log_dieu(LOG_EXIT_SYS,"get sorted ", !requiredby ? "required by" : "dependency", " list of service: ", name) ;
......@@ -79,11 +79,11 @@ void svc_init_array(unsigned int *list, unsigned int listlen, pidservice_t *apid
if (pids.vertex < 0)
log_dieu(LOG_EXIT_SYS, "get vertex id -- please make a bug report") ;
if (ares[pids.aresid].type != TYPE_CLASSIC) {
if (pids.res->type != TYPE_CLASSIC) {
ss_state_t sta = STATE_ZERO ;
if (!state_read(&sta, &ares[pids.aresid]))
if (!state_read(&sta, pids.res))
log_dieusys(LOG_EXIT_SYS, "read state file of: ", name) ;
if (sta.isup == STATE_FLAGS_TRUE)
......@@ -95,7 +95,7 @@ void svc_init_array(unsigned int *list, unsigned int listlen, pidservice_t *apid
s6_svstatus_t status ;
r = s6_svstatus_read(ares[pids.aresid].sa.s + ares[pids.aresid].live.scandir, &status) ;
r = s6_svstatus_read(pids.res->sa.s + pids.res->live.scandir, &status) ;
pid_t pid = !r ? 0 : status.pid ;
......@@ -109,4 +109,4 @@ void svc_init_array(unsigned int *list, unsigned int listlen, pidservice_t *apid
apids[pos] = pids ;
}
}
\ No newline at end of file
}
......@@ -43,8 +43,6 @@
static unsigned int napid = 0 ;
static unsigned int npid = 0 ;
static resolve_service_t_ref pares = 0 ;
static unsigned int pareslen = 0 ;
static char data[DATASIZE + 1] ;
static char updown[4] ;
static uint8_t opt_updown = 0 ;
......@@ -109,19 +107,6 @@ static inline void kill_all(pidservice_t *apids)
while (j--) kill(apids[j].pid, SIGKILL) ;
}
static int pidservice_get_id(pidservice_t *apids, unsigned int id)
{
log_flow() ;
unsigned int pos = 0 ;
for (; pos < napid ; pos++) {
if (apids[pos].vertex == id)
return (unsigned int) pos ;
}
return -1 ;
}
static int check_action(pidservice_t *apids, unsigned int pos, unsigned int receive, unsigned int what)
{
unsigned int p = char2enum[receive] ;
......@@ -161,16 +146,16 @@ static void notify(pidservice_t *apids, unsigned int pos, char const *sig, unsig
if (apids[pos].notif[i] == apids[idx].vertex && !FLAGS_ISSET(apids[idx].state, flag)) {
size_t nlen = uint_fmt(fmt, apids[pos].aresid) ;
size_t nlen = uint_fmt(fmt, pos) ;
fmt[nlen] = 0 ;
size_t len = nlen + 1 + 2 ;
char s[len + 1] ;
auto_strings(s, fmt, ":", sig, "@") ;
log_trace("sends notification ", sig, " to: ", pares[apids[idx].aresid].sa.s + pares[apids[idx].aresid].name, " from: ", pares[apids[pos].aresid].sa.s + pares[apids[pos].aresid].name) ;
log_trace("sends notification ", sig, " to: ", apids[idx].res->sa.s + apids[idx].res->name, " from: ", apids[pos].res->sa.s + apids[pos].res->name) ;
if (write(apids[idx].pipe[1], s, strlen(s)) < 0)
log_dieusys(LOG_EXIT_SYS, "send notif to: ", pares[apids[idx].aresid].sa.s + pares[apids[idx].aresid].name) ;
log_dieusys(LOG_EXIT_SYS, "send notif to: ", apids[idx].res->sa.s + apids[idx].res->name) ;
}
}
}
......@@ -186,8 +171,8 @@ static void announce(unsigned int pos, pidservice_t *apids, unsigned int what, u
int fd = 0 ;
char fmt[UINT_FMT] ;
char const *name = pares[apids[pos].aresid].sa.s + pares[apids[pos].aresid].name ;
char const *scandir = pares[apids[pos].aresid].sa.s + pares[apids[pos].aresid].live.scandir ;
char const *name = apids[pos].res->sa.s + apids[pos].res->name ;
char const *scandir = apids[pos].res->sa.s + apids[pos].res->live.scandir ;
size_t scandirlen = strlen(scandir) ;
char file[scandirlen + 6] ;
......@@ -197,7 +182,7 @@ static void announce(unsigned int pos, pidservice_t *apids, unsigned int what, u
if (success) {
if (pares[apids[pos].aresid].type == TYPE_CLASSIC) {
if (apids[pos].res->type == TYPE_CLASSIC) {
fd = open_trunc(file) ;
if (fd < 0)
......@@ -205,17 +190,17 @@ static void announce(unsigned int pos, pidservice_t *apids, unsigned int what, u
fd_close(fd) ;
}
notify(apids, pos, "F", what) ;
fmt[uint_fmt(fmt, exitcode)] = 0 ;
log_1_warn("Unable to ", reloadmsg == 1 ? "restart" : reloadmsg > 1 ? "reload" : what ? "stop" : "start", " service: ", name, " -- exited with signal: ", fmt) ;
log_1_warn("unable to ", reloadmsg == 1 ? "restart" : reloadmsg > 1 ? "reload" : what ? "stop" : "start", " service: ", name, " -- exited with signal: ", fmt) ;
notify(apids, pos, "F", what) ;
FLAGS_SET(apids[pos].state, SVC_FLAGS_BLOCK|SVC_FLAGS_FATAL) ;
} else {
if (!state_messenger(&pares[apids[pos].aresid], STATE_FLAGS_ISUP, \
if (!state_messenger(apids[pos].res, STATE_FLAGS_ISUP, \
data[1] == 'a' || \
data[1] == 'h' || \
data[1] == 'U' || \
......@@ -223,7 +208,7 @@ static void announce(unsigned int pos, pidservice_t *apids, unsigned int what, u
? STATE_FLAGS_TRUE : what ? STATE_FLAGS_FALSE : STATE_FLAGS_TRUE))
log_dieu(LOG_EXIT_SYS, "send message to state of: ", name) ;
if (!pares[apids[pos].aresid].execute.down && pares[apids[pos].aresid].type == TYPE_CLASSIC) {
if (!apids[pos].res->execute.down && apids[pos].res->type == TYPE_CLASSIC) {
if (!what) {
......@@ -242,12 +227,12 @@ static void announce(unsigned int pos, pidservice_t *apids, unsigned int what, u
}
}
log_info("Successfully ", reloadmsg == 1 ? "restarted" : reloadmsg > 1 ? "reloaded" : what ? "stopped" : "started", " service: ", name) ;
notify(apids, pos, what ? "D" : "U", what) ;
FLAGS_CLEAR(apids[pos].state, SVC_FLAGS_BLOCK) ;
FLAGS_SET(apids[pos].state, flag|SVC_FLAGS_UNBLOCK) ;
log_info("Successfully ", reloadmsg == 1 ? "restarted" : reloadmsg > 1 ? "reloaded" : what ? "stopped" : "started", " service: ", name) ;
}
}
......@@ -269,7 +254,7 @@ static int handle_signal(pidservice_t *apids, unsigned int what, graph_t *graph,
for (;;) {
unsigned int pos = 0 ;
int wstat ;
int wstat = 0 ;
pid_t r = wait_nohang(&wstat) ;
if (r < 0) {
......@@ -290,17 +275,16 @@ static int handle_signal(pidservice_t *apids, unsigned int what, graph_t *graph,
if (!WIFSIGNALED(wstat) && !WEXITSTATUS(wstat)) {
announce(pos, apids, what, 0, 0) ;
npid-- ;
} else {
ok = WIFSIGNALED(wstat) ? WTERMSIG(wstat) : WEXITSTATUS(wstat) ;
announce(pos, apids, what, 1, ok) ;
npid-- ;
kill_all(apids) ;
break ;
}
npid-- ;
}
}
break ;
......@@ -318,23 +302,23 @@ static int handle_signal(pidservice_t *apids, unsigned int what, graph_t *graph,
return ok ;
}
unsigned int compute_timeout(unsigned int idx, unsigned int what)
unsigned int compute_timeout(resolve_service_t *res, unsigned int what)
{
unsigned int timeout = 0 ;
if (!what) {
if (pares[idx].type == TYPE_ONESHOT && pares[idx].execute.timeout.up)
timeout = pares[idx].execute.timeout.up ;
else if (pares[idx].type == TYPE_CLASSIC && pares[idx].execute.timeout.kill)
timeout = pares[idx].execute.timeout.kill ;
if (res->type == TYPE_ONESHOT && res->execute.timeout.up)
timeout = res->execute.timeout.up ;
else if (res->type == TYPE_CLASSIC && res->execute.timeout.kill)
timeout = res->execute.timeout.kill ;
} else {
if (pares[idx].type == TYPE_ONESHOT && pares[idx].execute.timeout.down)
timeout = pares[idx].execute.timeout.down ;
else if (pares[idx].type == TYPE_CLASSIC && pares[idx].execute.timeout.finish)
timeout = pares[idx].execute.timeout.finish ;
if (res->type == TYPE_ONESHOT && res->execute.timeout.down)
timeout = res->execute.timeout.down ;
else if (res->type == TYPE_CLASSIC && res->execute.timeout.finish)
timeout = res->execute.timeout.finish ;
}
if (!timeout && PINFO->opt_timeout)
......@@ -348,8 +332,7 @@ static int doit(pidservice_t *apids, unsigned int napid, unsigned int idx, unsig
{
log_flow() ;
unsigned int pidx = apids[idx].aresid ;
uint8_t type = pares[pidx].type ;
uint8_t type = apids[idx].res->type ;
pid_t pid ;
int wstat ;
......@@ -358,17 +341,17 @@ static int doit(pidservice_t *apids, unsigned int napid, unsigned int idx, unsig
unsigned int timeout = 0 ;
timeout = compute_timeout(pidx, what) ;
timeout = compute_timeout(apids[idx].res, what) ;
tfmt[uint_fmt(tfmt, timeout)] = 0 ;
if (type == TYPE_CLASSIC) {
char *scandir = pares[pidx].sa.s + pares[pidx].live.scandir ;
char *scandir = apids[idx].res->sa.s + apids[idx].res->live.scandir ;
if (updown[2] == 'U' || updown[2] == 'D' || updown[2] == 'R') {
if (!pares[pidx].notify)
if (!apids[idx].res->notify)
updown[2] = updown[2] == 'U' ? 'u' : updown[2] == 'D' ? 'd' : updown[2] == 'R' ? 'r' : updown[2] ;
}
......@@ -402,17 +385,9 @@ static int doit(pidservice_t *apids, unsigned int napid, unsigned int idx, unsig
} else if (type == TYPE_ONESHOT) {
char *sa = pares[pidx].sa.s ;
char *name = sa + pares[pidx].name ;
size_t namelen = strlen(name) ;
char *home = pares[pidx].sa.s + pares[pidx].path.home ;
size_t homelen = strlen(home) ;
char script[homelen + SS_SYSTEM_LEN + SS_SERVICE_LEN + SS_SVC_LEN + 1 + namelen + 7 + 1] ;
auto_strings(script, home, SS_SYSTEM, SS_SERVICE, SS_SVC, "/", name) ;
char *oneshotdir = pares[pidx].sa.s + pares[pidx].live.oneshotddir ;
char *scandir = pares[pidx].sa.s + pares[pidx].live.scandir ;
char *servicedir = apids[idx].res->sa.s + apids[idx].res->live.servicedir ;
char *oneshotdir = apids[idx].res->sa.s + apids[idx].res->live.oneshotddir ;
char *scandir = apids[idx].res->sa.s + apids[idx].res->live.scandir ;
char oneshot[strlen(oneshotdir) + 2 + 1] ;
auto_strings(oneshot, oneshotdir, "/s") ;
......@@ -427,7 +402,7 @@ static int doit(pidservice_t *apids, unsigned int napid, unsigned int idx, unsig
newargv[m++] = "--" ;
newargv[m++] = oneshot ;
newargv[m++] = !what ? "up" : "down" ;
newargv[m++] = script ;
newargv[m++] = servicedir ;
newargv[m++] = 0 ;
log_trace("sending ", !what ? "up" : "down", " to: ", scandir) ;
......@@ -457,7 +432,7 @@ static int doit(pidservice_t *apids, unsigned int napid, unsigned int idx, unsig
newargv[m++] = "--" ;
newargv[m++] = oneshot ;
newargv[m++] = "up" ;
newargv[m++] = script ;
newargv[m++] = servicedir ;
newargv[m++] = 0 ;
pid = child_spawn0(newargv[0], newargv, (char const *const *) environ) ;
......@@ -478,19 +453,19 @@ static int doit(pidservice_t *apids, unsigned int napid, unsigned int idx, unsig
} else if (type == TYPE_MODULE) {
return svc_compute_ns(pares, pareslen, pidx, what, PINFO, updown, opt_updown, reloadmsg, data, PROPAGATE, apids, napid) ;
return svc_compute_ns(apids[idx].res, what, PINFO, updown, opt_updown, reloadmsg, data, PROPAGATE, apids, napid) ;
}
/* should be never reached*/
return 0 ;
}
static int async_deps(pidservice_t *apids, unsigned int i, unsigned int what, ssexec_t *info, tain *deadline)
static int async_deps(struct resolve_hash_s **hres, pidservice_t *apids, unsigned int i, unsigned int what, ssexec_t *info, tain *deadline)
{
log_flow() ;
int r ;
unsigned int pos = 0, id = 0, ilog = 0, idx = 0 ;
unsigned int pos = 0, id = 0, idx = 0 ;
char buf[(UINT_FMT*2)*SS_MAX_SERVICE + 1] ;
tain dead ;
......@@ -504,7 +479,7 @@ static int async_deps(pidservice_t *apids, unsigned int i, unsigned int what, ss
memset(visit, 0, (n + 1) * sizeof(unsigned int));
log_trace("waiting dependencies for: ", pares[apids[i].aresid].sa.s + pares[apids[i].aresid].name) ;
log_trace("waiting dependencies for: ", apids[i].res->sa.s + apids[i].res->name) ;
while (pos < n) {
......@@ -515,7 +490,7 @@ static int async_deps(pidservice_t *apids, unsigned int i, unsigned int what, ss
if (!r) {
errno = ETIMEDOUT ;
log_dieusys(LOG_EXIT_SYS,"time out", pares[apids[i].aresid].sa.s + pares[apids[i].aresid].name) ;
log_dieusys(LOG_EXIT_SYS,"timed out", apids[i].res->sa.s + apids[i].res->name) ;
}
if (x.revents & IOPAUSE_READ) {
......@@ -547,11 +522,11 @@ static int async_deps(pidservice_t *apids, unsigned int i, unsigned int what, ss
/**
* the received string have the format:
* index_of_the_ares_array_of_the_service_dependency:signal_receive
* apids_array_id:signal_receive
*
* typically:
* - 10:D
* - 30:u
* - 8:u
* - ...
*
* Split it and check the signal receive.*/
......@@ -566,24 +541,18 @@ static int async_deps(pidservice_t *apids, unsigned int i, unsigned int what, ss
if (!uint0_scan(line, &id))
log_dieusys(LOG_EXIT_SYS, "retrieve service number -- please make a bug report") ;
ilog = id ;
log_trace(pares[apids[i].aresid].sa.s + pares[apids[i].aresid].name, " acknowledges: ", pc, " from: ", pares[ilog].sa.s + pares[ilog].name) ;
log_trace(apids[i].res->sa.s + apids[i].res->name, " acknowledges: ", pc, " from: ", apids[id].res->sa.s + apids[id].res->name) ;
if (!visit[pos]) {
id = pidservice_get_id(apids, id) ;
if (id < 0)
log_dieu(LOG_EXIT_SYS, "get apidservice id -- please make a bug report") ;
id = check_action(apids, id, c, what) ;
if (id < 0)
log_die(LOG_EXIT_SYS, "service dependency: ", pares[ilog].sa.s + pares[ilog].name, " of: ", pares[apids[i].aresid].sa.s + pares[apids[i].aresid].name," crashed") ;
log_die(LOG_EXIT_SYS, "service dependency: ", apids[id].res->sa.s + apids[id].res->name, " of: ", apids[i].res->sa.s + apids[i].res->name," crashed") ;
if (!id)
continue ;
visit[pos++]++ ;
visit[pos++] ;
}
}
}
......@@ -594,7 +563,7 @@ static int async_deps(pidservice_t *apids, unsigned int i, unsigned int what, ss
return 1 ;
}
static int async(pidservice_t *apids, unsigned int napid, unsigned int i, unsigned int what, ssexec_t *info, graph_t *graph, tain *deadline)
static int async(struct resolve_hash_s **hres, pidservice_t *apids, unsigned int napid, unsigned int i, unsigned int what, ssexec_t *info, graph_t *graph, tain *deadline)
{
log_flow() ;
......@@ -611,17 +580,15 @@ static int async(pidservice_t *apids, unsigned int napid, unsigned int i, unsign
FLAGS_SET(apids[i].state, SVC_FLAGS_BLOCK) ;
if (apids[i].nedge)
if (!async_deps(apids, i, what, info, deadline))
log_warnu_return(LOG_EXIT_ZERO, !what ? "start" : "stop", " dependencies of service: ", name) ;
if (!async_deps(hres, apids, i, what, info, deadline))
log_warnu_return(LOG_EXIT_SYS, !what ? "start" : "stop", " dependencies of service: ", name) ;
e = doit(apids, napid, i, what, deadline) ;
} else {
log_warn("skipping service: ", name, " -- already in ", what ? "stopping" : "starting", " process") ;
notify(apids, i, what ? "d" : "u", what) ;
}
} else {
......@@ -634,7 +601,7 @@ static int async(pidservice_t *apids, unsigned int napid, unsigned int i, unsign
return e ;
}
int svc_launch(pidservice_t *apids, unsigned int len, 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)
int svc_launch(pidservice_t *apids, unsigned int len, 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)
{
log_flow() ;
......@@ -653,8 +620,6 @@ int svc_launch(pidservice_t *apids, unsigned int len, uint8_t what, graph_t *gra
opt_updown = rise_opt ;
reloadmsg = msg ;
auto_strings(data, signal) ;
pares = ares ;
pareslen = areslen ;
if (info->opt_timeout)
tain_from_millisecs(&deadline, info->timeout) ;
......@@ -700,7 +665,7 @@ int svc_launch(pidservice_t *apids, unsigned int len, uint8_t what, graph_t *gra
close(apidservice[pos].pipe[1]) ;
e = async(apidservice, napid, pos, what, info, graph, &deadline) ;
e = async(hres, apidservice, napid, pos, what, info, graph, &deadline) ;
goto end ;
}
......@@ -734,11 +699,11 @@ int svc_launch(pidservice_t *apids, unsigned int len, uint8_t what, graph_t *gra
selfpipe_finish() ;
end:
for (pos = 0 ; pos < napid ; pos++) {
close(apidservice[pos].pipe[1]) ;
close(apidservice[pos].pipe[0]) ;
}
for (pos = 0 ; pos < napid ; pos++) {
close(apidservice[pos].pipe[1]) ;
close(apidservice[pos].pipe[0]) ;
}
end:
return e ;
}
......@@ -50,13 +50,12 @@ static void sanitize_it(resolve_service_t *res)
}
/** this function considers that the service is already down except for the logger */
void svc_unsupervise(unsigned int *alist, unsigned int alen, graph_t *g, resolve_service_t *ares, unsigned int areslen, ssexec_t *info)
void svc_unsupervise(unsigned int *alist, unsigned int alen, graph_t *g, struct resolve_hash_s **hres, ssexec_t *info)
{
log_flow() ;
unsigned int pos = 0 ;
size_t bpos = 0 ;
stralloc sa = STRALLOC_ZERO ;
if (!alen)
return ;
......@@ -65,15 +64,15 @@ void svc_unsupervise(unsigned int *alist, unsigned int alen, graph_t *g, resolve
char *name = g->data.s + genalloc_s(graph_hash_t,&g->hash)[alist[pos]].vertex ;
int aresid = service_resolve_array_search(ares, areslen, name) ;
if (aresid < 0)
log_dieu(LOG_EXIT_SYS,"find ares id of: ", name, " -- please make a bug reports") ;
struct resolve_hash_s *hash = hash_search(hres, name) ;
if (hash == NULL)
log_dieu(LOG_EXIT_SYS,"find hash id of: ", name, " -- please make a bug reports") ;
sanitize_it(&ares[aresid]) ;
sanitize_it(&hash->res) ;
if (ares[aresid].type == TYPE_MODULE && ares[aresid].dependencies.ncontents) {
if (hash->res.type == TYPE_MODULE && hash->res.dependencies.ncontents) {
sa.len = 0, bpos = 0 ;
bpos = 0 ;
_init_stack_(stk, strlen(hash->res.sa.s + hash->res.dependencies.contents)) ;
......@@ -82,14 +81,13 @@ void svc_unsupervise(unsigned int *alist, unsigned int alen, graph_t *g, resolve
FOREACH_STK(&stk, bpos) {
int aresid = service_resolve_array_search(ares, areslen, sa.s + bpos) ;
if (aresid < 0)
log_dieu(LOG_EXIT_SYS,"find ares id of: ", sa.s + bpos, " -- please make a bug reports") ;
struct resolve_hash_s *h = hash_search(hres, stk.s + bpos) ;
if (h == NULL)
log_dieu(LOG_EXIT_SYS,"find hash id of: ", stk.s + bpos, " -- please make a bug reports") ;
sanitize_it(&ares[aresid]) ;
sanitize_it(&h->res) ;
}
}
}
stralloc_free(&sa) ;
}
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