Debian Codegraph @

tests/bin/intr.c

raw
1 #include <config.h>
2
3 #include <getarg.h>
4 #include <roken.h>
5 #include <time.h>
6
7 static int help_flag;
8 static int timeout = 3;
9
10 static struct getargs args[] = {
11 { "help", 'h', arg_flag, &help_flag, NULL, NULL },
12 { "timeout", 't', arg_integer, &timeout, NULL, NULL }
13 };
14
15 static int nargs = sizeof(args) / sizeof(args[0]);
16
17 static time_t
18 handle_timeout(void *data)
19 {
20 static int killed;
21
22 if (!killed++)
23 return -1; /* kill it */
24 return -2; /* stop waiting for it */
25 }
26
27 static void
28 usage(int status)
29 {
30 arg_printusage(args, nargs, NULL, "command");
31 exit(status);
32 }
33
34
35 int
36 main(int argc, char **argv)
37 {
38 int optidx = 0;
39
40 setprogname(argv[0]);
41
42 if (getarg(args, nargs, argc, argv, &optidx))
43 usage(1);
44
45 if (help_flag)
46 usage(0);
47
48 argc -= optidx;
49 argv += optidx;
50
51 if (argc == 0)
52 usage(1);
53
54 return simple_execvp_timed(argv[0], argv, handle_timeout, NULL,
55 timeout);
56 }