Here's the patch I spoke of:
Joe
--
Be still like a mountain and flow like a great river.
--Lao Tse
--- clamav-milter.c 2003-09-30 07:53:55.000000000 -0400
+++ clamav-milter.c.new 2003-10-02 15:22:15.000000000 -0400
@@ -163,6 +163,8 @@
#include <stdio.h>
#include <sysexits.h>
+#include <fcntl.h>
+#include <paths.h>
#ifndef TARGET_OS_FREEBSD
#include <malloc.h>
#endif
@@ -299,6 +301,7 @@
extern char *optarg;
char *port = NULL, *ptr;
FILE *clamd;
+ int fd;
const char *cfgfile = CL_DEFAULT_CFG;
struct cfgstruct *cpt;
char cmd[64];
@@ -527,6 +530,36 @@
*ptr = '\0';
if(!cfgopt(copt, "Foreground"))
+ {
+ close (STDIN_FILENO);
+ close (STDOUT_FILENO);
+ close (STDERR_FILENO);
+
+ /* point stdid, stdout, stderr to /dev/null */
+ if ( (fd = open (_PATH_DEVNULL, O_RDWR, 0)) != -1)
+ {
+ dup2 (fd, STDIN_FILENO);
+ dup2 (fd, STDOUT_FILENO);
+ dup2 (fd, STDERR_FILENO);
+ if (fd > 2)
+ close (fd);
+ }
+
+ switch(fork()) {
+ case -1:
+ perror("fork");
+ return EX_TEMPFAIL;
+ case 0: /* child */
+ break;
+ default: /* parent */
+ return EX_OK;
+ }
+
+ if (setsid () == -1)
+ {
+ return EX_TEMPFAIL;
+ }
+
switch(fork()) {
case -1:
perror("fork");
@@ -536,6 +569,7 @@
default: /* parent */
return EX_OK;
}
+ }
if(smfi_setconn(port) == MI_FAILURE) {
fprintf(stderr, "%s: smfi_setconn failed\n",
@@ -715,7 +749,7 @@
{
struct privdata *privdata;
struct sockaddr_in reply;
- short port;
+ unsigned short port;
int nbytes, rc;
char buf[64];
@@ -1172,6 +1206,8 @@
assert(privdata == NULL);
#endif
+ clamfi_cleanup (ctx);
+
if(logVerbose)
syslog(LOG_DEBUG, "clamfi_close");
@@ -1241,7 +1277,8 @@
/*
* Deliberately errs on the side of broadcasting too many times
*/
- --n_children;
+ if (n_children != 0)
+ --n_children;
if((n_children < max_children) && (n_children > 0)) {
#ifdef CL_DEBUG
puts("pthread_cond_broadcast");