I was having problems with "rmdirs" going into spinloops when called from "clamscan", so I re-coded it - attached.
I've also devised my own "quick and dirty" solution to the problem of "clamd" crashing and leaking memory. Seeing as the problem seems to be mainly in "mbox" i've ditched it and replaced it with "ripmime". On the 375 test messages I have been using it is also 12 seconds faster (89 secs down to 77 secs).
So, here's my new "mbox.c" :-
-------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <unistd.h>
#define RIPMIME "/usr/local/bin/ripmime"
int cl_mbox(const char *dir, int desc)
{
int ret,stat; ret = fork();
if (ret==-1) return -1;
if (ret==0)
{
if (desc) dup2(desc,0);
execlp(RIPMIME,RIPMIME,"-d",dir,"-i","-",NULL);
exit(-1);
}
waitpid(ret,&stat,0);
return 0;
}
--------------------------------------------------------------James
int rmdirs(const char *dirname)
{
DIR *dd;
struct dirent *dent;
struct stat statbuf;
char fname[PATH_MAX],*cp;
strcpy(fname,dirname);
strcat(fname,"/");
cp = fname + strlen(fname);
if ((dd = opendir(dirname)) == NULL)
{
if(!printinfected) mprintf("%s: Can't open directory.\n", dirname);
if(errno == EACCES)
{
mprintf("@Can't remove some temporary directories due to access
problem.\n");
closedir(dd);
return 0;
}
return 53;
}
while ((dent = readdir(dd)))
{
if ((!dent->d_ino)||(!strcmp(dent->d_name, "."))||(!strcmp(dent->d_name,
".."))) continue;
strcpy(cp,dent->d_name);
if(lstat(fname, &statbuf) == -1) continue;
if(S_ISDIR(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode))
rmdirs(fname);
else
unlink(fname);
}
closedir(dd);
if (rmdir(dirname)) perror(dirname);
return 0;
}
