Browse code

clamav-milter: don't logg() past fork(), add notes

aCaB authored on 2010/05/03 17:37:31
Showing 3 changed files
... ...
@@ -371,6 +371,8 @@ sfsistat clamfi_eom(SMFICTX *ctx) {
371 371
 			    char *e_msg_id = strdup(msg_id);
372 372
 			    pid_t pid;
373 373
 
374
+			    logg("*VirusEvent: about to execute '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s'\n", viraction, vir, e_id, e_from, e_to, e_msg_subj, e_msg_id, e_msg_date);
375
+
374 376
 			    pthread_mutex_lock(&virusaction_lock);
375 377
 			    pid = fork();
376 378
 			    if(!pid) {
... ...
@@ -384,14 +386,19 @@ sfsistat clamfi_eom(SMFICTX *ctx) {
384 384
 				args[6] = e_msg_id;
385 385
 				args[7] = e_msg_date;
386 386
 				args[8] = NULL;
387
-				logg("*Executing: '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s'\n", viraction, vir, e_id, e_from, e_to, e_msg_subj, e_msg_id, e_msg_date);
388
-				if((ret = execvp(viraction, args)) < 0) {
389
-				    logg("!VirusEvent: exec failed: %s\n", cli_strerror(errno, er, sizeof(er)));
390
-				}
391
-				exit(ret);
387
+				exit(execvp(viraction, args));
392 388
 			    } else if(pid > 0) {
393 389
 				pthread_mutex_unlock(&virusaction_lock);
394
-				waitpid(pid, NULL, 0);
390
+				if(waitpid(pid, &ret, 0)<0)
391
+				    logg("!VirusEvent: waitpid() failed: %s\n", cli_strerror(errno, er, sizeof(er)));
392
+				else {
393
+				    if(WIFEXITED(ret))
394
+					logg("*VirusEvent: child exited with code %d\n", WEXITSTATUS(ret));
395
+				    else if(WIFSIGNALED(ret))
396
+					logg("*VirusEvent: child killed by signal %d\n", WTERMSIG(ret));
397
+				    else
398
+					logg("*VirusEvent: child lost\n");
399
+				}
395 400
 			    } else {
396 401
 				logg("!VirusEvent: fork failed: %s\n", cli_strerror(errno, er, sizeof(er)));
397 402
 			    }
... ...
@@ -187,10 +187,13 @@ Example
187 187
 # Default: disabled
188 188
 #ReportHostname my.mail.server.name
189 189
 
190
-# Execute a command when an infected message is processed.
190
+# Execute a command (possibly searching PATH) when an infected message is found.
191 191
 # The following parameters are passed to the invoked program in this order:
192 192
 # virus name, queue id, sender, destination, subject, message id, message date.
193
-# Note: this requires MTA macroes to be available (see LogInfected below)
193
+# Note #1: this requires MTA macroes to be available (see LogInfected below)
194
+# Note #2: the process is invoked in the context of clamav-milter
195
+# Note #3: clamav-milter will wait for the process to exit. Be quick or fork to
196
+# avoid unnecessary delays in email delievery
194 197
 # Default: disabled
195 198
 #VirusAction /usr/local/bin/my_infected_message_handler
196 199
 
... ...
@@ -420,7 +420,7 @@ const struct clam_option __clam_options[] = {
420 420
 
421 421
     { "ReportHostname", NULL, 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_MILTER, "When AddHeader is in use, this option allows to arbitrary set the reported\nhostname. This may be desirable in order to avoid leaking internal names.\nIf unset the real machine name is used.", "my.mail.server.name" },
422 422
 
423
-    { "VirusAction", NULL, 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_MILTER, "Execute a command when an infected message is processed.\nThe following parameters are passed to the invoked program in this order:\nvirus name, queue id, sender, destination, subject, message id, message date.\nNote: this requires MTA macroes to be available (see LogInfected below)", "/usr/local/bin/my_infected_message_handler" },
423
+    { "VirusAction", NULL, 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_MILTER, "Execute a command when an infected message is processed.\nThe following parameters are passed to the invoked program in this order:\nvirus name, queue id, sender, destination, subject, message id, message date.\nNote #1: this requires MTA macroes to be available (see LogInfected below)\nNote #2: the process is invoked in the context of clamav-milter\nNote #3: clamav-milter will wait for the process to exit. Be quick or fork to\navoid unnecessary delays in email delievery", "/usr/local/bin/my_infected_message_handler" },
424 424
 
425 425
     { "Chroot", NULL, 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_MILTER, "Chroot to the specified directory.\nChrooting is performed just after reading the config file and before\ndropping privileges.", "/newroot" },
426 426