20#include <bsd/unistd.h>
23#include <gvm/base/prefs.h>
24#include <gvm/util/nvticache.h>
36#define G_LOG_DOMAIN "sd main"
55collect_nvts (
const char *folder,
const char *subdir, GSList *files)
63 dir = g_dir_open (folder, 0, NULL);
67 fname = g_dir_read_name (dir);
72 path = g_build_filename (folder, fname, NULL);
73 if (g_file_test (path, G_FILE_TEST_IS_DIR))
75 char *new_folder, *new_subdir;
77 new_folder = g_build_filename (folder, fname, NULL);
78 new_subdir = g_build_filename (subdir, fname, NULL);
87 else if (g_str_has_suffix (fname,
".nasl"))
88 files = g_slist_prepend (files, g_build_filename (subdir, fname, NULL));
90 fname = g_dir_read_name (dir);
101 int elapsed, remaining;
103 if (start_time.tv_sec == 0)
106 gettimeofday (¤t_time, NULL);
107 elapsed = current_time.tv_sec - start_time.tv_sec;
108 remaining = total - loaded;
109 return (remaining * elapsed) / loaded;
127 shm_key = rand () + 1;
135 loading_shmid = shmget (shm_key,
sizeof (
int) * 2, IPC_CREAT | 0600);
220 GSList *oids, *element;
222 setproctitle (
"openvas: Cleaning leftover NVTs.");
224 count = nvticache_count ();
225 if ((
int) count <= num_files)
228 oids = element = nvticache_get_oids ();
231 char *path = nvticache_get_src (element->data);
233 if (!g_file_test (path, G_FILE_TEST_EXISTS))
234 nvticache_delete (element->data);
236 element = element->next;
238 g_slist_free_full (oids, g_free);
244 GSList *files = NULL, *f;
245 int loaded_files = 0, num_files = 0;
251 g_debug (
"%s:%d : folder == NULL", __FILE__, __LINE__);
252 g_debug (
"Could not determine the value of <plugins_folder>. "
254 (
char *) prefs_get (
"config_file"));
259 num_files = g_slist_length (files);
265 if (gettimeofday (&start_time, NULL))
267 bzero (&start_time,
sizeof (start_time));
268 g_debug (
"gettimeofday: %s", strerror (errno));
274 static int err_count = 0;
275 char *
name = f->data;
278 if (loaded_files % 50 == 0)
283 percentile = (loaded_files * 100) / num_files;
285 setproctitle (
"openvas: Reloaded %d of %d NVTs"
286 " (%d%% / ETA: %02d:%02d)",
287 loaded_files, num_files, percentile, eta / 60,
290 if (prefs_get_bool (
"log_plugins_name_at_load"))
291 g_message (
"Loading %s",
name);
292 if (g_str_has_suffix (
name,
".nasl"))
300 g_debug (
"Stopped loading plugins: High number of errors.");
301 setproctitle (
"openvas: Error loading NVTs.");
302 g_slist_free_full (files, g_free);
305 f = g_slist_next (f);
309 g_slist_free_full (files, g_free);
312 setproctitle (
"openvas: Reloaded all the NVTs.");
320 const gchar *pref_include_folders;
323 pref_include_folders = prefs_get (
"include_folders");
324 if (pref_include_folders != NULL)
326 gchar **include_folders = g_strsplit (pref_include_folders,
":", 0);
329 for (i = 0; i < g_strv_length (include_folders); i++)
333 g_debug (
"Could not add %s to the list of include folders.\n"
334 "Make sure %s exists and is a directory.\n",
335 include_folders[i], include_folders[i]);
338 g_strfreev (include_folders);
351 const char *plugins_folder = prefs_get (
"plugins_folder");
353 if (nvticache_init (plugins_folder, prefs_get (
"db_address")))
355 g_debug (
"Failed to initialize nvti cache.");
375 const char *plugins_folder = prefs_get (
"plugins_folder");
void nasl_clean_inc(void)
int add_nasl_inc_dir(const char *)
Adds the given string as directory for searching for includes.
static struct timeval timeval(unsigned long val)
int nasl_file_check(const char *folder, const char *filename)
Check a single .nasl/.inc file.
int nasl_plugin_add(const char *folder, char *filename)
Add one .nasl plugin to the plugin list.
static int calculate_eta(struct timeval start_time, int loaded, int total)
static void cleanup_leftovers(int num_files)
int total_loading_plugins(void)
int plugins_init(void)
main function for loading all the plugins
static GSList * collect_nvts(const char *folder, const char *subdir, GSList *files)
Collects all NVT files in a directory and recurses into subdirs.
static void set_total_loading_plugins(int total)
static void include_dirs(void)
void init_loading_shm(void)
void destroy_loading_shm(void)
static int plugins_reload_from_dir(const char *folder)
static void set_current_loading_plugins(int current)
int current_loading_plugins(void)
int plugins_cache_init(void)
Main function for nvticache initialization without loading the plugins.
void(*)(int) openvas_signal(int signum, void(*handler)(int))
headerfile for sighand.c.