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