diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clamsmtpd.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/clamsmtpd.c b/src/clamsmtpd.c index f1d6e75..34a53a3 100644 --- a/src/clamsmtpd.c +++ b/src/clamsmtpd.c @@ -37,6 +37,7 @@ #include <sys/types.h> #include <sys/param.h> +#include <sys/wait.h> #include <paths.h> #include <ctype.h> @@ -327,14 +328,16 @@ int cb_check_data(spctx_t* sp) const char* virus; clctx_t* ctx = (clctx_t*)sp; - /* Connect to clamav */ - if(!spio_valid(&(ctx->clam))) - r = connect_clam(ctx); - - if(r != -1 && (r = sp_cache_data(sp)) > 0) + /* ClamAV doesn't like empty files */ + if((r = sp_cache_data(sp)) > 0) + { + /* Connect to clamav */ + if(!spio_valid(&(ctx->clam))) + r = connect_clam(ctx); - /* ClamAV doesn't like empty files */ - r = clam_scan_file(ctx, &virus); + if(r != -1) + r = clam_scan_file(ctx, &virus); + } switch(r) { @@ -659,6 +662,9 @@ static int virus_action(clctx_t* ctx, const char* virus) if(g_clstate.virusaction != NULL) { + /* Cleanup any old actions */ + while(waitpid(-1, &i, WNOHANG) > 0) + ; sp_messagex(sp, LOG_DEBUG, "executing virus action: %s", g_clstate.virusaction); @@ -670,13 +676,6 @@ static int virus_action(clctx_t* ctx, const char* virus) /* The child */ case 0: - /* - * New process group because we don't care about this child, - * it's return value, waiting for it to exit or any of that. - * Apparently this can't fail when done like this. - */ - setsid(); - /* Close all descriptors */ for(i = 0; i <= 2; i++) close(i); @@ -696,7 +695,7 @@ static int virus_action(clctx_t* ctx, const char* virus) /* If that returned then there was an error, but there's * not much we can do about it. */ - exit(1); + _exit(1); break; }; } |