]> www.infradead.org Git - users/hch/xfstests-dev.git/commitdiff
xfsqa: Fix signal usage in aio-dio test code
authorDave Chinner <david@fromorbit.com>
Tue, 19 Jan 2010 23:28:24 +0000 (10:28 +1100)
committerDave Chinner <david@fromorbit.com>
Tue, 19 Jan 2010 23:28:24 +0000 (10:28 +1100)
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@fromorbit.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
src/aio-dio-regress/aio-dio-invalidate-failure.c

index be01a3af1bbbf6b15cbf8e793bfad7db5b9dc4e1..24f3e3c660b2f77517b464871e20ccd7cf8ed16d 100644 (file)
@@ -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);