~ubuntu-branches/ubuntu/jaunty/clamav/jaunty-backports

« back to all changes in this revision

Viewing changes to clamd/clamd.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-10-02 17:11:00 UTC
  • mfrom: (0.3.1 lucid-proposed)
  • Revision ID: james.westby@ubuntu.com-20101002171100-0erjjoucua6kw2pc
Tags: 0.96.3+dfsg-2ubuntu0.10.04.1~jaunty1
* Source backport for Jaunty
  - Change build-dep on libtdl-dev to libtdl7-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#endif
31
31
#ifndef _WIN32
32
32
#include <sys/time.h>
 
33
#include <sys/resource.h>
33
34
#endif
34
35
#include <sys/types.h>
35
36
#include <sys/stat.h>
42
43
#include <grp.h>
43
44
#endif
44
45
#include <signal.h>
 
46
#include <errno.h>
45
47
 
46
48
#if defined(USE_SYSLOG) && !defined(C_AIX)
47
49
#include <syslog.h>
107
109
#ifndef _WIN32
108
110
        struct passwd *user = NULL;
109
111
        struct sigaction sa;
 
112
        struct rlimit rlim;
110
113
#endif
111
114
        time_t currtime;
112
115
        const char *dbdir, *cfgfile;
294
297
        logg("#Running as user %s (UID %u, GID %u)\n", user->pw_name, user->pw_uid, user->pw_gid);
295
298
#endif
296
299
 
 
300
#if defined(RLIMIT_DATA) && defined(C_BSD)
 
301
    if (getrlimit(RLIMIT_DATA, &rlim) == 0) {
 
302
       /* bb #1941.
 
303
        * On 32-bit FreeBSD if you set ulimit -d to >2GB then mmap() will fail
 
304
        * too soon (after ~120 MB).
 
305
        * Set limit lower than 2G if on 32-bit */
 
306
       uint64_t lim = rlim.rlim_cur;
 
307
       lim = (int32_t) lim;
 
308
       if (sizeof(void*) == 4 &&
 
309
           lim != rlim.rlim_cur) {
 
310
           rlim.rlim_cur = 2048*1024-1;
 
311
           if (setrlimit(RLIMIT_DATA, &rlim) < 0)
 
312
               logg("!setrlimit(RLIMIT_DATA) failed: %s\n", strerror(errno));
 
313
           else
 
314
               logg("^Running on 32-bit system, and RLIMIT_DATA > 2GB, lowering to 2GB!\n");
 
315
       }
 
316
    }
 
317
#endif
 
318
 
 
319
 
297
320
    if(logg_size)
298
321
        logg("#Log file size limited to %d bytes.\n", logg_size);
299
322
    else
431
454
            break;
432
455
        }
433
456
    }
 
457
    if((opt = optget(opts,"BytecodeMode"))->enabled) {
 
458
        enum bytecode_mode mode;
 
459
        if (!strcmp(opt->strarg, "ForceJIT"))
 
460
            mode = CL_BYTECODE_MODE_JIT;
 
461
        else if(!strcmp(opt->strarg, "ForceInterpreter"))
 
462
            mode = CL_BYTECODE_MODE_INTERPRETER;
 
463
        else if(!strcmp(opt->strarg, "Test"))
 
464
            mode = CL_BYTECODE_MODE_TEST;
 
465
        else
 
466
            mode = CL_BYTECODE_MODE_AUTO;
 
467
        cl_engine_set_num(engine, CL_ENGINE_BYTECODE_MODE, mode);
 
468
    }
434
469
    if((opt = optget(opts,"BytecodeTimeout"))->enabled) {
435
470
        cl_engine_set_num(engine, CL_ENGINE_BYTECODE_TIMEOUT, opt->numarg);
436
471
    }
528
563
        gengine = engine;
529
564
        atexit(free_engine);
530
565
        if(daemonize() == -1) {
531
 
            logg("!daemonize() failed\n");
 
566
            logg("!daemonize() failed: %s\n", strerror(errno));
532
567
            ret = 1;
533
568
            break;
534
569
        }