* Only display our own kills in verbose mode.

* Factorise min/max ratio values.
This commit is contained in:
Sam Hocevar 2007-01-14 20:17:45 +00:00 committed by sam
parent cb6226ea65
commit 5f6aa51632
3 changed files with 40 additions and 18 deletions

View File

@ -53,8 +53,8 @@ static struct files
static int *fds, static_fds[STATIC_FILES];
static int maxfd, nfiles;
static int32_t seed = 0;
static float ratio = 0.004f;
static int32_t seed = DEFAULT_SEED;
static float ratio = DEFAULT_RATIO;
static int autoinc = 0;
void _zz_include(char const *regex)
@ -76,10 +76,10 @@ void _zz_setseed(int32_t s)
void _zz_setratio(float r)
{
if(r < 0.0f)
r = 0.0f;
else if(r > 5.0f)
r = 5.0f;
if(r < MIN_RATIO)
r = MIN_RATIO;
else if(r > MAX_RATIO)
r = MAX_RATIO;
ratio = r;
}

View File

@ -25,6 +25,14 @@
* any part of the file without reading the whole file. */
#define CHUNKBYTES 1024
/* Default seed is 0. Why not? */
#define DEFAULT_SEED 0
/* The default fuzzing ratio is, arbitrarily, 0.4% */
#define DEFAULT_RATIO 0.004f
#define MIN_RATIO 0.00001f
#define MAX_RATIO 5.0f
struct fuzz
{
uint32_t seed;

View File

@ -80,8 +80,10 @@ static int maxforks = 1, child_count = 0, maxcrashes = 1, crashes = 0;
static char **newargv;
static char *protect = NULL, *refuse = NULL;
static int seed = 0;
static int endseed = 1;
static uint32_t seed = DEFAULT_SEED;
static uint32_t endseed = DEFAULT_SEED + 1;
static float ratio = DEFAULT_RATIO;
static float endratio = DEFAULT_RATIO;
static int quiet = 0;
static int maxbytes = -1;
static int md5 = 0;
@ -214,16 +216,17 @@ int main(int argc, char *argv[])
quiet = 1;
break;
case 'r': /* --ratio */
setenv("ZZUF_RATIO", optarg, 1);
_zz_setratio(atof(optarg));
parser = strchr(optarg, ':');
ratio = atof(optarg);
endratio = parser ? atof(parser + 1) : ratio;
break;
case 'R': /* --refuse */
refuse = optarg;
break;
case 's': /* --seed */
parser = strchr(optarg, ':');
_zz_setseed(seed = atol(optarg));
endseed = parser ? atoi(parser + 1) : seed + 1;
seed = atol(optarg);
endseed = parser ? (uint32_t)atoi(parser + 1) : seed + 1;
break;
case 'S': /* --signal */
setenv("ZZUF_SIGNAL", "1", 1);
@ -265,6 +268,9 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
_zz_setseed(seed);
_zz_setratio(ratio);
loop_stdin();
return EXIT_SUCCESS;
@ -501,6 +507,8 @@ static void spawn_children(void)
/* Set environment variables */
sprintf(buf, "%i", seed);
setenv("ZZUF_SEED", buf, 1);
sprintf(buf, "%g", ratio);
setenv("ZZUF_RATIO", buf, 1);
/* Run our process */
if(execvp(newargv[0], newargv))
@ -511,6 +519,9 @@ static void spawn_children(void)
return;
}
if(verbose)
fprintf(stdout, "zzuf[seed=%i]: launched %s\n", seed, newargv[0]);
/* Were the parent, acknowledge spawn */
child_list[i].date = now;
child_list[i].pid = pid;
@ -541,8 +552,9 @@ static void clean_children(void)
if(child_list[i].status == STATUS_RUNNING
&& maxbytes >= 0 && child_list[i].bytes > maxbytes)
{
fprintf(stdout, "zzuf[seed=%i]: data output exceeded, sending SIGTERM\n",
child_list[i].seed);
if(verbose)
fprintf(stdout, "zzuf[seed=%i]: data output exceeded,"
" sending SIGTERM\n", child_list[i].seed);
kill(child_list[i].pid, SIGTERM);
child_list[i].date = now;
child_list[i].status = STATUS_SIGTERM;
@ -552,8 +564,9 @@ static void clean_children(void)
&& maxtime >= 0
&& now > child_list[i].date + maxtime)
{
fprintf(stdout, "zzuf[seed=%i]: running time exceeded, sending SIGTERM\n",
child_list[i].seed);
if(verbose)
fprintf(stdout, "zzuf[seed=%i]: running time exceeded,"
" sending SIGTERM\n", child_list[i].seed);
kill(child_list[i].pid, SIGTERM);
child_list[i].date = now;
child_list[i].status = STATUS_SIGTERM;
@ -566,8 +579,9 @@ static void clean_children(void)
if(child_list[i].status == STATUS_SIGTERM
&& now > child_list[i].date + 2000000)
{
fprintf(stdout, "zzuf[seed=%i]: not responding, sending SIGKILL\n",
child_list[i].seed);
if(verbose)
fprintf(stdout, "zzuf[seed=%i]: not responding,"
" sending SIGKILL\n", child_list[i].seed);
kill(child_list[i].pid, SIGKILL);
child_list[i].status = STATUS_SIGKILL;
}