summaryrefslogtreecommitdiff
path: root/third_party/heimdal/tests/bin/intr.c
blob: 867c5c295e08047fb27cd26c781c368794b7f171 (plain)
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
#include <config.h>

#include <getarg.h>
#include <roken.h>
#include <time.h>

static int help_flag;
static int timeout = 3;

static struct getargs args[] = {
    { "help", 'h', arg_flag, &help_flag, NULL, NULL },
    { "timeout", 't', arg_integer, &timeout, NULL, NULL }
};

static int nargs = sizeof(args) / sizeof(args[0]);

static time_t
handle_timeout(void *data)
{
    static int killed;

    if (!killed++)
        return -1;  /* kill it */
    return -2;      /* stop waiting for it */
}

static void
usage(int status)
{
    arg_printusage(args, nargs, NULL, "command");
    exit(status);
}


int
main(int argc, char **argv)
{
    int optidx = 0;

    setprogname(argv[0]);

    if (getarg(args, nargs, argc, argv, &optidx))
        usage(1);

    if (help_flag)
        usage(0);

    argc -= optidx;
    argv += optidx;

    if (argc == 0)
        usage(1);

    return simple_execvp_timed(argv[0], argv, handle_timeout, NULL,
                               timeout);
}