OpenVAS Scanner 23.32.3
pluginlaunch.h File Reference

pluginlaunch.c header. More...

#include "pluginload.h"
#include "pluginscheduler.h"
Include dependency graph for pluginlaunch.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ERR_CANT_FORK   -2
 Error for when it is not possible to fork a new plugin process.
#define ERR_NO_FREE_SLOT   -99
 Error for when the process table is full.

Functions

void pluginlaunch_init (const char *)
void pluginlaunch_wait (kb_t, kb_t)
 Waits and 'pushes' processes until num_running_processes is 0.
void pluginlaunch_wait_for_free_process (kb_t, kb_t)
 Waits and 'pushes' processes until the number of running processes has changed.
void pluginlaunch_stop (void)
int plugin_launch (struct scan_globals *, struct scheduler_plugin *, struct in6_addr *, GSList *, kb_t, kb_t, nvti_t *, int *)
 Start a plugin.
void pluginlaunch_disable_parallel_checks (void)
void pluginlaunch_enable_parallel_checks (void)
int wait_for_children (void)

Detailed Description

pluginlaunch.c header.

Definition in file pluginlaunch.h.

Macro Definition Documentation

◆ ERR_CANT_FORK

#define ERR_CANT_FORK   -2

Error for when it is not possible to fork a new plugin process.

Definition at line 22 of file pluginlaunch.h.

Referenced by attack_host(), launch_plugin(), and plugin_launch().

◆ ERR_NO_FREE_SLOT

#define ERR_NO_FREE_SLOT   -99

Error for when the process table is full.

Definition at line 26 of file pluginlaunch.h.

Referenced by attack_host(), launch_plugin(), next_free_process(), and plugin_launch().

Function Documentation

◆ plugin_launch()

int plugin_launch ( struct scan_globals * globals,
struct scheduler_plugin * plugin,
struct in6_addr * ip,
GSList * vhosts,
kb_t kb,
kb_t main_kb,
nvti_t * nvti,
int * error )

Start a plugin.

Check for free slots available in the process table. Set error with ERR_NO_FREE_SLOT if the process table is full. Set error with ERR_CANT_FORK if was not possible to fork() a new child.

Returns
PID of process that is connected to the plugin as returned by plugin classes pl_launch function. Less than 0 means there was a problem, but error param should be checked.

Definition at line 480 of file pluginlaunch.c.

483{
484 int p;
485
486 /* Wait for a free slot */
488 p = next_free_process (main_kb, kb, plugin);
489 if (p < 0)
490 {
491 g_warning ("%s. There is currently no free slot available for starting a "
492 "new plugin.",
493 __func__);
494 *error = ERR_NO_FREE_SLOT;
495 return -1;
496 }
497
498 processes[p].plugin = plugin;
499 processes[p].timeout = plugin_timeout (nvti);
500 gettimeofday (&(processes[p].start), NULL);
501 processes[p].pid = nasl_plugin_launch (globals, ip, vhosts, kb, plugin->oid);
502
503 if (processes[p].pid > 0)
505 else
506 {
507 processes[p].plugin->running_state = PLUGIN_STATUS_UNRUN;
508 *error = ERR_CANT_FORK;
509 }
510 return processes[p].pid;
511}
kb_t main_kb
Definition kb_cache.c:15
static pid_t pid
int nasl_plugin_launch(struct scan_globals *globals, struct in6_addr *ip, GSList *vhosts, kb_t kb, const char *oid)
Launch a NASL plugin.
static struct running processes[MAX_PROCESSES]
void pluginlaunch_wait_for_free_process(kb_t main_kb, kb_t kb)
Waits and 'pushes' processes until the number of running processes has changed.
static int num_running_processes
static int next_free_process(kb_t main_kb, kb_t kb, struct scheduler_plugin *upcoming)
static int plugin_timeout(nvti_t *nvti)
#define ERR_CANT_FORK
Error for when it is not possible to fork a new plugin process.
#define ERR_NO_FREE_SLOT
Error for when the process table is full.
@ PLUGIN_STATUS_UNRUN

References ERR_CANT_FORK, ERR_NO_FREE_SLOT, main_kb, nasl_plugin_launch(), next_free_process(), num_running_processes, scheduler_plugin::oid, pid, PLUGIN_STATUS_UNRUN, plugin_timeout(), pluginlaunch_wait_for_free_process(), and processes.

Referenced by launch_plugin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pluginlaunch_disable_parallel_checks()

void pluginlaunch_disable_parallel_checks ( void )

Definition at line 351 of file pluginlaunch.c.

352{
354}
static int max_running_processes

References max_running_processes.

Referenced by get_next_in_range().

Here is the caller graph for this function:

◆ pluginlaunch_enable_parallel_checks()

void pluginlaunch_enable_parallel_checks ( void )

Definition at line 357 of file pluginlaunch.c.

358{
360}
static int old_max_running_processes

References max_running_processes, and old_max_running_processes.

Referenced by get_next_in_range().

Here is the caller graph for this function:

◆ pluginlaunch_init()

void pluginlaunch_init ( const char * host)

Definition at line 324 of file pluginlaunch.c.

325{
326 int i;
327
328 char **split = g_strsplit (prefs_get ("non_simult_ports"), ", ", 0);
329 for (i = 0; split[i]; i++)
330 non_simult_ports = g_slist_prepend (non_simult_ports, g_strdup (split[i]));
331 g_strfreev (split);
334 hostname = host;
335
337 {
338 g_debug ("max_checks (%d) > MAX_PROCESSES (%d) - modify "
339 "openvas/openvas/pluginlaunch.c",
342 }
343
345 bzero (&(processes), sizeof (processes));
346
347 init_kb_usage ();
348}
#define MAX_PROCESSES
'Hard' limit of the max. number of concurrent plugins per host.
static GSList * non_simult_ports
const char * hostname
void init_kb_usage(void)
Definition plugutils.c:47
Host information, implemented as doubly linked list.
Definition hosts.c:37
int get_max_checks_number(void)
Definition utils.c:168

References get_max_checks_number(), hostname, init_kb_usage(), MAX_PROCESSES, max_running_processes, non_simult_ports, num_running_processes, old_max_running_processes, and processes.

Referenced by attack_host().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pluginlaunch_stop()

void pluginlaunch_stop ( void )

Definition at line 363 of file pluginlaunch.c.

364{
365 int i;
366
367 for (i = 0; i < MAX_PROCESSES; i++)
368 {
369 if (processes[i].pid > 0)
370 {
371 /* Since the plugin process is a group leader process
372 * we can send the signal to -PID process to kill
373 * also the plugin's child processes. */
376 processes[i].plugin->running_state = PLUGIN_STATUS_DONE;
377 bzero (&(processes[i]), sizeof (struct running));
378 }
379 }
380}
@ PLUGIN_STATUS_DONE
int terminate_process(pid_t pid)
Terminates a given process. If termination does not work, the process will get killed....
Definition processes.c:96
Structure to represent a process in the sense of a running NVT.

References MAX_PROCESSES, num_running_processes, pid, PLUGIN_STATUS_DONE, processes, and terminate_process().

Referenced by attack_host(), launch_plugin(), pluginlaunch_wait_for_free_process(), and scan_stop_cleanup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pluginlaunch_wait()

void pluginlaunch_wait ( kb_t main_kb,
kb_t kb )

Waits and 'pushes' processes until num_running_processes is 0.

Definition at line 517 of file pluginlaunch.c.

518{
520 {
523 waitpid (-1, NULL, 0);
524 }
525}
static void update_running_processes(kb_t main_kb, kb_t kb)

References main_kb, num_running_processes, and update_running_processes().

Referenced by attack_host().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pluginlaunch_wait_for_free_process()

void pluginlaunch_wait_for_free_process ( kb_t main_kb,
kb_t kb )

Waits and 'pushes' processes until the number of running processes has changed.

Definition at line 550 of file pluginlaunch.c.

551{
553 return;
555 /* Max number of processes are still running, wait for a child to exit or
556 * to timeout. */
557
559 g_debug ("%s. Number of running processes >= maximum running processes (%d "
560 ">= %d). "
561 "Waiting for free slot for processes.",
563
564 /* Be careful with changing the max_running_process value.
565 * The plugin scheduler can change this value for running one plugin at
566 * time. */
567 while (
569 || (num_running_processes > 0 && (check_memory () || check_sysload ())))
570 {
571 sigset_t mask;
572 struct timespec ts = {0, 0};
573
574 ts.tv_sec = timeout_running_processes ();
575 assert (ts.tv_sec);
576 sigemptyset (&mask);
577 sigaddset (&mask, SIGCHLD);
578 sigaddset (&mask, SIGUSR1);
579 /* Wait here for the shortest plugins timeout or for a child which ended.
580 * Also, it handles signal SIGUSR1 to stop a scan. Otherwise the signa is
581 * ignored, the plugin is never stopped and the scanner keeps waiting. */
582 int sig = sigtimedwait (&mask, NULL, &ts);
583 if (sig < 0 && errno != EAGAIN)
584 g_warning ("%s: %s (%d)", __func__, strerror (errno), errno);
585 else if (sig == SIGUSR1)
586 {
587 /* SIGUSR1 signal is sent during scan stop to all host processes.
588 Therefore pluginlaunch_stop() is called here, for the
589 special case in which we are waiting for the last plugin, of the
590 last host, to finish.
591 */
593 }
594 // cleanup ipcc cache
597 }
598}
static int check_memory()
static int check_sysload()
void pluginlaunch_stop(void)
static int timeout_running_processes(void)
Return shortest timeout of the running processes.
int procs_cleanup_children(void)
iterates through ipcc and verify if a child is stopped or killed to free the file handler.
Definition processes.c:47

References check_memory(), check_sysload(), main_kb, max_running_processes, num_running_processes, pluginlaunch_stop(), procs_cleanup_children(), timeout_running_processes(), and update_running_processes().

Referenced by attack_host(), and plugin_launch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait_for_children()

int wait_for_children ( void )