Commit 603eef5f authored by François Grisez's avatar François Grisez

Ensure that Flexisip and its monitor are realy started before detaching the watchdog

parent a4972599
......@@ -267,10 +267,6 @@ fork_flexisip:
if (err==-1 || err==0){
exit(-1);
}
if(write(pipe_fds[1], "ok", 3) == -1) {
exit(-1);
}
close(pipe_wd_fs[0]);
/*
* Flexisip has successfully started.
......@@ -278,6 +274,13 @@ fork_flexisip:
*/
fork_monitor:
if(startMonitor){
int pipe_wd_mo[2];
err = pipe(pipe_wd_mo);
if(err == -1){
LOGE("Cannot create pipe. %s", strerror(errno));
kill(flexisip_pid, SIGTERM);
exit(-1);
}
monitor_pid = fork();
if (monitor_pid < 0){
fprintf(stderr,"Could not fork: %s\n",strerror(errno));
......@@ -286,14 +289,30 @@ fork_monitor:
if (monitor_pid == 0) {
/* We are in the flexisip monitor process */
close(pipe_fds[1]);
Monitor::exec();
close(pipe_wd_mo[0]);
Monitor::exec(pipe_wd_mo[1]);
LOGE("Fail to launch the Flexisip monitor");
exit(-1);
}
/* We are in the watchdog process */
close(pipe_wd_mo[1]);
err = read(pipe_wd_mo[0], buf, sizeof(buf));
if(err == -1 || err == 0) {
kill(flexisip_pid, SIGTERM);
exit(-1);
}
close(pipe_wd_mo[0]);
}
/*
* We are in the watchdog process once again
*/
if(write(pipe_fds[1], "ok", 3) == -1) {
exit(-1);
}
close(pipe_wd_fs[0]);
/*
* This loop aims to restart childs of the watchdog process
* when they have a crash
*/
......
......@@ -40,15 +40,28 @@ Monitor::Init::Init() {
s->addChildrenValues(items);
}
void Monitor::exec() {
GenericStruct *monitorParams = GenericManager::get()->getRoot()->get<GenericStruct>("monitor");
GenericStruct *authParams = GenericManager::get()->getRoot()->get<GenericStruct>("module::Authentication");
void Monitor::exec(int socket) {
GenericStruct *monitorParams;
try{
monitorParams = GenericManager::get()->getRoot()->get<GenericStruct>("monitor");
}catch(FlexisipException &e) {
LOGE(e.str().c_str());
exit(-1);
}
string interval = monitorParams->get<ConfigValue>("test-interval")->get();
string logfile = monitorParams->get<ConfigString>("logfile")->read();
string port = monitorParams->get<ConfigValue>("switch-port")->get();
GenericStruct *authParams;
try{
authParams = GenericManager::get()->getRoot()->get<GenericStruct>("module::Authentication");
}catch(FlexisipException &e){
LOGE(e.str().c_str());
exit(-1);
}
list<string> identities = monitorParams->get<ConfigStringList>("identities")->read();
list<string> trustedHosts = authParams->get<ConfigStringList>("trusted-hosts")->read();
if(identities.size() != trustedHosts.size()) {
LOGE("Flexisip monitor: there is not as many SIP indentities as trusted-hosts");
exit(-1);
......@@ -80,5 +93,11 @@ void Monitor::exec() {
i++;
}
args[i] = NULL;
if(write(socket, "ok", 3) == -1) {
exit(-1);
}
close(socket);
execvp(args[0], args);
}
......@@ -23,7 +23,7 @@
class Monitor {
public:
static void exec();
static void exec(int socket);
private:
class Init {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment