27#include <gvm/base/prefs.h>
28#include <gvm/util/nvticache.h>
41#define G_LOG_DOMAIN "sd main"
46#define MAX_PROCESSES 32
78 static int vts_timeouts_counter = 0;
79 int max_vts_timeouts = 0;
80 const gchar *max_vts_timeouts_str = NULL;
83 if ((max_vts_timeouts_str = prefs_get (
"max_vts_timeouts")) == NULL)
85 g_debug (
"%s: max_vts_timeouts not set.", __func__);
90 max_vts_timeouts = atoi (max_vts_timeouts_str);
91 if (max_vts_timeouts <= 0)
93 g_debug (
"%s: max_vts_timeouts disabled", __func__);
97 vts_timeouts_counter++;
99 if (vts_timeouts_counter >= max_vts_timeouts)
113 int log_whole = prefs_get_bool (
"log_whole_attack");
118 gettimeofday (&now, NULL);
124 int ret_terminate = 0;
129 && ((now.tv_sec -
processes[i].start.tv_sec)
138 g_message (
"%s (pid %d) is slow to finish - killing it",
141 g_snprintf (msg,
sizeof (msg),
142 "ERRMSG|||%s||| |||general/tcp|||%s|||"
143 "NVT timed out after %d seconds.",
146 "internal/results", msg);
155 g_snprintf (msg,
sizeof (msg),
156 "ERRMSG|||%s||| |||general/tcp||| |||"
157 "Host has been marked as dead. Too many "
161 main_kb,
"internal/results", msg);
166 if (ret_terminate == 0)
181 if (now.tv_usec <
processes[i].start.tv_usec)
184 now.tv_usec += 1000000;
189 char *
name = nvticache_get_filename (
oid);
191 "%s (%s) [%d] finished its job in %ld.%.3ld seconds",
193 (
long) (now.tv_sec -
processes[i].start.tv_sec),
194 (
long) ((now.tv_usec -
processes[i].start.tv_usec)
199 g_snprintf (msg,
sizeof (msg),
"%s/%ld/%ld",
oid,
200 (
long) ((now.tv_sec * 1000)
201 + (
long) (now.tv_usec / 1000)),
204 kb_item_push_str (kb,
"general/script_stats", msg);
211 while (e < 0 && errno == EINTR);
229 if (!list1 || !list2)
237 if (!strcmp (list1->data, tmp->data))
249 GSList *common_ports = NULL;
250 char **array, *ports;
255 ports = nvticache_get_required_ports (
oid);
258 array = g_strsplit (ports,
", ", 0);
263 for (i = 0; array[i]; i++)
268 if (!strcmp (tmp->data, array[i]))
269 common_ports = g_slist_prepend (common_ports, g_strdup (tmp->data));
282 GSList *common_ports1 = NULL, *common_ports2 = NULL;
287 if (common_ports1 && common_ports2 &&
common (common_ports1, common_ports2))
289 g_slist_free_full (common_ports1, g_free);
290 g_slist_free_full (common_ports2, g_free);
328 char **split = g_strsplit (prefs_get (
"non_simult_ports"),
", ", 0);
329 for (i = 0; split[i]; i++)
338 g_debug (
"max_checks (%d) > MAX_PROCESSES (%d) - modify "
339 "openvas/openvas/pluginlaunch.c",
391 timeout = atoi (timeout_str);
397 tmp = atoi (prefs_get (
"scanner_plugins_timeout"));
398 timeout = tmp ? tmp : SCANNER_NVT_TIMEOUT;
402 tmp = atoi (prefs_get (
"plugins_timeout"));
403 timeout = tmp ? tmp : NVT_TIMEOUT;
416 memset (buf, 0,
sizeof (buf));
418 fd = fopen (
"/proc/meminfo",
"r");
421 g_warning (
"Couldn't open /proc/meminfo");
424 len = fread (buf, 1,
sizeof (buf) - 1, fd);
432 g_warning (
"Couldn't read /proc/meminfo");
435 hit = strstr (buf,
"MemAvailable:");
439 return atoi (hit + 14) / 1000;
481 struct in6_addr *ip, GSList *vhosts, kb_t kb, kb_t
main_kb,
482 nvti_t *nvti,
int *error)
491 g_warning (
"%s. There is currently no free slot available for starting a "
500 gettimeofday (&(
processes[p].start), NULL);
523 waitpid (-1, NULL, 0);
539 if (!timeout ||
processes[i].timeout < timeout)
559 g_debug (
"%s. Number of running processes >= maximum running processes (%d "
561 "Waiting for free slot for processes.",
572 struct timespec ts = {0, 0};
577 sigaddset (&mask, SIGCHLD);
578 sigaddset (&mask, SIGUSR1);
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)
static struct timeval timeval(unsigned long val)
int nasl_plugin_launch(struct scan_globals *globals, struct in6_addr *ip, GSList *vhosts, kb_t kb, const char *oid)
Launch a NASL plugin.
Header file for module network.
Category (ACT_*) definitions.
void pluginlaunch_enable_parallel_checks(void)
void pluginlaunch_init(const char *host)
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.
static struct running processes[MAX_PROCESSES]
static int common(GSList *list1, GSList *list2)
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 get_available_memory()
static int max_running_processes
static int max_nvt_timeouts_reached(void)
Check if max_nvt_timeouts is set and if has been reached.
static int simult_ports(const char *oid, const char *next_oid)
static int check_memory()
static int check_sysload()
void pluginlaunch_stop(void)
#define MAX_PROCESSES
'Hard' limit of the max. number of concurrent plugins per host.
static GSList * non_simult_ports
static GSList * required_ports_in_list(const char *oid, GSList *list)
static void update_running_processes(kb_t main_kb, kb_t kb)
static int num_running_processes
static int timeout_running_processes(void)
Return shortest timeout of the running processes.
void pluginlaunch_wait(kb_t main_kb, kb_t kb)
Waits and 'pushes' processes until num_running_processes is 0.
void pluginlaunch_disable_parallel_checks(void)
static int next_free_process(kb_t main_kb, kb_t kb, struct scheduler_plugin *upcoming)
static int old_max_running_processes
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.
header for pluginscheduler.c
char * get_plugin_preference(const char *oid, const char *name, int pref_id)
Get the a plugins preference.
int kb_item_push_str_with_main_kb_check(kb_t kb, const char *name, const char *value)
Check if the current kb corresponds to the original scanid, if it matches it kb_item_push_str....
Header file for module plugutils.
int procs_cleanup_children(void)
iterates through ipcc and verify if a child is stopped or killed to free the file handler.
int terminate_process(pid_t pid)
Terminates a given process. If termination does not work, the process will get killed....
headerfile for sighand.c.
Host information, implemented as doubly linked list.
Structure to represent a process in the sense of a running NVT.
struct scheduler_plugin * plugin
int get_max_checks_number(void)
int process_alive(pid_t pid)
int check_host_still_alive(kb_t, const char *)
Check if the hosts is still alive and set it as dead if not.