From 3021258f6064a7bdb46bb2e039a093230650b408 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Wed, 18 Mar 2015 15:21:55 -0500 Subject: [PATCH] Add tests/bin/intr This utility, inspired by the old SunOS 4.x intr(8) utility, will be used to start daemons with --detach and a timeout, like this: intr -t 5 kdc --detach || { echo failed to start kdc; exit 1 } This will allow tests to stop having to sleep poll for "started" output from the daemons they start, allowing them to run faster and to impose a reasonable timeout on daemon startup. The default timeout is 3 seconds. --- tests/bin/Makefile.am | 8 +++++++ tests/bin/intr.c | 56 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/bin/intr.c diff --git a/tests/bin/Makefile.am b/tests/bin/Makefile.am index 52b7f15d6..914493fbe 100644 --- a/tests/bin/Makefile.am +++ b/tests/bin/Makefile.am @@ -2,6 +2,14 @@ include $(top_srcdir)/Makefile.am.common noinst_SCRIPTS = setup-env +noinst_PROGRAMS = intr + +nodist_intr_SOURCES = intr.c + +CHECK_LOCAL = no-check-local + +intr_LDADD = $(LIB_roken) + do_subst = \ top_srcdir="$$(cd ${top_srcdir} && pwd)" ; \ top_builddir="$$(cd ${top_builddir} && pwd)" ; \ diff --git a/tests/bin/intr.c b/tests/bin/intr.c new file mode 100644 index 000000000..867c5c295 --- /dev/null +++ b/tests/bin/intr.c @@ -0,0 +1,56 @@ +#include + +#include +#include +#include + +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); +}