~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to freshclam/execute.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20070220103344-zgcu2psnx9d98fpa
Tags: upstream-0.90
ImportĀ upstreamĀ versionĀ 0.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  By Per Jessen <per@computer.org> with changes by the ClamAV team
 
2
 *  By Per Jessen <per@computer.org>
3
3
 *
4
4
 *  This program is free software; you can redistribute it and/or modify
5
5
 *  it under the terms of the GNU General Public License as published by
23
23
 
24
24
#include <stdio.h>
25
25
#include <stdlib.h>
26
 
#ifdef  HAVE_UNISTD_H
27
26
#include <unistd.h>
28
 
#endif
29
27
#include <string.h>
30
28
#include <errno.h>
31
29
 
32
30
#include "shared/output.h"
33
 
#include "shared/optparser.h"
34
31
#include "execute.h"
35
32
 
36
33
#define MAX_CHILDREN 5
37
34
 
38
35
int active_children;
39
36
 
40
 
void execute( const char *type, const char *text, const struct optstruct *opts )
 
37
void execute( const char *type, const char *text )
41
38
{
42
 
        int ret;
43
 
 
44
 
    if(!optget(opts, "daemon")->enabled) {
45
 
        if(sscanf(text, "EXIT_%d", &ret) == 1) {
46
 
            logg("*%s: EXIT_%d\n", type, ret);
47
 
            exit(ret);
48
 
        }
49
 
        if(system(text) == -1)
50
 
            logg("%s: system(%s) failed\n", type, text);
51
 
 
52
 
        return;
53
 
    }
54
 
 
55
 
#ifdef _WIN32
56
 
    if(spawnlp(_P_NOWAIT, text, text, NULL) == -1) {
57
 
        logg("^%s: couldn't execute \"%s\".\n", type, text);
58
 
        return;
59
 
    }
60
 
#else
61
 
    if ( active_children<MAX_CHILDREN ) {
62
39
        pid_t pid;
 
40
 
 
41
        if ( active_children<MAX_CHILDREN )
63
42
        switch( pid=fork() ) {
64
43
        case 0:
65
44
                if ( -1==system(text) )
73
52
        default:
74
53
                active_children++;
75
54
        }
76
 
    } else {
 
55
        else
 
56
        {
77
57
                logg("^%s: already %d processes active.\n", type, active_children);
78
 
    }
79
 
#endif
 
58
        }
80
59
}