OpenVAS Scanner  5.1.3
pluginlaunch.c File Reference
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <strings.h>
#include <errno.h>
#include <sys/time.h>
#include <openvas/misc/network.h>
#include <openvas/misc/nvt_categories.h>
#include <openvas/misc/internal_com.h>
#include <openvas/misc/prefs.h>
#include <openvas/base/nvticache.h>
#include "pluginload.h"
#include "utils.h"
#include "log.h"
#include "sighand.h"
#include "processes.h"
#include "pluginscheduler.h"
#include "plugs_req.h"
Include dependency graph for pluginlaunch.c:

Go to the source code of this file.

Data Structures

struct  running
 Structure to represent a process in the sense of a running NVT. More...
 

Macros

#define MAX_PROCESSES   32
 'Hard' limit of the max. number of concurrent plugins per host. More...
 

Functions

void wait_for_children ()
 
void pluginlaunch_init (const char *host)
 
void pluginlaunch_disable_parrallel_checks (void)
 
void pluginlaunch_enable_parrallel_checks (void)
 
void pluginlaunch_stop (int soft_stop)
 
int plugin_launch (struct arglist *globals, struct scheduler_plugin *plugin, struct host_info *hostinfo, kb_t kb, char *name)
 
void pluginlaunch_wait (void)
 Waits and 'pushes' processes until num_running_processes is 0. More...
 
void pluginlaunch_child_cleanup (void)
 Cleanup file descriptors used by the processes array. To be called by the child process running the plugin. More...
 
void pluginlaunch_wait_for_free_process (void)
 Waits and 'pushes' processes until the number of running processes has changed. More...
 

Variables

const char * hostname = NULL
 

Macro Definition Documentation

◆ MAX_PROCESSES

#define MAX_PROCESSES   32

'Hard' limit of the max. number of concurrent plugins per host.

Definition at line 52 of file pluginlaunch.c.

Referenced by pluginlaunch_child_cleanup(), and wait_for_children().

Function Documentation

◆ plugin_launch()

int plugin_launch ( struct arglist *  globals,
struct scheduler_plugin plugin,
struct host_info *  hostinfo,
kb_t  kb,
char *  name 
)
Returns
PID of process that is connected to the plugin as returned by plugin classes pl_launch function (<=0 means there was a problem).

Definition at line 414 of file pluginlaunch.c.

416 {
417  int p;
418  int dsoc[2];
419 
420  /* Wait for a free slot while reading the input from the plugins */
421  while (num_running_processes >= max_running_processes)
422  {
423  read_running_processes ();
424  update_running_processes ();
425  }
426 
427  p = next_free_process (plugin);
428  processes[p].plugin = plugin;
429  processes[p].timeout = prefs_nvt_timeout (plugin->oid);
430  if (processes[p].timeout == 0)
431  processes[p].timeout = nvticache_get_timeout (plugin->oid);
432 
433  if (processes[p].timeout == 0)
434  {
435  int category = nvticache_get_category (plugin->oid);
436  if (category == ACT_SCANNER)
437  processes[p].timeout = atoi (prefs_get ("scanner_plugins_timeout")
438  ?: "-1");
439  else
440  processes[p].timeout = atoi (prefs_get ("plugins_timeout") ?: "-1");
441  }
442 
443  if (socketpair (AF_UNIX, SOCK_STREAM, 0, dsoc) < 0)
444  {
445  perror ("pluginlaunch.c:plugin_launch:socketpair(1) ");
446  }
447  gettimeofday (&(processes[p].start), NULL);
448 
449  processes[p].upstream_soc = arg_get_value_int (globals, "global_socket");
450  processes[p].internal_soc = dsoc[0];
451 
452  processes[p].pid =
453  nasl_plugin_launch (globals, hostinfo, kb, name, plugin->oid, dsoc[1]);
454 
455  processes[p].alive = 1;
456  close (dsoc[1]);
457  if (processes[p].pid > 0)
458  num_running_processes++;
459  else
460  processes[p].plugin->running_state = PLUGIN_STATUS_UNRUN;
461 
462  return processes[p].pid;
463 }
int alive
Definition: pluginlaunch.c:70
struct scheduler_plugin * plugin
Definition: pluginlaunch.c:63
int internal_soc
Definition: pluginlaunch.c:69
int upstream_soc
Definition: pluginlaunch.c:68
int nasl_plugin_launch(struct arglist *globals, struct host_info *hostinfo, kb_t kb, char *name, const char *oid, int soc)
Launch a NASL plugin.
Definition: nasl_plugins.c:145
int timeout
Definition: pluginlaunch.c:66
#define PLUGIN_STATUS_UNRUN

◆ pluginlaunch_child_cleanup()

void pluginlaunch_child_cleanup ( void  )

Cleanup file descriptors used by the processes array. To be called by the child process running the plugin.

Definition at line 486 of file pluginlaunch.c.

References MAX_PROCESSES.

487 {
488  int i;
489  for (i = 0; i < MAX_PROCESSES; i++)
490  if (processes[i].internal_soc)
491  close (processes[i].internal_soc);
492 }
#define MAX_PROCESSES
&#39;Hard&#39; limit of the max. number of concurrent plugins per host.
Definition: pluginlaunch.c:52

◆ pluginlaunch_disable_parrallel_checks()

void pluginlaunch_disable_parrallel_checks ( void  )

Definition at line 366 of file pluginlaunch.c.

367 {
368  max_running_processes = 1;
369 }

◆ pluginlaunch_enable_parrallel_checks()

void pluginlaunch_enable_parrallel_checks ( void  )

Definition at line 372 of file pluginlaunch.c.

373 {
374  max_running_processes = old_max_running_processes;
375 }

◆ pluginlaunch_init()

void pluginlaunch_init ( const char *  host)

Definition at line 344 of file pluginlaunch.c.

345 {
346  struct arglist *preferences = preferences_get ();
347  non_simult_ports_list = arg_get_value (preferences, "non_simult_ports_list");
348  max_running_processes = get_max_checks_number ();
349  old_max_running_processes = max_running_processes;
350  hostname = host;
351 
352  if (max_running_processes >= MAX_PROCESSES)
353  {
354  log_write
355  ("max_checks (%d) > MAX_PROCESSES (%d) - modify openvas-scanner/openvassd/pluginlaunch.c",
356  max_running_processes, MAX_PROCESSES);
357  max_running_processes = MAX_PROCESSES - 1;
358  }
359 
360 
361  num_running_processes = 0;
362  bzero (&(processes), sizeof (processes));
363 }
void log_write(const char *str,...)
Write into the logfile / syslog.
Definition: log.c:140
#define MAX_PROCESSES
&#39;Hard&#39; limit of the max. number of concurrent plugins per host.
Definition: pluginlaunch.c:52
Host information, implemented as doubly linked list.
Definition: hosts.c:44
const char * hostname
Definition: pluginlaunch.c:81
int get_max_checks_number(void)
Definition: utils.c:150

◆ pluginlaunch_stop()

void pluginlaunch_stop ( int  soft_stop)

Definition at line 379 of file pluginlaunch.c.

380 {
381  int i;
382 
383  if (soft_stop)
384  {
385  read_running_processes ();
386 
387  for (i = 0; i < MAX_PROCESSES; i++)
388  {
389  if (processes[i].pid > 0)
390  kill (processes[i].pid, SIGTERM);
391  }
392  usleep (20000);
393  }
394 
395  for (i = 0; i < MAX_PROCESSES; i++)
396  {
397  if (processes[i].pid > 0)
398  {
399  kill (processes[i].pid, SIGKILL);
400  num_running_processes--;
401  processes[i].plugin->running_state = PLUGIN_STATUS_DONE;
402  close (processes[i].internal_soc);
403  bzero (&(processes[i]), sizeof (struct running));
404  }
405  }
406 }
struct scheduler_plugin * plugin
Definition: pluginlaunch.c:63
#define MAX_PROCESSES
&#39;Hard&#39; limit of the max. number of concurrent plugins per host.
Definition: pluginlaunch.c:52
#define PLUGIN_STATUS_DONE
Structure to represent a process in the sense of a running NVT.
Definition: pluginlaunch.c:61

◆ pluginlaunch_wait()

void pluginlaunch_wait ( void  )

Waits and 'pushes' processes until num_running_processes is 0.

Definition at line 470 of file pluginlaunch.c.

References wait_for_children().

471 {
472  do
473  {
475  read_running_processes ();
476  update_running_processes ();
477  }
478  while (num_running_processes != 0);
479 }
void wait_for_children()
Definition: pluginlaunch.c:126
Here is the call graph for this function:

◆ pluginlaunch_wait_for_free_process()

void pluginlaunch_wait_for_free_process ( void  )

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

Definition at line 499 of file pluginlaunch.c.

Referenced by plugin_next_unrun_dependency().

500 {
501  int num = num_running_processes;
502  while (num && num_running_processes == num)
503  {
505  read_running_processes ();
506  update_running_processes ();
507  }
508 }
void wait_for_children()
Definition: pluginlaunch.c:126
Here is the caller graph for this function:

◆ wait_for_children()

void wait_for_children ( void  )

Definition at line 126 of file pluginlaunch.c.

References MAX_PROCESSES.

Referenced by pluginlaunch_wait().

127 {
128  int i;
129 
130  for (i = 0; i < MAX_PROCESSES; i++)
131  if (processes[i].pid != 0)
132  {
133  int ret;
134  do
135  {
136  ret = waitpid (-1, NULL, WNOHANG);
137  }
138  while (ret < 0 && errno == EINTR);
139  }
140 }
#define MAX_PROCESSES
&#39;Hard&#39; limit of the max. number of concurrent plugins per host.
Definition: pluginlaunch.c:52
Here is the caller graph for this function:

Variable Documentation

◆ hostname

const char* hostname = NULL

Definition at line 81 of file pluginlaunch.c.