X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=inline;f=tests%2Ftest-sigaction.c;h=b08f00c02a0cc71b52082922d512655225048e8b;hb=c9f0960c2cd1acf9c29b27860589698ea54fa4ec;hp=e009bf602290212de9240d2b2ef5fd2469a48a48;hpb=bc1842b36da8d92e81eaf94b8e13d8f6e0afc63e;p=gnulib.git diff --git a/tests/test-sigaction.c b/tests/test-sigaction.c index e009bf602..b08f00c02 100644 --- a/tests/test-sigaction.c +++ b/tests/test-sigaction.c @@ -1,5 +1,5 @@ /* Test of sigaction() function. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,21 +20,13 @@ #include -#include -#include - -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - signal (SIGABRT, SIG_DFL); \ - abort (); \ - } \ - } \ - while (0) +#include "signature.h" +SIGNATURE_CHECK (sigaction, int, (int, struct sigaction const *, + struct sigaction *)); + +#include + +#include "macros.h" #ifndef SA_NOCLDSTOP # define SA_NOCLDSTOP 0 @@ -42,6 +34,12 @@ #ifndef SA_ONSTACK # define SA_ONSTACK 0 #endif +#ifndef SA_RESETHAND +# define SA_RESETHAND 0 +#endif +#ifndef SA_RESTART +# define SA_RESTART 0 +#endif #ifndef SA_SIGINFO # define SA_SIGINFO 0 #endif @@ -52,8 +50,8 @@ /* Define a mask of flags required by POSIX. Some implementations provide other flags as extensions, such as SA_RESTORER, that we must ignore in this test. */ -#define SA_MASK (SA_NOCLDSTOP | SA_ONSTACK | SA_RESETHAND | SA_RESTART \ - SA_SIGINFO | SA_NOCLDWAIT | SA_NODEFER) +#define MASK_SA_FLAGS (SA_NOCLDSTOP | SA_ONSTACK | SA_RESETHAND | SA_RESTART \ + | SA_SIGINFO | SA_NOCLDWAIT | SA_NODEFER) /* This test is unsafe in the presence of an asynchronous SIGABRT, because we install a signal-handler that is intentionally not @@ -76,7 +74,12 @@ handler (int sig) ASSERT (sa.sa_handler == handler); break; case 1: + /* This assertion fails on glibc-2.3.6 systems with LinuxThreads, + when this program is linked with -lpthread, due to the sigaction() + override in libpthread.so. */ +#if !(defined __GLIBC__ || defined __UCLIBC__) ASSERT (sa.sa_handler == SIG_DFL); +#endif break; default: ASSERT (0); @@ -84,29 +87,36 @@ handler (int sig) } int -main (int argc, char *argv[]) +main (void) { struct sigaction sa; struct sigaction old_sa; sa.sa_handler = handler; + sa.sa_flags = 0; ASSERT (sigemptyset (&sa.sa_mask) == 0); ASSERT (sigaction (SIGABRT, &sa, NULL) == 0); ASSERT (raise (SIGABRT) == 0); + sa.sa_flags = SA_RESETHAND | SA_NODEFER; ASSERT (sigaction (SIGABRT, &sa, &old_sa) == 0); - ASSERT ((old_sa.sa_flags & SA_MASK) == 0); + ASSERT ((old_sa.sa_flags & MASK_SA_FLAGS) == 0); ASSERT (old_sa.sa_handler == handler); ASSERT (raise (SIGABRT) == 0); + sa.sa_handler = SIG_DFL; ASSERT (sigaction (SIGABRT, &sa, &old_sa) == 0); ASSERT ((old_sa.sa_flags & SA_SIGINFO) == 0); +#if !(defined __GLIBC__ || defined __UCLIBC__) /* see above */ ASSERT (old_sa.sa_handler == SIG_DFL); +#endif + sa.sa_handler = SIG_IGN; ASSERT (sigaction (SIGABRT, &sa, NULL) == 0); ASSERT (raise (SIGABRT) == 0); ASSERT (sigaction (SIGABRT, NULL, &old_sa) == 0); ASSERT (old_sa.sa_handler == SIG_IGN); ASSERT (raise (SIGABRT) == 0); + return 0; }