xfs
[Top] [All Lists]

[PATCH 2/3] xfsqa: Fix signal usage in aio-dio test code

To: xfs@xxxxxxxxxxx
Subject: [PATCH 2/3] xfsqa: Fix signal usage in aio-dio test code
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Tue, 19 Jan 2010 20:03:11 +1100
In-reply-to: <1263891792-30952-1-git-send-email-david@xxxxxxxxxxxxx>
References: <1263891792-30952-1-git-send-email-david@xxxxxxxxxxxxx>
Using signal() to set up signal handlers doesn't always do what you
want. A recent upgrade made test 208 fail because wait() was not
getting interrupted by a SIGALRM. Tracing showed that signal() was
being converted to a sigaction(SA_RESTART) handler, which allows
syscalls that return ERESTARTSYS to immediately restart without
returning EINTR to the calling process. The kernel code returns
ERESTARTSYS to signal interruptions while in wait().

Replace the use of signal with sigaction() to ensure that the
SA_RESTART flag is not set and the EINTR is delivered to the process
sitting in wait().  This makes test 208 terminate at 200s again.

Signed-off-by: Dave Chinner <david@xxxxxxxxxxxxx>
---
 src/aio-dio-regress/aio-dio-invalidate-failure.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/src/aio-dio-regress/aio-dio-invalidate-failure.c 
b/src/aio-dio-regress/aio-dio-invalidate-failure.c
index be01a3a..24f3e3c 100644
--- a/src/aio-dio-regress/aio-dio-invalidate-failure.c
+++ b/src/aio-dio-regress/aio-dio-invalidate-failure.c
@@ -21,6 +21,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <signal.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -117,6 +118,7 @@ int main(int argc, char **argv)
        int fd;
        int fd2;
        int status;
+       struct sigaction sa;
 
        if (argc != 2)
                fail("only arg should be file name");
@@ -150,7 +152,12 @@ int main(int argc, char **argv)
                exit(0);
        }
 
-       signal(SIGALRM, alarm_handler);
+       memset(&sa, 0, sizeof(sa));
+       sa.sa_handler = alarm_handler;
+       sigemptyset(&sa.sa_mask);
+       if (sigaction(SIGALRM, &sa, NULL) == -1)
+               fail("sigaction: %d\n", errno);
+
        alarm(SECONDS);
 
        pid = wait(&status);
-- 
1.6.5

<Prev in Thread] Current Thread [Next in Thread>