Index: clamd/server-th.c =================================================================== --- clamd/server-th.c (revision 3586) +++ clamd/server-th.c (working copy) @@ -279,6 +279,7 @@ time_t start_time, current_time; pid_t mainpid; int idletimeout; + int polltimeout = -1; #if defined(C_BIGSTACK) || defined(C_BSD) size_t stacksize; @@ -516,14 +517,21 @@ #endif int socketd = socketds[0]; int new_sd = 0; + int timeout = 0; - if(nsockets > 1) { - int pollret = poll_fds(socketds, nsockets, -1, 1); - if(pollret > 0) { - socketd = socketds[pollret - 1]; - } else { - new_sd = -1; - } + if (selfchk) { + time(¤t_time); + polltimeout = selfchk - (int) (current_time - start_time); + if (polltimeout < 0) + polltimeout == 0; + } + int pollret = poll_fds(socketds, nsockets, polltimeout, 1); + if(pollret > 0) { + socketd = socketds[pollret - 1]; + } else { + if (pollret == 0) + timeout = 1; + new_sd = -1; } #if !defined(C_WINDOWS) && !defined(C_BEOS) if(new_sd != -1 && fstat(socketd, &st_buf) == -1) { @@ -538,7 +546,7 @@ #endif if (new_sd != -1) new_sd = accept(socketd, NULL, NULL); - if((new_sd == -1) && (errno != EINTR)) { + if((new_sd == -1) && (errno != EINTR) && !timeout) { if(progexit) { break; } @@ -589,7 +597,7 @@ if(selfchk) { time(¤t_time); - if((current_time - start_time) > (time_t)selfchk) { + if((current_time - start_time) >= (time_t)selfchk) { if(reload_db(engine, dboptions, copt, TRUE, &ret)) { pthread_mutex_lock(&reload_mutex); reload = 1;