Initialize mutex.

Fix poll_fd to properly lock/unlock mutex.
This fixes the STREAM command.

git-svn: trunk@4787
0.95
Török Edvin 17 years ago
parent 165e74cbf4
commit 80681b50c7
  1. 5
      ChangeLog
  2. 5
      clamd/others.c
  3. 6
      clamd/others.h
  4. 6
      clamd/server-th.c

@ -1,3 +1,8 @@
Sat Feb 14 11:43:10 EET 2009 (edwin)
------------------------------------
* clamd/others.c, clamd/others.h, clamd/server-th.c: Initialize
mutex. Fix poll_fd to properly lock/unlock mutex.
Sat Feb 14 10:17:37 CET 2009 (acab)
-----------------------------------
* clamav-milter/clamfi.c: Revert previous and add a better fix

@ -214,12 +214,13 @@ static int realloc_polldata(struct fd_data *data)
int poll_fd(int fd, int timeout_sec, int check_signals)
{
int ret;
struct fd_data fds;
struct fd_data fds = FDS_INIT;
memset(&fds, 0, sizeof(fds));
if (fds_add(&fds, fd, 1) == -1)
return -1;
pthread_mutex_lock(&fds.buf_mutex);
ret = fds_poll_recv(&fds, timeout_sec, check_signals);
pthread_mutex_unlock(&fds.buf_mutex);
fds_free(&fds);
return ret;
}

@ -66,6 +66,12 @@ struct fd_data {
#endif
};
#ifdef HAVE_POLL
#define FDS_INIT { PTHREAD_MUTEX_INITIALIZER, NULL, 0, NULL, 0}
#else
#define FDS_INIT { PTHREAD_MUTEX_INITIALIZER, NULL, 0}
#endif
int poll_fd(int fd, int timeout_sec, int check_signals);
void virusaction(const char *filename, const char *virname, const struct optstruct *opts);
int writen(int fd, void *buff, unsigned int count);

@ -283,6 +283,8 @@ struct acceptdata {
int syncpipe_wake_accept[2];
};
#define ACCEPTDATA_INIT { FDS_INIT, FDS_INIT, {-1, -1}, {-1, -1} }
static void *acceptloop_th(void *arg)
{
#ifdef HAVE_STRERROR_R
@ -419,7 +421,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
uint64_t val64;
size_t i, j, rr_last = 0;
pthread_t accept_th;
struct acceptdata acceptdata;
struct acceptdata acceptdata = ACCEPTDATA_INIT;
struct fd_data *fds = &acceptdata.recv_fds;
time_t start_time, current_time;
unsigned int selfchk;
@ -722,8 +724,6 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
idletimeout = optget(opts, "IdleTimeout")->numarg;
memset(&acceptdata, 0, sizeof(acceptdata));
for (i=0;i < nsockets;i++)
if (fds_add(&acceptdata.fds, socketds[i], 1) == -1) {
logg("!fds_add failed\n");

Loading…
Cancel
Save