Browse code

clamonacc - add maxthreads config option; fix issue where mutex wasn't being unlocked on empty case; fix issue where pathname wasn't being passed in; added some noisy logging

Mickey Sola authored on 2019/05/18 01:34:54
Showing 6 changed files
... ...
@@ -82,6 +82,8 @@ int main(int argc, char **argv)
82 82
 	}
83 83
 	ctx->clamdopts = clamdopts;
84 84
 
85
+        ctx->maxthreads = optget(ctx->clamdopts, "OnAccessMaxThreads")->numarg;
86
+
85 87
         /* Setup our event queue */
86 88
         switch(onas_scanque_start(&ctx)) {
87 89
             case CL_SUCCESS:
... ...
@@ -230,7 +230,10 @@ int onas_fan_eloop(struct onas_context **ctx) {
230 230
                                         /* fanotify specific stuffs */
231 231
 					event_data->bool_opts |= ONAS_SCTH_B_FANOTIFY;
232 232
 					event_data->fmd = fmd;
233
+                                        event_data->pathname = cli_strdup(fname);
233 234
 
235
+
236
+					logg("ClamFanotif: attempting to feed consumer queue\n");
234 237
 					/* feed consumer queue */
235 238
 					if (CL_SUCCESS != onas_queue_event(event_data)) {
236 239
                 close(fmd->fd);
... ...
@@ -345,7 +345,7 @@ void *onas_ddd_th(void *arg) {
345 345
 	 * SIGFPE, SIGILL, SIGSEGV, or SIGBUS signal */
346 346
     sigdelset(&sigset, SIGFPE);
347 347
     sigdelset(&sigset, SIGILL);
348
-    sigdelset(&sigset, SIGSEGV);
348
+	//sigdelset(&sigset, SIGSEGV);
349 349
 #ifdef SIGBUS
350 350
     sigdelset(&sigset, SIGBUS);
351 351
 #endif
... ...
@@ -153,7 +153,7 @@ void *onas_scanque_th(void *arg) {
153 153
 	 * SIGFPE, SIGILL, SIGSEGV, or SIGBUS signal */
154 154
 	sigdelset(&sigset, SIGFPE);
155 155
 	sigdelset(&sigset, SIGILL);
156
-	sigdelset(&sigset, SIGSEGV);
156
+	//sigdelset(&sigset, SIGSEGV);
157 157
 #ifdef SIGBUS
158 158
 	sigdelset(&sigset, SIGBUS);
159 159
 #endif
... ...
@@ -164,11 +164,13 @@ void *onas_scanque_th(void *arg) {
164 164
 	sigaction(SIGUSR1, &act, NULL);
165 165
 	sigaction(SIGSEGV, &act, NULL);
166 166
 
167
+	logg("*ClamQueue: initializing event queue consumer w/ (%d) threads in thread pool\n", ctx->maxthreads);
167 168
         onas_init_event_queue();
168 169
         threadpool thpool = thpool_init(ctx->maxthreads);
169 170
 	g_thpool = thpool;
170 171
 
171 172
         /* loop w/ onas_consume_event until we die */
173
+	logg("*ClamQueue: waiting to cosume events ...\n");
172 174
 	do {
173 175
 		/* if there's no event to consume ... */
174 176
 		if (!onas_consume_event(thpool)) {
... ...
@@ -196,6 +198,7 @@ static int onas_consume_event(threadpool thpool) {
196 196
 
197 197
     /* TODO: create scth arg using head event data, use get queue head here before lock*/
198 198
     if (onas_queue_is_b_empty()) {
199
+        pthread_mutex_unlock(&onas_queue_lock);
199 200
         return 1;
200 201
     }
201 202
 
... ...
@@ -214,10 +217,13 @@ static int onas_consume_event(threadpool thpool) {
214 214
 
215 215
 cl_error_t onas_queue_event(struct onas_scan_event *event_data) {
216 216
 
217
+
218
+    logg("*ClamonQueue: queueing event!\n");
217 219
     pthread_mutex_lock(&onas_queue_lock);
218 220
 
219 221
     struct onas_event_queue_node *node = NULL;
220 222
 
223
+    logg("*ClamonQueue: queueing event!\n");
221 224
     if (CL_EMEM == onas_new_event_queue_node(&node)) {
222 225
 	    return CL_EMEM;
223 226
     }
... ...
@@ -262,6 +262,9 @@ void *onas_scan_worker(void *arg) {
262 262
 
263 263
 	if (NULL == event_data || NULL == event_data->pathname) {
264 264
 		logg("ClamWorker: invalid worker arguments for scanning thread\n");
265
+                if (event_data) {
266
+                    logg("ClamWorker: pathname is null\n");
267
+                }
265 268
         goto done;
266 269
     }
267 270
 
... ...
@@ -423,6 +423,9 @@ const struct clam_option __clam_options[] = {
423 423
 
424 424
     { "OnAccessCurlTimeout", NULL, 0, CLOPT_TYPE_NUMBER, MATCH_NUMBER, 5000l, NULL, 0, OPT_CLAMD, "Max amount of time (in milliseconds) that the OnAccess client should spend for every connect, send, and recieve attempt when communicating with clamd via curl (5s default)", "10000L" },
425 425
 
426
+    { "OnAccessMaxThreads", NULL, 0, CLOPT_TYPE_NUMBER, MATCH_NUMBER, 5, NULL, 0, OPT_CLAMD, "Max number of scanning threads to allocate to the OnAccess thread pool at startup--these threads are the ones responsible for creating a connection with the daemon and kicking off scanning after an event has been processed. To prevent clamonacc from consuming all clamd's resources keep this lower than clamd's max threads. Default is 5", "10" },
427
+
428
+
426 429
     /* clamonacc cmdline options */
427 430
 
428 431
     { NULL, "watch-list", 'w', CLOPT_TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMONACC, "", ""},