28 #include "../nasl/nasl.h" 35 #include <gvm/base/prefs.h> 36 #include <gvm/base/proctitle.h> 37 #include <gvm/util/nvticache.h> 49 #define G_LOG_DOMAIN "sd main" 68 collect_nvts (
const char *folder,
const char *subdir, GSList *files)
76 dir = g_dir_open (folder, 0, NULL);
80 fname = g_dir_read_name (dir);
85 path = g_build_filename (folder, fname, NULL);
86 if (g_file_test (path, G_FILE_TEST_IS_DIR))
88 char *new_folder, *new_subdir;
90 new_folder = g_build_filename (folder, fname, NULL);
91 new_subdir = g_build_filename (subdir, fname, NULL);
100 else if (g_str_has_suffix (fname,
".nasl"))
101 files = g_slist_prepend (files, g_build_filename (subdir, fname, NULL));
103 fname = g_dir_read_name (dir);
114 int elapsed, remaining;
116 if (start_time.tv_sec == 0)
119 gettimeofday (¤t_time, NULL);
120 elapsed = current_time.tv_sec - start_time.tv_sec;
121 remaining = total - loaded;
122 return (remaining * elapsed) / loaded;
140 shm_key = rand () + 1;
148 loading_shmid = shmget (shm_key,
sizeof (
int) * 2, IPC_CREAT | 0600);
233 GSList *oids, *element;
235 proctitle_set (
"openvas: Cleaning leftover NVTs.");
237 count = nvticache_count ();
238 if ((
int) count <= num_files)
241 oids = element = nvticache_get_oids ();
244 char *path = nvticache_get_src (element->data);
246 if (!g_file_test (path, G_FILE_TEST_EXISTS))
247 nvticache_delete (element->data);
249 element = element->next;
251 g_slist_free_full (oids, g_free);
257 GSList *files = NULL, *f;
258 int loaded_files = 0, num_files = 0;
264 g_debug (
"%s:%d : folder == NULL", __FILE__, __LINE__);
265 g_debug (
"Could not determine the value of <plugins_folder>. " 267 (
char *) prefs_get (
"config_file"));
272 num_files = g_slist_length (files);
278 if (gettimeofday (&start_time, NULL))
280 bzero (&start_time,
sizeof (start_time));
281 g_debug (
"gettimeofday: %s", strerror (errno));
287 static int err_count = 0;
288 char *
name = f->data;
291 if (loaded_files % 50 == 0)
296 percentile = (loaded_files * 100) / num_files;
298 proctitle_set (
"openvas: Reloaded %d of %d NVTs" 299 " (%d%% / ETA: %02d:%02d)",
300 loaded_files, num_files, percentile, eta / 60,
303 if (prefs_get_bool (
"log_plugins_name_at_load"))
304 g_message (
"Loading %s",
name);
305 if (g_str_has_suffix (
name,
".nasl"))
313 g_debug (
"Stopped loading plugins: High number of errors.");
314 proctitle_set (
"openvas: Error loading NVTs.");
315 g_slist_free_full (files, g_free);
318 f = g_slist_next (f);
322 g_slist_free_full (files, g_free);
325 proctitle_set (
"openvas: Reloaded all the NVTs.");
333 const gchar *pref_include_folders;
336 pref_include_folders = prefs_get (
"include_folders");
337 if (pref_include_folders != NULL)
339 gchar **include_folders = g_strsplit (pref_include_folders,
":", 0);
342 for (i = 0; i < g_strv_length (include_folders); i++)
346 g_debug (
"Could not add %s to the list of include folders.\n" 347 "Make sure %s exists and is a directory.\n",
348 include_folders[i], include_folders[i]);
351 g_strfreev (include_folders);
361 const char *plugins_folder = prefs_get (
"plugins_folder");
363 if (nvticache_init (plugins_folder, prefs_get (
"db_address")))
365 g_debug (
"Failed to initialize nvti cache.");
380 const char *plugins_folder = prefs_get (
"plugins_folder");
387 waitpid (child_pid, &ret, 0);
static void include_dirs(void)
void(*)(int) openvas_signal(int signum, void(*handler)(int))
static void plugins_reload_from_dir(void *folder)
headerfile for sighand.c.
int total_loading_plugins(void)
void nasl_clean_inc(void)
void set_current_loading_plugins(int current)
int nasl_plugin_add(char *folder, char *filename)
Add one .nasl plugin to the plugin list.
int current_loading_plugins(void)
void destroy_loading_shm(void)
int calculate_eta(struct timeval start_time, int loaded, int total)
struct timeval timeval(unsigned long val)
void init_loading_shm(void)
void set_total_loading_plugins(int total)
GSList * collect_nvts(const char *folder, const char *subdir, GSList *files)
Collects all NVT files in a directory and recurses into subdirs.
static void cleanup_leftovers(int num_files)
pid_t create_process(process_func_t function, void *argument)
Create a new process (fork).
int plugins_cache_init(void)
Main function for nvticache initialization without loading the plugins.
int add_nasl_inc_dir(const char *)
Adds the given string as directory for searching for includes.