va_end(va);
}
-static TEST_PRINTF(1, 2) NORETURN void die(const char *fmt, ...)
+static void die_test_cleanup(void)
{
- va_list va;
+ struct gpiotool_proc *proc = &globals.test_ctx.tool_proc;
+ int status;
+
+ if (proc->running) {
+ kill(proc->pid, SIGKILL);
+ waitpid(proc->pid, &status, 0);
+ }
if (globals.test_ctx.running)
pr_raw("\n");
+}
+
+static TEST_PRINTF(1, 2) NORETURN void die(const char *fmt, ...)
+{
+ va_list va;
+
+ die_test_cleanup();
va_start(va, fmt);
vmsg("FATAL", CRED, fmt, va);
{
va_list va;
- if (globals.test_ctx.running)
- pr_raw("\n");
+ die_test_cleanup();
va_start(va, fmt);
vmsgn("FATAL", CRED, fmt, va);
pfd.events = POLLIN | POLLPRI;
status = poll(&pfd, 1, 5000);
- if (status == 0) {
- /*
- * If a tool program is taking longer than 5 seconds to
- * terminate, then something's wrong. Kill it before dying.
- */
- test_tool_signal(SIGKILL);
+ if (status == 0)
die("tool program is taking too long to terminate");
- } else if (status < 0) {
- /* Error in poll() - we still need to kill the process. */
- test_tool_signal(SIGKILL);
+ else if (status < 0)
die_perr("error when polling the signalfd");
- }
rd = read(proc->sig_fd, &sinfo, sizeof(sinfo));
close(proc->sig_fd);