OpenVAS Scanner 22.7.9
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.

◆ 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.

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 458 of file pluginlaunch.c.

461{
462 int p;
463
464 /* Wait for a free slot */
466 p = next_free_process (main_kb, kb, plugin);
467 if (p < 0)
468 {
469 g_warning ("%s. There is currently no free slot available for starting a "
470 "new plugin.",
471 __func__);
472 *error = ERR_NO_FREE_SLOT;
473 return -1;
474 }
475
476 processes[p].plugin = plugin;
477 processes[p].timeout = plugin_timeout (nvti);
478 gettimeofday (&(processes[p].start), NULL);
479 processes[p].pid = nasl_plugin_launch (globals, ip, vhosts, kb, plugin->oid);
480
481 if (processes[p].pid > 0)
483 else
484 {
486 *error = ERR_CANT_FORK;
487 }
488 return processes[p].pid;
489}
kb_t main_kb
Definition: kb_cache.c:15
static pid_t pid
Definition: nasl_cmd_exec.c:39
int nasl_plugin_launch(struct scan_globals *globals, struct in6_addr *ip, GSList *vhosts, kb_t kb, const char *oid)
Launch a NASL plugin.
Definition: nasl_plugins.c:166
static struct running processes[MAX_PROCESSES]
Definition: pluginlaunch.c:63
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: pluginlaunch.c:528
static int num_running_processes
Definition: pluginlaunch.c:64
static int next_free_process(kb_t main_kb, kb_t kb, struct scheduler_plugin *upcoming)
Definition: pluginlaunch.c:292
static int plugin_timeout(nvti_t *nvti)
Definition: pluginlaunch.c:372
#define ERR_CANT_FORK
Error for when it is not possible to fork a new plugin process.
Definition: pluginlaunch.h:22
#define ERR_NO_FREE_SLOT
Error for when the process table is full.
Definition: pluginlaunch.h:26
@ PLUGIN_STATUS_UNRUN
struct scheduler_plugin * plugin
Definition: pluginlaunch.c:53
pid_t pid
Definition: pluginlaunch.c:55
int timeout
Definition: pluginlaunch.c:56
enum plugin_status running_state

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

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 340 of file pluginlaunch.c.

341{
343}
static int max_running_processes
Definition: pluginlaunch.c:65

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 346 of file pluginlaunch.c.

347{
349}
static int old_max_running_processes
Definition: pluginlaunch.c:66

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 315 of file pluginlaunch.c.

316{
317 int i;
318
319 char **split = g_strsplit (prefs_get ("non_simult_ports"), ", ", 0);
320 for (i = 0; split[i]; i++)
321 non_simult_ports = g_slist_prepend (non_simult_ports, g_strdup (split[i]));
322 g_strfreev (split);
325 hostname = host;
326
328 {
329 g_debug ("max_checks (%d) > MAX_PROCESSES (%d) - modify "
330 "openvas/openvas/pluginlaunch.c",
333 }
334
336 bzero (&(processes), sizeof (processes));
337}
#define MAX_PROCESSES
'Hard' limit of the max. number of concurrent plugins per host.
Definition: pluginlaunch.c:46
static GSList * non_simult_ports
Definition: pluginlaunch.c:67
const char * hostname
Definition: pluginlaunch.c:68
Host information, implemented as doubly linked list.
Definition: hosts.c:37
int get_max_checks_number(void)
Definition: utils.c:165

References get_max_checks_number(), hostname, 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 352 of file pluginlaunch.c.

353{
354 int i;
355
356 for (i = 0; i < MAX_PROCESSES; i++)
357 {
358 if (processes[i].pid > 0)
359 {
360 /* Since the plugin process is a group leader process
361 * we can send the signal to -PID process to kill
362 * also the plugin's child processes. */
366 bzero (&(processes[i]), sizeof (struct running));
367 }
368 }
369}
@ 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.
Definition: pluginlaunch.c:52

References MAX_PROCESSES, num_running_processes, pid, running::plugin, PLUGIN_STATUS_DONE, processes, scheduler_plugin::running_state, 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 495 of file pluginlaunch.c.

496{
498 {
501 waitpid (-1, NULL, 0);
502 }
503}
static void update_running_processes(kb_t main_kb, kb_t kb)
Definition: pluginlaunch.c:109

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 528 of file pluginlaunch.c.

529{
531 return;
533 /* Max number of processes are still running, wait for a child to exit or
534 * to timeout. */
535
537 g_debug ("%s. Number of running processes >= maximum running processes (%d "
538 ">= %d). "
539 "Waiting for free slot for processes.",
541
542 /* Be careful with changing the max_running_process value.
543 * The plugin scheduler can change this value for running one plugin at
544 * time. */
545 while (
547 || (num_running_processes > 0 && (check_memory () || check_sysload ())))
548 {
549 sigset_t mask;
550 struct timespec ts = {0, 0};
551
552 ts.tv_sec = timeout_running_processes ();
553 assert (ts.tv_sec);
554 sigemptyset (&mask);
555 sigaddset (&mask, SIGCHLD);
556 sigaddset (&mask, SIGUSR1);
557 /* Wait here for the shortest plugins timeout or for a child which ended.
558 * Also, it handles signal SIGUSR1 to stop a scan. Otherwise the signa is
559 * ignored, the plugin is never stopped and the scanner keeps waiting. */
560 int sig = sigtimedwait (&mask, NULL, &ts);
561 if (sig < 0 && errno != EAGAIN)
562 g_warning ("%s: %s (%d)", __func__, strerror (errno), errno);
563 else if (sig == SIGUSR1)
564 {
565 /* SIGUSR1 signal is sent during scan stop to all host processes.
566 Therefore pluginlaunch_stop() is called here, for the
567 special case in which we are waiting for the last plugin, of the
568 last host, to finish.
569 */
571 }
572 // cleanup ipcc cache
575 }
576}
static int check_memory()
Definition: pluginlaunch.c:421
static int check_sysload()
Definition: pluginlaunch.c:435
void pluginlaunch_stop(void)
Definition: pluginlaunch.c:352
static int timeout_running_processes(void)
Return shortest timeout of the running processes.
Definition: pluginlaunch.c:509
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  )