Can bogofilter run by multiprocess at the same time
陈治璋
john.chen at net263.com
Tue Oct 12 05:28:37 CEST 2004
The folloing code can produce a deadlock in bogofilter :
uname -a :
Linux xmail 2.4.2-2smp #1 SMP Sun Apr 8 20:21:34 EDT 2001 i686 unknown
gcc -v :
gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
My question is: Can bogofilter run by multiprocess at the same time?
#include <string>
#include <signal.h>
#include <pthread.h>
#include <stdio.h>
#include <sys/wait.h>
#include <sys/stat.h>
void *read_file(char *filename)
{
struct stat statbuf;
void *read_buf = NULL;
FILE *file_read = NULL;
memset(&statbuf,0,sizeof(struct stat));
if (!filename)
return NULL;
if (strstr(filename,"../") || strstr(filename,"..\\") )
return NULL;
if (!stat(filename,&statbuf)){
if (statbuf.st_size == 0)
return NULL;
read_buf = (void *)malloc(statbuf.st_size+1);
if (!read_buf){
return NULL;
}
file_read = fopen(filename,"rb");
if (!file_read ||
fread(read_buf,statbuf.st_size,1,file_read)!=1){
free(read_buf);
if (!file_read){
}else{
fclose(file_read);
}
return NULL;
}
fclose(file_read);
}
return (read_buf);
}
string get_email(const char* filename )
{
char* buf = (char*)read_file((char*)filename);
string sbuf = buf;
delete[] buf;
return sbuf;
}
void* bogo_check(void* p)
{
FILE* file = popen("bogofilter", "w");
signal(SIGPIPE, SIG_IGN);
if (file == NULL)
{
perror("popen");
}
fputs( get_email("spam.eml").c_str(),file);
int status = pclose(file);
return NULL;
}
int main(){
pthread_t ids[52];
for (int i = 0; i < 52; i ++){
pthread_create(&ids[i], NULL, bogo_check, NULL);
}
for (int i = 0; i < 52; i ++){
pthread_join(ids[i], NULL);
printf("checked %d!\n", i);
}
}
More information about the bogofilter-dev
mailing list