git-svn: trunk@4787
Török Edvin authored on 2009/02/14 18:14:04... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Sat Feb 14 11:43:10 EET 2009 (edwin) |
|
2 |
+------------------------------------ |
|
3 |
+ * clamd/others.c, clamd/others.h, clamd/server-th.c: Initialize |
|
4 |
+ mutex. Fix poll_fd to properly lock/unlock mutex. |
|
5 |
+ |
|
1 | 6 |
Sat Feb 14 10:17:37 CET 2009 (acab) |
2 | 7 |
----------------------------------- |
3 | 8 |
* clamav-milter/clamfi.c: Revert previous and add a better fix |
... | ... |
@@ -214,12 +214,13 @@ static int realloc_polldata(struct fd_data *data) |
214 | 214 |
int poll_fd(int fd, int timeout_sec, int check_signals) |
215 | 215 |
{ |
216 | 216 |
int ret; |
217 |
- struct fd_data fds; |
|
217 |
+ struct fd_data fds = FDS_INIT; |
|
218 | 218 |
|
219 |
- memset(&fds, 0, sizeof(fds)); |
|
220 | 219 |
if (fds_add(&fds, fd, 1) == -1) |
221 | 220 |
return -1; |
221 |
+ pthread_mutex_lock(&fds.buf_mutex); |
|
222 | 222 |
ret = fds_poll_recv(&fds, timeout_sec, check_signals); |
223 |
+ pthread_mutex_unlock(&fds.buf_mutex); |
|
223 | 224 |
fds_free(&fds); |
224 | 225 |
return ret; |
225 | 226 |
} |
... | ... |
@@ -66,6 +66,12 @@ struct fd_data { |
66 | 66 |
#endif |
67 | 67 |
}; |
68 | 68 |
|
69 |
+#ifdef HAVE_POLL |
|
70 |
+#define FDS_INIT { PTHREAD_MUTEX_INITIALIZER, NULL, 0, NULL, 0} |
|
71 |
+#else |
|
72 |
+#define FDS_INIT { PTHREAD_MUTEX_INITIALIZER, NULL, 0} |
|
73 |
+#endif |
|
74 |
+ |
|
69 | 75 |
int poll_fd(int fd, int timeout_sec, int check_signals); |
70 | 76 |
void virusaction(const char *filename, const char *virname, const struct optstruct *opts); |
71 | 77 |
int writen(int fd, void *buff, unsigned int count); |
... | ... |
@@ -283,6 +283,8 @@ struct acceptdata { |
283 | 283 |
int syncpipe_wake_accept[2]; |
284 | 284 |
}; |
285 | 285 |
|
286 |
+#define ACCEPTDATA_INIT { FDS_INIT, FDS_INIT, {-1, -1}, {-1, -1} } |
|
287 |
+ |
|
286 | 288 |
static void *acceptloop_th(void *arg) |
287 | 289 |
{ |
288 | 290 |
#ifdef HAVE_STRERROR_R |
... | ... |
@@ -419,7 +421,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi |
419 | 419 |
uint64_t val64; |
420 | 420 |
size_t i, j, rr_last = 0; |
421 | 421 |
pthread_t accept_th; |
422 |
- struct acceptdata acceptdata; |
|
422 |
+ struct acceptdata acceptdata = ACCEPTDATA_INIT; |
|
423 | 423 |
struct fd_data *fds = &acceptdata.recv_fds; |
424 | 424 |
time_t start_time, current_time; |
425 | 425 |
unsigned int selfchk; |
... | ... |
@@ -722,8 +724,6 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi |
722 | 722 |
|
723 | 723 |
idletimeout = optget(opts, "IdleTimeout")->numarg; |
724 | 724 |
|
725 |
- memset(&acceptdata, 0, sizeof(acceptdata)); |
|
726 |
- |
|
727 | 725 |
for (i=0;i < nsockets;i++) |
728 | 726 |
if (fds_add(&acceptdata.fds, socketds[i], 1) == -1) { |
729 | 727 |
logg("!fds_add failed\n"); |