43 |
/* Private Prototypes */ |
/* Private Prototypes */ |
44 |
static void do_stop(Process_T p); |
static void do_stop(Process_T p); |
45 |
static void do_start(Process_T p); |
static void do_start(Process_T p); |
46 |
static void do_restart_dependandt(Process_T p); |
static void do_dependandt(Process_T p, char *action); |
47 |
|
|
48 |
|
|
49 |
/** |
/** |
236 |
return; |
return; |
237 |
} |
} |
238 |
|
|
239 |
|
do_dependandt(p, "stop"); |
240 |
do_start(p); |
do_start(p); |
241 |
do_restart_dependandt(p); |
do_dependandt(p, "start"); |
242 |
|
|
243 |
} else if(is(action, "stop")) { |
} else if(is(action, "stop")) { |
244 |
|
|
359 |
|
|
360 |
|
|
361 |
/* |
/* |
362 |
* This is a pre-recursive function called after p was started and |
* This is a pre-recursive function called before p is started for |
363 |
* used to restart every process that depends on p, in reverse order. |
* stopping every process that depends on p, in reverse order and |
364 |
|
* after p was started to start every process that depends on p again. |
365 |
|
* The action parametere controls if this function should start or |
366 |
|
* stop the precceses that depend on p. |
367 |
* @param p A Process_T object |
* @param p A Process_T object |
368 |
|
* @param action An action to do on the dependant processes |
369 |
*/ |
*/ |
370 |
static void do_restart_dependandt(Process_T p) { |
static void do_dependandt(Process_T p, char *action) { |
371 |
|
|
372 |
Process_T parent; |
Process_T parent; |
373 |
int max_tries= Run.polltime; |
int max_tries= Run.polltime; |
380 |
|
|
381 |
Dependant_T d; |
Dependant_T d; |
382 |
|
|
383 |
for(d= parent->dependantlist; d; d= d->next ) |
for(d= parent->dependantlist; d; d= d->next) |
384 |
if(is(d->dependant, p->name)) |
if(is(d->dependant, p->name)) |
385 |
break; |
break; |
386 |
if(d && p->stop && p->start) { |
if(d && p->stop && p->start) { |
387 |
if(is_process_running(parent)) { |
|
388 |
log("stop: (%s) %s\n", parent->name, parent->stop->arg[0]); |
if(is(action, "stop")) { |
389 |
spawn(parent, parent->stop); |
if(is_process_running(parent)) { |
390 |
memset(parent->procinfo, 0, sizeof *(parent->procinfo)); |
log("stop: (%s) %s\n", parent->name, parent->stop->arg[0]); |
391 |
/* Wait until the process is actually stopped before atempting |
spawn(parent, parent->stop); |
392 |
* to restart it */ |
memset(parent->procinfo, 0, sizeof *(parent->procinfo)); |
393 |
while(max_tries--) { |
/* Wait until the process is actually stopped */ |
394 |
if(!is_process_running(parent)) |
while(max_tries--) { |
395 |
break; |
if(!is_process_running(parent)) |
396 |
sleep(1); |
break; |
397 |
|
sleep(1); |
398 |
|
} |
399 |
|
} |
400 |
|
} else if(is(action, "start")) { |
401 |
|
if(! is_process_running(parent)) { |
402 |
|
log("start: (%s) %s\n", parent->name, parent->start->arg[0]); |
403 |
|
spawn(parent, parent->start); |
404 |
} |
} |
405 |
} |
} |
406 |
if(! is_process_running(parent)) { |
do_dependandt(parent, action); |
|
log("start: (%s) %s\n", parent->name, parent->start->arg[0]); |
|
|
spawn(parent, parent->start); |
|
|
} |
|
|
do_restart_dependandt(parent); |
|
407 |
} |
} |
408 |
} |
} |
409 |
} |
} |