ipsec starter gives the charon daemon 8s to terminate gracefully before killing the process brutally

This commit is contained in:
Andreas Steffen
2008-08-01 10:35:59 +00:00
parent 181abd3fdd
commit 573fd9ce03
+21 -7
View File
@@ -63,38 +63,46 @@ starter_charon_sigchild(pid_t pid)
int int
starter_stop_charon (void) starter_stop_charon (void)
{ {
pid_t pid;
int i; int i;
pid_t pid = _charon_pid;
pid = _charon_pid;
if (pid) if (pid)
{ {
_stop_requested = 1; _stop_requested = 1;
/* be more and more aggressive */ /* be more and more aggressive */
for (i = 0; i < 20 && (pid = _charon_pid) != 0; i++) for (i = 0; i < 50 && (pid = _charon_pid) != 0; i++)
{ {
if (i == 0) if (i == 0)
{
kill(pid, SIGINT); kill(pid, SIGINT);
else if (i < 10) }
else if (i < 40)
{
kill(pid, SIGTERM); kill(pid, SIGTERM);
else if (i == 10) }
else if (i == 40)
{ {
kill(pid, SIGKILL); kill(pid, SIGKILL);
plog("starter_stop_charon(): charon does not respond, sending KILL"); plog("starter_stop_charon(): charon does not respond, sending KILL");
} }
else else
{
kill(pid, SIGKILL); kill(pid, SIGKILL);
usleep(200000); }
usleep(200000); /* sleep for 200 ms */
} }
if (_charon_pid == 0) if (_charon_pid == 0)
{
plog("charon stopped after %d ms", 200*i);
return 0; return 0;
}
plog("starter_stop_charon(): can't stop charon !!!"); plog("starter_stop_charon(): can't stop charon !!!");
return -1; return -1;
} }
else else
{ {
plog("stater_stop_charon(): charon is not started..."); plog("stater_stop_charon(): charon was not started...");
} }
return -1; return -1;
} }
@@ -194,11 +202,17 @@ starter_start_charon (starter_config_t *cfg, bool no_fork)
for (i = 0; i < 20 && (pid = _charon_pid) != 0; i++) for (i = 0; i < 20 && (pid = _charon_pid) != 0; i++)
{ {
if (i == 0) if (i == 0)
{
kill(pid, SIGINT); kill(pid, SIGINT);
}
else if (i < 10) else if (i < 10)
{
kill(pid, SIGTERM); kill(pid, SIGTERM);
}
else else
{
kill(pid, SIGKILL); kill(pid, SIGKILL);
}
usleep(20000); usleep(20000);
} }
} }