~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to clamd/session.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  MA 02110-1301, USA.
19
19
 */
20
20
 
21
 
#ifdef  _MSC_VER
22
 
#include <winsock.h>
23
 
#endif
24
 
 
25
21
#if HAVE_CONFIG_H
26
22
#include "clamav-config.h"
27
23
#endif
33
29
#include <unistd.h>
34
30
#endif
35
31
#include <sys/types.h>
36
 
#ifndef C_WINDOWS
37
32
#include <dirent.h>
 
33
#ifndef _WIN32
 
34
#include <sys/socket.h>
38
35
#ifdef HAVE_SYS_SELECT_H
39
36
#include <sys/select.h>
40
37
#endif
41
 
#include <sys/socket.h>
42
38
#ifdef HAVE_FD_PASSING
43
39
#ifdef HAVE_SYS_UIO_H
44
40
#include <sys/uio.h>
192
188
    struct scan_cb_data scandata;
193
189
    struct cli_ftw_cbdata data;
194
190
    unsigned ok, error, total;
 
191
    struct stat sb;
195
192
    jobgroup_t *group = NULL;
196
193
 
197
194
    if (thrmgr_group_need_terminate(conn->group)) {
223
220
            thrmgr_setactivetask(NULL, "CONTSCAN");
224
221
            type = TYPE_CONTSCAN;
225
222
            break;
226
 
        case COMMAND_MULTISCAN:
 
223
        case COMMAND_MULTISCAN: {
 
224
            int multiscan, max, alive;
 
225
            pthread_mutex_lock(&conn->thrpool->pool_mutex);
 
226
            multiscan = conn->thrpool->thr_multiscan;
 
227
            max = conn->thrpool->thr_max;
 
228
            if (multiscan+1 < max)
 
229
                conn->thrpool->thr_multiscan = multiscan+1;
 
230
            else {
 
231
                alive = conn->thrpool->thr_alive;
 
232
                ret = -1;
 
233
            }
 
234
            pthread_mutex_unlock(&conn->thrpool->pool_mutex);
 
235
            if (ret) {
 
236
                /* multiscan has 1 control thread, so there needs to be at least
 
237
                   1 threads that is a non-multiscan controlthread to scan and
 
238
                   make progress. */
 
239
                logg("^Not enough threads for multiscan. Max: %d, Alive: %d, Multiscan: %d+1\n",
 
240
                     max, alive, multiscan);
 
241
                conn_reply(conn, conn->filename, "Not enough threads for multiscan. Increase MaxThreads.", "ERROR");
 
242
                return 1;
 
243
            }
227
244
            flags &= ~CLI_FTW_NEED_STAT;
228
245
            thrmgr_setactivetask(NULL, "MULTISCAN");
229
246
            type = TYPE_MULTISCAN;
231
248
            if (!group)
232
249
                return CL_EMEM;
233
250
            break;
 
251
            }
234
252
        case COMMAND_MULTISCANFILE:
235
253
            thrmgr_setactivetask(NULL, "MULTISCANFILE");
236
254
            scandata.group = NULL;
316
334
        flags |= CLI_FTW_FOLLOW_DIR_SYMLINK;
317
335
    if (optget(opts, "FollowFileSymlinks")->enabled)
318
336
        flags |= CLI_FTW_FOLLOW_FILE_SYMLINK;
 
337
 
 
338
    if(!optget(opts, "CrossFilesystems")->enabled)
 
339
        if(stat(conn->filename, &sb) == 0)
 
340
            scandata.dev = sb.st_dev;
 
341
 
319
342
    ret = cli_ftw(conn->filename, flags,  maxdirrec ? maxdirrec : INT_MAX, scan_callback, &data, scan_pathchk);
320
343
    if (ret == CL_EMEM)
321
344
        if(optget(opts, "ExitOnOOM")->enabled)
322
345
            return -1;
323
346
    if (scandata.group && conn->cmdtype == COMMAND_MULTISCAN) {
324
347
        thrmgr_group_waitforall(group, &ok, &error, &total);
 
348
        pthread_mutex_lock(&conn->thrpool->pool_mutex);
 
349
        conn->thrpool->thr_multiscan--;
 
350
        pthread_mutex_unlock(&conn->thrpool->pool_mutex);
325
351
    } else {
326
352
        error = scandata.errors;
327
353
        total = scandata.total;
342
368
static int dispatch_command(client_conn_t *conn, enum commands cmd, const char *argument)
343
369
{
344
370
    int ret = 0;
 
371
    int bulk;
345
372
    client_conn_t *dup_conn = (client_conn_t *) malloc(sizeof(struct client_conn_tag));
346
373
 
347
374
    if(!dup_conn) {
356
383
        return -1;
357
384
    }
358
385
    dup_conn->scanfd = -1;
 
386
    bulk = 1;
359
387
    switch (cmd) {
360
388
        case COMMAND_FILDES:
361
389
            if (conn->scanfd == -1) {
381
409
            break;
382
410
        case COMMAND_STREAM:
383
411
        case COMMAND_STATS:
 
412
            /* not a scan command, don't queue to bulk */
 
413
            bulk = 0;
384
414
            /* just dispatch the command */
385
415
            break;
386
416
    }
387
 
    if(!ret && !thrmgr_group_dispatch(dup_conn->thrpool, dup_conn->group, dup_conn)) {
 
417
    if (!dup_conn->group)
 
418
        bulk = 0;
 
419
    if(!ret && !thrmgr_group_dispatch(dup_conn->thrpool, dup_conn->group, dup_conn, bulk)) {
388
420
        logg("!thread dispatch failed\n");
389
421
        ret = -2;
390
422
    }