1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*
* By Per Jessen <per@computer.org> with changes by the ClamAV team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#include <errno.h>
#ifdef C_WINDOWS
#include <process.h>
#endif
#include "shared/output.h"
#include "shared/optparser.h"
#include "execute.h"
#define MAX_CHILDREN 5
int active_children;
void execute( const char *type, const char *text, const struct optstruct *opts )
{
int ret;
#ifndef C_WINDOWS
pid_t pid;
#endif
if(!optget(opts, "daemon")->enabled) {
if(sscanf(text, "EXIT_%d", &ret) == 1) {
logg("*%s: EXIT_%d\n", type, ret);
exit(ret);
}
if(system(text) == -1)
logg("%s: system(%s) failed\n", type, text);
return;
}
#ifdef C_WINDOWS
if(active_children < MAX_CHILDREN) {
if(spawnlp(P_DETACH, text, text, NULL) == -1) {
logg("^%s: couldn't execute \"%s\".\n", type, text);
return;
}
active_children++; /* FIXME: this is never reduced */
} else
logg("^%s: already %d processes active.\n", type, active_children);
#else
if ( active_children<MAX_CHILDREN )
switch( pid=fork() ) {
case 0:
if ( -1==system(text) )
{
logg("^%s: couldn't execute \"%s\".\n", type, text);
}
exit(0);
case -1:
logg("^%s::fork() failed, %s.\n", type, strerror(errno));
break;
default:
active_children++;
}
else
{
logg("^%s: already %d processes active.\n", type, active_children);
}
#endif
}
|