Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for zombie process in case of timed out nvts (openvas-6). #378

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/pluginlaunch.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ update_running_processes (kb_t kb)
if (processes[i].pid > 0)
{
int is_alive = process_alive (processes[i].pid);
int ret_terminate = 0;

// If process dead or timed out
if (!is_alive
Expand All @@ -116,6 +117,15 @@ update_running_processes (kb_t kb)
"NVT timed out after %d seconds.",
oid ?: " ", processes[i].timeout);
kb_item_push_str (kb, "internal/results", msg);

ret_terminate = terminate_process (processes[i].pid);
if (ret_terminate == 0)
{
terminate_process (processes[i].pid * -1);
num_running_processes--;
processes[i].plugin->running_state = PLUGIN_STATUS_DONE;
bzero (&(processes[i]), sizeof (processes[i]));
}
}
else
{
Expand Down Expand Up @@ -143,11 +153,12 @@ update_running_processes (kb_t kb)
e = waitpid (processes[i].pid, NULL, 0);
}
while (e < 0 && errno == EINTR);

terminate_process (processes[i].pid * -1);
num_running_processes--;
processes[i].plugin->running_state = PLUGIN_STATUS_DONE;
bzero (&(processes[i]), sizeof (processes[i]));
}
terminate_process (processes[i].pid * -1);
num_running_processes--;
processes[i].plugin->running_state = PLUGIN_STATUS_DONE;
bzero (&(processes[i]), sizeof (processes[i]));
}
}
}
Expand Down
19 changes: 17 additions & 2 deletions src/processes.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@
*/
#define G_LOG_DOMAIN "sd main"

/**
* @brief Send SIGTERM to the pid process. Try to wait the
* the process. In case of the process has still not change
the state, it sends SIGKILL to the process and must be waited
later to avoid leaving a zombie process

@param[in] pid Process id to terminate.

@return 0 on success, -1 if the process was waited but not changed
the state
*/
int
terminate_process (pid_t pid)
{
Expand All @@ -57,9 +68,13 @@ terminate_process (pid_t pid)
{
usleep (1000);
if (waitpid (pid, NULL, WNOHANG) >= 0)
kill (pid, SIGKILL);
{
kill (pid, SIGKILL);
return -1;
}
}
return -1;

return 0;
}

static void
Expand Down