Changeset 1657


Ignore:
Timestamp:
Jan 12, 2007, 4:47:48 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • Change timing functions to gettimeofday() instead of time() for more precision.
Location:
zzuf/trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/Makefile.am

    • Property svn:keywords set to Id
    r1521 r1657  
     1# $Id$
    12
    23SUBDIRS = src test doc
  • zzuf/trunk/src/Makefile.am

    • Property svn:keywords set to Id
    r1639 r1657  
     1# $Id$
     2
    13COMMON = random.c random.h fd.c fd.h fuzz.c fuzz.h
    24
    35bin_PROGRAMS = zzuf
    4 zzuf_SOURCES = zzuf.c $(COMMON) md5.c md5.h
     6zzuf_SOURCES = zzuf.c $(COMMON) md5.c md5.h timer.c timer.h
    57zzuf_CFLAGS = -DLIBDIR=\"$(libdir)/zzuf\"
    68
  • zzuf/trunk/src/zzuf.c

    r1655 r1657  
    3434#include <errno.h>
    3535#include <signal.h>
    36 #include <sys/time.h>
    37 #include <time.h>
    3836#include <sys/wait.h>
    3937#include <sys/time.h>
     
    4543#include "fuzz.h"
    4644#include "md5.h"
     45#include "timer.h"
    4746
    4847static void spawn_child(char **);
     
    7271    int fd[3]; /* 0 is debug, 1 is stderr, 2 is stdout */
    7372    int bytes, seed;
    74     time_t date;
     73    int64_t date;
    7574    struct md5 *ctx;
    7675} *child_list;
     
    8483static int checkexit = 0;
    8584static int maxmem = -1;
    86 static double maxtime = -1.0;
     85static int64_t maxtime = -1;
    8786
    8887#define ZZUF_FD_SET(fd, p_fdset, maxfd) \
     
    215214            break;
    216215        case 'T': /* --max-time */
    217             maxtime = atof(optarg);
     216            maxtime = (int64_t)(atof(optarg) * 1000000.0);
    218217            break;
    219218        case 'x': /* --check-exit */
     
    469468
    470469    /* We’re the parent, acknowledge spawn */
    471     child_list[i].date = time(NULL);
     470    child_list[i].date = _zz_time();
    472471    child_list[i].pid = pid;
    473472    for(j = 0; j < 3; j++)
     
    487486static void clean_children(void)
    488487{
    489     time_t now = time(NULL);
     488    int64_t now = _zz_time();
    490489    int i, j;
    491490
     
    504503
    505504        if(child_list[i].status == STATUS_RUNNING
    506             && maxtime >= 0.0
    507             && difftime(now, child_list[i].date) > maxtime)
     505            && maxtime >= 0
     506            && now > child_list[i].date + maxtime)
    508507        {
    509508            fprintf(stdout, "zzuf[seed=%i]: time exceeded, sending SIGTERM\n",
     
    515514    }
    516515
    517     /* Kill children if necessary */
     516    /* Kill children if necessary (still there after 2 seconds) */
    518517    for(i = 0; i < maxforks; i++)
    519518    {
    520519        if(child_list[i].status == STATUS_SIGTERM
    521             && difftime(now, child_list[i].date) > 2.0)
     520            && now > child_list[i].date + 2000000)
    522521        {
    523522            fprintf(stdout, "zzuf[seed=%i]: not responding, sending SIGKILL\n",
Note: See TracChangeset for help on using the changeset viewer.