tst_test: Propagate SIGINT to test process

Since the test runs in separate process and separate process group
pressing Ctrl+C only sends SIGINT to the library process.

This commit adds SIGINT handler for the library process that kills the
whole test process group. The upside is that system resources allocated
in the library are cleaned up even in this case.

We also reset signal handlers in the test process after the fork now.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Acked-by: Jan Stancek <jstancek@redhat.com>
diff --git a/lib/tst_test.c b/lib/tst_test.c
index a94bccd..12ca051 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -724,6 +724,18 @@
 	alarm(results->timeout);
 }
 
+#define SIGINT_MSG "Sending SIGKILL to test process...\n"
+
+static void sigint_handler(int sig LTP_ATTRIBUTE_UNUSED)
+{
+	if (test_pid > 0) {
+		if (write(2, SIGINT_MSG, sizeof(SIGINT_MSG) - 1)) {
+			/* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 */
+		}
+		kill(-test_pid, SIGKILL);
+	}
+}
+
 void tst_set_timeout(unsigned int timeout)
 {
 	char *mul = getenv("LTP_TIMEOUT_MUL");
@@ -767,18 +779,23 @@
 	else
 		tst_set_timeout(300);
 
+	SAFE_SIGNAL(SIGINT, sigint_handler);
+
 	test_pid = fork();
 	if (test_pid < 0)
 		tst_brk(TBROK | TERRNO, "fork()");
 
 	if (!test_pid) {
+		SAFE_SIGNAL(SIGALRM, SIG_DFL);
+		SAFE_SIGNAL(SIGUSR1, SIG_DFL);
+		SAFE_SIGNAL(SIGINT, SIG_DFL);
 		SAFE_SETPGID(0, 0);
 		testrun();
 	}
 
 	SAFE_WAITPID(test_pid, &status, 0);
-
 	alarm(0);
+	SAFE_SIGNAL(SIGINT, SIG_DFL);
 
 	if (WIFEXITED(status) && WEXITSTATUS(status))
 		do_exit(WEXITSTATUS(status));