From 4f5a740806e92b52be1a58878a6588b60588082c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B6r=C3=B6k=20Edvin?= Date: Fri, 9 Jan 2009 19:56:07 +0000 Subject: [PATCH] fix accept logic git-svn-id: file:///var/lib/svn/clamav-devel/branches/clamd-proto@4600 77e5149b-7576-45b1-b177-96237e5ba77b --- ChangeLog | 4 ++++ clamd/others.c | 3 ++- clamd/server-th.c | 8 ++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9ced016e4..f668fd66f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri Jan 9 21:11:54 EET 2009 (edwin) +------------------------------------ + * clamd/others.c, clamd/server-th.c: fix accept logic + Fri Jan 9 21:04:57 EET 2009 (edwin) ------------------------------------ * clamd/others.c, clamd/server-th.c, clamd/server.h, diff --git a/clamd/others.c b/clamd/others.c index 0c18c0ed8..9bb4fbdf1 100644 --- a/clamd/others.c +++ b/clamd/others.c @@ -478,6 +478,8 @@ static void cleanup_fds(struct fd_data *data) static int read_fd_data(struct fd_buf *buf) { ssize_t n; + + buf->got_newdata=1; if (!buf->buffer) /* listen-only socket */ return 0; /* Read the pending packet, it may contain more than one command, but @@ -488,7 +490,6 @@ static int read_fd_data(struct fd_buf *buf) if (n < 0) return -1; buf->off += n; - buf->got_newdata=1; return n; } diff --git a/clamd/server-th.c b/clamd/server-th.c index 05aca4720..16a83e251 100644 --- a/clamd/server-th.c +++ b/clamd/server-th.c @@ -660,6 +660,8 @@ int acceptloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, un for (i=0;i < fds.nfds && new_sd >= 0; i++) { struct fd_buf *buf = &fds.buf[i]; + if (!buf->got_newdata) + continue; if (!buf->buffer) { /* listen only socket */ new_sd = accept(fds.buf[i].fd, NULL, NULL); @@ -686,7 +688,7 @@ int acceptloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, un #endif continue; } - } else if (buf->fd != -1 && buf->got_newdata) { + } else if (buf->fd != -1) { const char *cmd; size_t cmdlen = 0; size_t pos = 0; @@ -695,6 +697,7 @@ int acceptloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, un /* Parse & dispatch commands */ while ((cmd = get_cmd(buf, pos, &cmdlen)) != NULL) { + printf("%s\n",cmd); client_conn = (client_conn_t *) malloc(sizeof(struct client_conn_tag)); if(client_conn) { client_conn->sd = buf->fd; @@ -744,7 +747,8 @@ int acceptloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, un if (pos < buf->off) { memmove (buf->buffer, &buf->buffer[pos], buf->off - pos); buf->off -= pos; - } + } else + buf->off = 0; } }