-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
#include <string.h>
#include <signal.h>
#include <setjmp.h>
#include "test.h"
-#define TEST(c, ...) ((c) ? 1 : (error(#c" failed: " __VA_ARGS__),0))
-#define TESTE(c) (errno=0, TEST(c, "errno = %s\n", strerror(errno)))
+#define TEST(c, ...) ((c) ? 1 : (t_error(#c" failed: " __VA_ARGS__),0))
int main(void)
{
jmp_buf jb;
sigjmp_buf sjb;
volatile sigset_t oldset;
- sigset_t set;
+ sigset_t set, set2;
if (!setjmp(jb)) {
x = 1;
sigemptyset(&set);
sigaddset(&set, SIGUSR1);
- sigprocmask(SIG_UNBLOCK, &set, &set);
- oldset = set;
+ sigprocmask(SIG_UNBLOCK, &set, &set2);
+ oldset = set2;
/* Improve the chances of catching failure of sigsetjmp to
* properly save the signal mask in the sigjmb_buf. */
siglongjmp(sjb, 1);
}
set = oldset;
- sigprocmask(SIG_SETMASK, &set, &set);
- TEST(sigismember(&set, SIGUSR1)==0, "siglongjmp failed to restore mask\n");
+ sigprocmask(SIG_SETMASK, &set, &set2);
+ TEST(sigismember(&set2, SIGUSR1)==0, "siglongjmp failed to restore mask\n");
- return test_status;
+ sigemptyset(&set);
+ sigaddset(&set, SIGUSR1);
+ sigprocmask(SIG_UNBLOCK, &set, &set2);
+ oldset = set2;
+
+ if (!sigsetjmp(sjb, 0)) {
+ sigemptyset(&set);
+ sigaddset(&set, SIGUSR1);
+ sigprocmask(SIG_BLOCK, &set, 0);
+ siglongjmp(sjb, 1);
+ }
+ set = oldset;
+ sigprocmask(SIG_SETMASK, &set, &set2);
+ TEST(sigismember(&set2, SIGUSR1)==1, "siglongjmp incorrectly restored mask\n");
+
+ return t_status;
}