Add tests/bin/intr
[heimdal.git] / tests / bin / intr.c
blob867c5c295e08047fb27cd26c781c368794b7f171
1 #include <config.h>
3 #include <getarg.h>
4 #include <roken.h>
5 #include <time.h>
7 static int help_flag;
8 static int timeout = 3;
10 static struct getargs args[] = {
11 { "help", 'h', arg_flag, &help_flag, NULL, NULL },
12 { "timeout", 't', arg_integer, &timeout, NULL, NULL }
15 static int nargs = sizeof(args) / sizeof(args[0]);
17 static time_t
18 handle_timeout(void *data)
20 static int killed;
22 if (!killed++)
23 return -1; /* kill it */
24 return -2; /* stop waiting for it */
27 static void
28 usage(int status)
30 arg_printusage(args, nargs, NULL, "command");
31 exit(status);
35 int
36 main(int argc, char **argv)
38 int optidx = 0;
40 setprogname(argv[0]);
42 if (getarg(args, nargs, argc, argv, &optidx))
43 usage(1);
45 if (help_flag)
46 usage(0);
48 argc -= optidx;
49 argv += optidx;
51 if (argc == 0)
52 usage(1);
54 return simple_execvp_timed(argv[0], argv, handle_timeout, NULL,
55 timeout);