From 40d6f19ff9c1d052c860365a98a8a074d5671142 Mon Sep 17 00:00:00 2001 From: Imre Deak Date: Fri, 13 Oct 2017 14:30:08 +0300 Subject: aux: Suspend signal helper for shell commands The clone() system call with a larger executable (like /bin/sh) may have difficulty to make progress on some platforms if interrupted frequently. So suspend the signal helper process for the duration of the syscall. This is needed to solve an actual problem by the next patch. v2: - Clarify/fix code comments. (Chris) - Update igt_system_quiet() as well accordingly. Cc: Chris Wilson Cc: Daniel Vetter Signed-off-by: Imre Deak Reviewed-by: Chris Wilson (v1) --- lib/igt_aux.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'lib/igt_aux.c') diff --git a/lib/igt_aux.c b/lib/igt_aux.c index fa6594c3..8dde9a12 100644 --- a/lib/igt_aux.c +++ b/lib/igt_aux.c @@ -350,6 +350,44 @@ void igt_stop_signal_helper(void) sig_stat = 0; } +/** + * igt_suspend_signal_helper: + * + * Suspends the child process spawned with igt_fork_signal_helper(). This + * should be called before a critical section of code that has difficulty to + * make progress if interrupted frequently, like the clone() syscall called + * from a largish executable. igt_resume_signal_helper() must be called after + * the critical section to restart interruptions for the test. + */ +void igt_suspend_signal_helper(void) +{ + int status; + + if (!signal_helper.running) + return; + + kill(signal_helper.pid, SIGSTOP); + while (waitpid(signal_helper.pid, &status, WUNTRACED) == -1 && + errno == EINTR) + ; +} + +/** + * igt_resume_signal_helper: + * + * Resumes the child process spawned with igt_fork_signal_helper(). + * + * This should be paired with igt_suspend_signal_helper() and called after the + * problematic code sensitive to signals. + */ +void igt_resume_signal_helper(void) +{ + if (!signal_helper.running) + return; + + kill(signal_helper.pid, SIGCONT); +} + static struct igt_helper_process shrink_helper; static void __attribute__((noreturn)) shrink_helper_process(int fd, pid_t pid) { -- cgit v1.2.3