File tree Expand file tree Collapse file tree 4 files changed +41
-14
lines changed Expand file tree Collapse file tree 4 files changed +41
-14
lines changed Original file line number Diff line number Diff line change @@ -1111,16 +1111,16 @@ attack_network (struct scan_globals *globals, kb_t *network_kb)
1111
1111
struct attack_start_args args ;
1112
1112
char * host_str ;
1113
1113
1114
- rc = kb_new (& host_kb , prefs_get ("db_address" ));
1115
- if (rc )
1114
+ host_str = gvm_host_value_str (host );
1115
+ rc = hosts_new (globals , host_str , & host_kb );
1116
+ if (rc == -1 )
1116
1117
{
1117
- report_kb_failure ( global_socket , rc );
1118
+ g_free ( host_str );
1118
1119
goto scan_stop ;
1119
1120
}
1120
- host_str = gvm_host_value_str (host );
1121
- if (hosts_new (globals , host_str , host_kb ) < 0 )
1121
+ if (rc == -2 )
1122
1122
{
1123
- g_free ( host_str );
1123
+ report_kb_failure ( global_socket , rc );
1124
1124
goto scan_stop ;
1125
1125
}
1126
1126
Original file line number Diff line number Diff line change 34
34
#include <string.h> /* for strlen() */
35
35
#include <sys/wait.h> /* for waitpid() */
36
36
#include <unistd.h> /* for close() */
37
+ #include <gvm/base/prefs.h> /* for prefs_get() */
37
38
38
39
#undef G_LOG_DOMAIN
39
40
/**
40
41
* @brief GLib log domain.
41
42
*/
42
43
#define G_LOG_DOMAIN "sd main"
43
44
45
+ #define KB_RETRY_DELAY 60
44
46
/**
45
47
* @brief Host information, implemented as doubly linked list.
46
48
*/
@@ -208,22 +210,35 @@ hosts_init (int soc, int max_hosts)
208
210
}
209
211
210
212
int
211
- hosts_new (struct scan_globals * globals , char * name , kb_t kb )
213
+ hosts_new (struct scan_globals * globals , char * name , kb_t * kb )
212
214
{
213
215
struct host * h ;
216
+ int rc = 0 ;
214
217
215
- while ( hosts_num () >= g_max_hosts )
218
+ do
216
219
{
217
- if (hosts_read (globals ) < 0 )
218
- return -1 ;
220
+ rc = kb_new (kb , prefs_get ("db_address" ));
221
+ if (rc < 0 && rc != -2 )
222
+ return -2 ;
223
+ else if (rc == -2 )
224
+ sleep (KB_RETRY_DELAY );
225
+
226
+ if (hosts_num () > 0 )
227
+ if (hosts_read (globals ) < 0 )
228
+ return -1 ;
229
+
230
+ if (hosts_num () >= g_max_hosts )
231
+ kb_delete (* kb );
219
232
}
233
+ while (hosts_num () >= g_max_hosts || rc == -2 );
234
+
220
235
if (global_scan_stop )
221
236
return 0 ;
222
237
223
238
h = g_malloc0 (sizeof (struct host ));
224
239
h -> name = g_strdup (name );
225
240
h -> pid = 0 ;
226
- h -> host_kb = kb ;
241
+ h -> host_kb = * kb ;
227
242
if (hosts != NULL )
228
243
hosts -> prev = h ;
229
244
h -> next = hosts ;
Original file line number Diff line number Diff line change 32
32
hosts_init (int , int );
33
33
34
34
int
35
- hosts_new (struct scan_globals * , char * , kb_t );
35
+ hosts_new (struct scan_globals * , char * , kb_t * );
36
36
37
37
int
38
38
hosts_set_pid (char * , pid_t );
Original file line number Diff line number Diff line change 85
85
#define PROCTITLE_RELOADING "openvassd: Reloading"
86
86
#define PROCTITLE_SERVING "openvassd: Serving %s"
87
87
88
+ #define KB_RETRY_DELAY 60
88
89
/**
89
90
* Globals that should not be touched (used in utils module).
90
91
*/
@@ -610,13 +611,23 @@ stop_all_scans (void)
610
611
void
611
612
check_kb_status ()
612
613
{
613
- int waitredis = 5 , waitkb = 5 , ret = 0 ;
614
-
614
+ int waitredis = 5 , waitkb = 5 , ret = 0 , log_flag = 1 ;
615
615
kb_t kb_access_aux ;
616
616
617
617
while (waitredis != 0 )
618
618
{
619
619
ret = kb_new (& kb_access_aux , prefs_get ("db_address" ));
620
+ if (ret == -2 )
621
+ {
622
+ if (log_flag )
623
+ {
624
+ g_warning ("No redis DB available, It will retry every %ds..." ,
625
+ KB_RETRY_DELAY );
626
+ log_flag = 0 ;
627
+ }
628
+ sleep (KB_RETRY_DELAY );
629
+ continue ;
630
+ }
620
631
if (ret )
621
632
{
622
633
g_message ("Redis connection lost. Trying to reconnect." );
@@ -629,6 +640,7 @@ check_kb_status ()
629
640
kb_delete (kb_access_aux );
630
641
break ;
631
642
}
643
+ log_flag = 1 ;
632
644
}
633
645
634
646
if (waitredis == 0 )
You can’t perform that action at this time.
0 commit comments