Fixed process kill waitpid cleanup issues.

This commit is contained in:
ravinsp
2020-09-07 14:34:07 +05:30
parent 4ad8c59051
commit f121fa90fb
5 changed files with 19 additions and 9 deletions

View File

@@ -52,6 +52,8 @@ namespace comm
{
close(read_fd);
close(write_fd);
util::kill_process(pid, false);
return -1;
}

View File

@@ -312,8 +312,9 @@ namespace comm
close(firewall_pipe[0]);
// Wait for some time and check if websocketd is still running properly.
// Sending signal 0 to test whether process exist.
util::sleep(20);
if (kill(pid, 0) == -1)
if (util::kill_process(pid, false, 0) == -1)
return -1;
websocketd_pid = pid;

View File

@@ -40,9 +40,11 @@ namespace hpfs
if (pid > 0)
{
// HotPocket process.
// Check if process is still running.
util::sleep(20);
if (kill(pid, 0) == -1)
util::sleep(INIT_CHECK_INTERVAL);
// Check if hpfs process is still running.
// Sending signal 0 to test whether process exist.
if (util::kill_process(pid, false, 0) == -1)
return -1;
merge_pid = pid;
@@ -102,8 +104,9 @@ namespace hpfs
{
util::sleep(INIT_CHECK_INTERVAL);
// Check if process is still running.
if (kill(pid, 0) == -1)
// Check if hpfs process is still running.
// Sending signal 0 to test whether process exist.
if (util::kill_process(pid, false, 0) == -1)
{
LOG_ERR << "hpfs process " << pid << " has stopped.";
break;

View File

@@ -40,7 +40,11 @@ namespace sc
// Write the inputs into the contract process.
if (feed_inputs(ctx) != 0)
{
util::kill_process(pid, true);
ctx.contract_pid = 0;
goto failure;
}
// Wait for child process (contract process) to complete execution.
const int presult = await_process_execution(ctx.contract_pid);

View File

@@ -215,7 +215,7 @@ namespace util
pthread_sigmask(SIG_SETMASK, &mask, NULL);
}
// Kill a process with a signal and wait until it stops running.
// Kill a process with a signal and if specified, wait until it stops running.
int kill_process(const pid_t pid, const bool wait, const int signal)
{
if (kill(pid, signal) == -1)
@@ -224,8 +224,8 @@ namespace util
return -1;
}
int pid_status;
if (wait && waitpid(pid, &pid_status, 0) == -1)
const int wait_options = wait ? 0 : WNOHANG;
if (waitpid(pid, NULL, wait_options) == -1)
{
LOG_ERR << errno << ": waitpid after kill failed.";
return -1;