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

respect timeout given by the frontend file.

remove svc_send.c file
parent 4fd01223
No related branches found
No related tags found
No related merge requests found
......@@ -251,7 +251,7 @@ int ssexec_signal(int argc, char const *const *argv, ssexec_t *info)
pidservice_init_array(list, napid, apids, &graph, ares, areslen, info, requiredby, gflag) ;
r = svc_launch(apids, napid, what, &graph, ares, info->timeout ? info->timeout : 0, info, updown, opt_updown, reloadmsg, data, propagate) ;
r = svc_launch(apids, napid, what, &graph, ares, info, updown, opt_updown, reloadmsg, data, propagate) ;
graph_free_all(&graph) ;
......
......@@ -2,7 +2,6 @@ svc_compute_ns.o
svc_launch.o
svc_scandir_ok.o
svc_scandir_send.o
svc_send.o
svc_send_fdholder.o
svc_send_wait.o
svc_unsupervise.o
......
......@@ -116,7 +116,7 @@ static void pidservice_init_array(unsigned int *list, unsigned int listlen, pids
}
int svc_compute_ns(resolve_service_t *res, uint8_t what, uint8_t timeout, ssexec_t *info, char const *updown, uint8_t opt_updown, uint8_t reloadmsg,char const *data, uint8_t propagate)
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)
{
log_flow() ;
......@@ -178,7 +178,7 @@ int svc_compute_ns(resolve_service_t *res, uint8_t what, uint8_t timeout, ssexec
pidservice_init_array(list, napid, apids, &graph, ares, areslen, info, requiredby, gflag) ;
r = svc_launch(apids, napid, what, &graph, ares, info->timeout ? info->timeout : 0, info, updown, opt_updown, reloadmsg, data, propagate) ;
r = svc_launch(apids, napid, what, &graph, ares, info, updown, opt_updown, reloadmsg, data, propagate) ;
graph_free_all(&graph) ;
......
......@@ -417,20 +417,30 @@ static int handle_signal(pidservice_t *apids, unsigned int what, graph_t *graph,
return ok ;
}
/** this following function come from:
* https://git.skarnet.org/cgi-bin/cgit.cgi/s6-rc/tree/src/s6-rc/s6-rc.c#n111
* under license ISC where parameters was modified */
static uint32_t compute_timeout (uint32_t timeout, tain *deadline)
unsigned int compute_timeout(unsigned int idx, unsigned int what)
{
uint32_t t = timeout ;
int globalt ;
tain globaltto ;
tain_sub(&globaltto, deadline, &STAMP) ;
globalt = tain_to_millisecs(&globaltto) ;
if (!globalt) globalt = 1 ;
if (globalt > 0 && (!t || (unsigned int)globalt < t))
t = (uint32_t)globalt ;
return t ;
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 ;
} 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 (!timeout && PINFO->opt_timeout)
timeout = PINFO->timeout ;
return timeout ;
}
static int doit(pidservice_t *sv, unsigned int what, tain *deadline)
......@@ -445,10 +455,8 @@ static int doit(pidservice_t *sv, unsigned int what, tain *deadline)
char tfmt[UINT32_FMT] ;
unsigned int timeout = 0 ;
if (!what)
timeout = compute_timeout(type == TYPE_ONESHOT ? pares[sv->aresid].execute.timeout.up : pares[sv->aresid].execute.timeout.kill, deadline) ;
else
timeout = compute_timeout(type == TYPE_ONESHOT ? pares[sv->aresid].execute.timeout.down : pares[sv->aresid].execute.timeout.finish, deadline) ;
timeout = compute_timeout(sv->aresid, what) ;
tfmt[uint_fmt(tfmt, timeout)] = 0 ;
......@@ -534,7 +542,7 @@ static int doit(pidservice_t *sv, unsigned int what, tain *deadline)
} else if (type == TYPE_BUNDLE || type == TYPE_MODULE) {
return svc_compute_ns(&pares[sv->aresid], what, timeout, PINFO, updown, opt_updown, reloadmsg, data, PROPAGATE) ; ;
return svc_compute_ns(&pares[sv->aresid], what, PINFO, updown, opt_updown, reloadmsg, data, PROPAGATE) ; ;
}
// never happen, let compiler to be happy
return 0 ;
......@@ -580,7 +588,7 @@ static int async(pidservice_t *apids, unsigned int i, unsigned int what, ssexec_
return e ;
}
int svc_launch(pidservice_t *apids, unsigned int len, uint8_t what, graph_t *graph, resolve_service_t *ares, uint8_t timeout, 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, resolve_service_t *ares, ssexec_t *info, char const *rise, uint8_t rise_opt, uint8_t msg, char const *signal, uint8_t propagate)
{
log_flow() ;
......@@ -601,14 +609,11 @@ int svc_launch(pidservice_t *apids, unsigned int len, uint8_t what, graph_t *gra
auto_strings(data, signal) ;
pares = ares ;
if (timeout)
tain_from_millisecs(&deadline, timeout) ;
if (info->opt_timeout)
tain_from_millisecs(&deadline, info->timeout) ;
else
deadline = tain_infinite_relative ;
tain_now_set_stopwatch_g() ;
tain_add_g(&deadline, &deadline) ;
int spfd = selfpipe_init() ;
if (spfd < 0)
......@@ -632,6 +637,9 @@ int svc_launch(pidservice_t *apids, unsigned int len, uint8_t what, graph_t *gra
}
tain_now_set_stopwatch_g() ;
tain_add_g(&deadline, &deadline) ;
for (pos = 0 ; pos < napid ; pos++) {
pid = fork() ;
......
/*
* svc_send.c
*
* Copyright (c) 2018-2021 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 <oblibs/log.h>
#include <66/svc.h>
#include <66/resolve.h>
#include <66/ssexec.h>
int svc_send(char const *const *list, unsigned int nservice, char **sig, unsigned int siglen, ssexec_t *info)
{
log_flow() ;
int nargc = 2 + nservice + siglen ;
char const *newargv[nargc] ;
unsigned int m = 0 ;
newargv[m++] = "signal" ;
for (; *sig ; sig++)
newargv[m++] = *sig ;
for (; *list ; list++)
newargv[m++] = *list ;
newargv[m++] = 0 ;
return ssexec_signal(nargc, newargv, info) ;
}
......@@ -28,15 +28,27 @@ int svc_send_wait(char const *const *list, unsigned int nservice, char **sig, un
pid_t pid ;
int wstat ;
int nargc = 5 + nservice + siglen + info->opt_color ;
int nargc = 5 + nservice + siglen + info->opt_color + (info->opt_timeout ? 2 : 0) ;
char const *newargv[nargc] ;
unsigned int m = 0 ;
char verbo[UINT_FMT] ;
char fmt[UINT32_FMT] ;
verbo[uint_fmt(verbo, VERBOSITY)] = 0 ;
if (info->opt_timeout)
fmt[uint32_fmt(fmt,info->timeout)] = 0 ;
newargv[m++] = "66" ;
if (info->opt_color)
newargv[m++] = "-z" ;
if (info->timeout) {
newargv[m++] = "-T" ;
newargv[m++] = fmt ;
}
newargv[m++] = "-v" ;
newargv[m++] = verbo ;
newargv[m++] = "signal" ;
......
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