Changeset 1801 for zzuf/trunk


Ignore:
Timestamp:
Jul 10, 2007, 5:23:18 PM (16 years ago)
Author:
Sam Hocevar
Message:
  • Implemented -T / --max-cpu for max CPU time limits.
Location:
zzuf/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/opts.c

    r1791 r1801  
    4646    opts->maxmem = -1;
    4747    opts->maxtime = -1;
     48    opts->maxcpu = -1;
    4849    opts->delay = 0;
    4950    opts->lastlaunch = 0;
  • zzuf/trunk/src/opts.h

    r1791 r1801  
    2828    int quiet;
    2929    int maxbytes;
     30    int maxcpu;
    3031    int md5;
    3132    int checkexit;
  • zzuf/trunk/src/zzuf.c

    r1800 r1801  
    163163#   define OPTSTR_RLIMIT_MEM ""
    164164#endif
    165 #define OPTSTR OPTSTR_REGEX OPTSTR_RLIMIT_MEM \
    166             "Ab:B:C:dD:f:F:imnp:P:qr:R:s:St:vxhV"
     165#if defined HAVE_SETRLIMIT && defined ZZUF_RLIMIT_CPU
     166#   define OPTSTR_RLIMIT_CPU "T:"
     167#else
     168#   define OPTSTR_RLIMIT_CPU ""
     169#endif
     170#define OPTSTR OPTSTR_REGEX OPTSTR_RLIMIT_MEM OPTSTR_RLIMIT_CPU \
     171                "Ab:B:C:dD:f:F:imnp:P:qr:R:s:St:vxhV"
    167172#define MOREINFO "Try `%s --help' for more information.\n"
    168173        int option_index = 0;
     
    199204            { "signal",      0, NULL, 'S' },
    200205            { "max-time",    1, NULL, 't' },
     206            { "max-cpu",     1, NULL, 'T' },
    201207            { "verbose",     0, NULL, 'v' },
    202208            { "check-exit",  0, NULL, 'x' },
     
    310316            opts->maxtime = (int64_t)(atof(myoptarg) * 1000000.0);
    311317            break;
     318#if defined HAVE_SETRLIMIT && defined ZZUF_RLIMIT_CPU
     319        case 'T': /* --max-cpu */
     320            opts->maxcpu = (int)(atof(myoptarg) + 0.5);
     321            break;
     322#endif
    312323        case 'x': /* --check-exit */
    313324            opts->checkexit = 1;
     
    706717                       && opts->child[i].status == STATUS_SIGTERM))
    707718        {
     719            char const *message = "";
     720
     721            if(WTERMSIG(status) == SIGKILL && opts->maxmem >= 0)
     722                message = " (memory exceeded?)";
     723#   if defined SIGXCPU
     724            else if(WTERMSIG(status) == SIGXCPU && opts->maxcpu >= 0)
     725                message = " (CPU time exceeded?)";
     726#   endif
     727            else if(WTERMSIG(status) == SIGKILL && opts->maxcpu >= 0)
     728                message = " (CPU time exceeded?)";
     729
    708730            finfo(stderr, opts, opts->child[i].seed);
    709731            fprintf(stderr, "signal %i%s%s\n",
    710                     WTERMSIG(status), sig2str(WTERMSIG(status)),
    711                       (WTERMSIG(status) == SIGKILL && opts->maxmem >= 0) ?
    712                       " (memory exceeded?)" : "");
     732                    WTERMSIG(status), sig2str(WTERMSIG(status)), message);
    713733            opts->crashes++;
    714734        }
     
    907927#endif
    908928
     929#if defined HAVE_SETRLIMIT && defined ZZUF_RLIMIT_CPU
     930    if(opts->maxcpu >= 0)
     931    {
     932        struct rlimit rlim;
     933        rlim.rlim_cur = opts->maxcpu;
     934        rlim.rlim_max = opts->maxcpu + 5;
     935        setrlimit(ZZUF_RLIMIT_CPU, &rlim);
     936    }
     937#endif
     938
    909939    /* Set environment variables */
    910940    sprintf(buf, "%i", opts->seed);
     
    11101140#endif
    11111141    printf("              [-f fuzzing] [-D delay] [-F forks] [-C crashes] [-B bytes]\n");
     1142    printf("              [-t seconds] ");
     1143#if defined HAVE_SETRLIMIT && defined ZZUF_RLIMIT_CPU
     1144    printf(                           "[-T seconds] ");
     1145#endif
    11121146#if defined HAVE_SETRLIMIT && defined ZZUF_RLIMIT_MEM
    1113     printf("              [-t seconds] [-M bytes] [-b ranges] [-P protect] [-R refuse]\n");
    1114 #else
    1115     printf("              [-t seconds] [-b ranges] [-P protect] [-R refuse]\n");
    1116 #endif
    1117 #if defined HAVE_REGEX_H
    1118     printf("              [-p descriptors] [-I include] [-E exclude]\n");
    1119     printf("              [PROGRAM [--] [ARGS]...]\n");
    1120 #else
    1121     printf("              [-I include] [-E exclude] [PROGRAM [--] [ARGS]...]\n");
    1122 #endif
     1147    printf(                                        "[-M bytes] ");
     1148#endif
     1149    printf(                                                   "[-b ranges] [-P protect]\n");
     1150    printf("              [-R refuse] [-p descriptors] ");
     1151#if defined HAVE_REGEX_H
     1152    printf(                                           "[-I include] [-E exclude]\n");
     1153    printf("              ");
     1154#endif
     1155    printf(              "[PROGRAM [--] [ARGS]...]\n");
    11231156    printf("       zzuf -h | --help\n");
    11241157    printf("       zzuf -V | --version\n");
     
    11591192    printf("  -S, --signal              prevent children from diverting crashing signals\n");
    11601193    printf("  -t, --max-time <n>        kill children that run for more than <n> seconds\n");
     1194    printf("  -T, --max-cpu <n>         kill children that use more than <n> CPU seconds\n");
    11611195    printf("  -v, --verbose             print information during the run\n");
    11621196    printf("  -x, --check-exit          report processes that exit with a non-zero status\n");
Note: See TracChangeset for help on using the changeset viewer.