preliminary IDSESSION support, no IDs yet

git-svn-id: file:///var/lib/svn/clamav-devel/branches/clamd-proto@4671 77e5149b-7576-45b1-b177-96237e5ba77b
remotes/push_mirror/0.95
Török Edvin 17 years ago
parent 28e89f60ca
commit 79b43cf868
  1. 6
      ChangeLog
  2. 1
      clamd/others.c
  3. 2
      clamd/others.h
  4. 7
      clamd/server-th.c
  5. 18
      clamd/session.c
  6. 1
      clamd/session.h
  7. 10
      clamd/thrmgr.c
  8. 1
      clamd/thrmgr.h

@ -1,3 +1,9 @@
Tue Feb 3 23:02:49 EET 2009 (edwin)
------------------------------------
* clamd/others.c, clamd/others.h, clamd/server-th.c,
clamd/session.c, clamd/session.h, clamd/thrmgr.c, clamd/thrmgr.h:
preliminary IDSESSION support, no IDs yet
Tue Feb 3 19:36:07 EET 2009 (edwin)
------------------------------------
* clamd/scanner.c, clamd/server-th.c, clamd/session.c,

@ -387,6 +387,7 @@ int fds_add(struct fd_data *data, int fd, int listen_only)
data->nfds = n;
data->buf[n-1].fd = -1;
data->buf[n-1].recvfd = -1;
data->buf[n-1].group = NULL;
if (!listen_only) {
data->buf[n-1].bufsize = PATH_MAX+8;
/* plus extra space for a \0 so we can make sure every command is \0

@ -25,6 +25,7 @@
#include <stdlib.h>
#include "shared/optparser.h"
#include "thrmgr.h"
struct fd_buf {
unsigned char *buffer;
@ -33,6 +34,7 @@ struct fd_buf {
int fd;
int got_newdata;
int recvfd;
jobgroup_t *group;
};
struct fd_data {

@ -105,7 +105,7 @@ static void scanner_thread(void *arg)
timeout = -1;
ret = command(conn);
if (ret == COMMAND_SHUTDOWN) {
if (ret == -1) {
pthread_mutex_lock(&exit_mutex);
progexit = 1;
pthread_mutex_unlock(&exit_mutex);
@ -799,6 +799,8 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
conn.opts = opts;
conn.thrpool = thr_pool;
conn.engine = engine;
conn.group = buf->group;
conn.id = 0;
/* Parse & dispatch commands */
while ((cmd = get_cmd(buf, pos, &cmdlen, &term)) != NULL) {
int rc;
@ -833,8 +835,9 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
}
conn.scanfd = -1;
pos += cmdlen+1;
conn.id++;
}
buf->group = conn.group;
if (error) {
mdprintf(buf->fd, "ERROR%c", term);
shutdown(buf->fd, 2);

@ -194,7 +194,7 @@ int command(client_conn_t *conn)
if (cli_ftw(conn->filename, CLI_FTW_STD, maxdirrec ? maxdirrec : INT_MAX, scan_callback, &data) == CL_EMEM)
if(optget(opts, "ExitOnOOM")->enabled)
return COMMAND_SHUTDOWN;
if (scandata.group)
if (scandata.group && conn->cmdtype == COMMAND_MULTISCAN)
thrmgr_group_waitforall(&group, &ok, &error, &total);
else {
error = scandata.errors;
@ -300,12 +300,18 @@ int execute_or_dispatch_command(client_conn_t *conn, enum commands cmd, const ch
}
return 1;
}
case COMMAND_FILDES:
case COMMAND_SCAN:
case COMMAND_CONTSCAN:
case COMMAND_STREAM:
case COMMAND_MULTISCAN:
if (conn->group) {
/* these commands are not recognized inside an IDSESSION */
mdprintf(desc, "UNKNOWN COMMAND%c", term);
return 1;
}
/* fall-through */
case COMMAND_STATS:
case COMMAND_FILDES:
case COMMAND_SCAN:
case COMMAND_CONTSCAN:
return dispatch_command(conn, cmd, argument);
case COMMAND_IDSESSION:
if (conn->group) {
@ -313,7 +319,7 @@ int execute_or_dispatch_command(client_conn_t *conn, enum commands cmd, const ch
mdprintf(desc, "UNKNOWN COMMAND%c", term);
return 1;
}
conn->group = calloc(1, sizeof(*conn->group));
conn->group = thrmgr_group_new();
if (!conn->group)
return CL_EMEM;
return 0;
@ -323,6 +329,8 @@ int execute_or_dispatch_command(client_conn_t *conn, enum commands cmd, const ch
mdprintf(desc, "UNKNOWN COMMAND%c", term);
return 1;
}
/* TODO: notify group to free itself on exit */
conn->group = NULL;
return 1;
/*case COMMAND_UNKNOWN:*/
default:

@ -67,6 +67,7 @@ typedef struct client_conn_tag {
char *filename;
int scanfd;
int sd;
int id;
struct fd_data *fds;
unsigned int options;
const struct optstruct *opts;

@ -647,3 +647,13 @@ void thrmgr_group_waitforall(jobgroup_t *group, unsigned *ok, unsigned *error, u
*total = group->exit_total;
pthread_mutex_unlock(&group->mutex);
}
jobgroup_t *thrmgr_group_new(void)
{
jobgroup_t dummy = JOBGROUP_INITIALIZER;
jobgroup_t *group = malloc(sizeof(*group));
if (!group)
return NULL;
memcpy(group, &dummy, sizeof(dummy));
return group;
}

@ -95,6 +95,7 @@ int thrmgr_dispatch(threadpool_t *threadpool, void *user_data);
int thrmgr_group_dispatch(threadpool_t *threadpool, jobgroup_t *group, void *user_data);
void thrmgr_group_waitforall(jobgroup_t *group, unsigned *ok, unsigned *error, unsigned *total);
void thrmgr_group_finished(jobgroup_t *group, enum thrmgr_exit exitc);
jobgroup_t *thrmgr_group_new(void);
int thrmgr_printstats(int outfd);
void thrmgr_setactivetask(const char *filename, const char* command);
void thrmgr_setactiveengine(const struct cl_engine *engine);

Loading…
Cancel
Save