diff options
| author | guenther <> | 2015-10-22 05:30:18 +0000 |
|---|---|---|
| committer | guenther <> | 2015-10-22 05:30:18 +0000 |
| commit | 6f9e896881bfb4186fa07fea2fc39c32b2b6e75d (patch) | |
| tree | 5690debc3637470371dd9647f5c777439e4cda22 /src/regress/lib/libc/sigthr/sigthr_test.c | |
| parent | 169b1d04ba02c0b6ed76ddbfa052ef2c50e38d9e (diff) | |
| download | openbsd-6f9e896881bfb4186fa07fea2fc39c32b2b6e75d.tar.gz openbsd-6f9e896881bfb4186fa07fea2fc39c32b2b6e75d.tar.bz2 openbsd-6f9e896881bfb4186fa07fea2fc39c32b2b6e75d.zip | |
Add a regress for libc handling of SIGTHR
Diffstat (limited to 'src/regress/lib/libc/sigthr/sigthr_test.c')
| -rw-r--r-- | src/regress/lib/libc/sigthr/sigthr_test.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/regress/lib/libc/sigthr/sigthr_test.c b/src/regress/lib/libc/sigthr/sigthr_test.c new file mode 100644 index 0000000000..c2eaa1f779 --- /dev/null +++ b/src/regress/lib/libc/sigthr/sigthr_test.c | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> | ||
| 3 | * | ||
| 4 | * Public domain. | ||
| 5 | * | ||
| 6 | * Verify that SIGTHR can't be blocked or caught by applications. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <err.h> | ||
| 10 | #include <errno.h> | ||
| 11 | #include <stdio.h> | ||
| 12 | #include <stdlib.h> | ||
| 13 | #include <string.h> | ||
| 14 | #include <signal.h> | ||
| 15 | |||
| 16 | void sighandler(int sig) { } | ||
| 17 | |||
| 18 | int | ||
| 19 | main(void) | ||
| 20 | { | ||
| 21 | struct sigaction sa; | ||
| 22 | sigset_t set, oset; | ||
| 23 | |||
| 24 | /* | ||
| 25 | * check sigprocmask | ||
| 26 | */ | ||
| 27 | if (sigprocmask(SIG_BLOCK, NULL, &set)) | ||
| 28 | err(1, "sigprocmask"); | ||
| 29 | if (sigismember(&set, SIGTHR)) | ||
| 30 | errx(1, "SIGTHR already blocked"); | ||
| 31 | sigaddset(&set, SIGTHR); | ||
| 32 | if (sigprocmask(SIG_BLOCK, &set, NULL)) | ||
| 33 | err(1, "sigprocmask"); | ||
| 34 | if (sigprocmask(SIG_SETMASK, &set, &oset)) | ||
| 35 | err(1, "sigprocmask"); | ||
| 36 | if (sigismember(&oset, SIGTHR)) | ||
| 37 | errx(1, "SIGTHR blocked with SIG_BLOCK"); | ||
| 38 | if (sigprocmask(SIG_BLOCK, NULL, &oset)) | ||
| 39 | err(1, "sigprocmask"); | ||
| 40 | if (sigismember(&oset, SIGTHR)) | ||
| 41 | errx(1, "SIGTHR blocked with SIG_SETMASK"); | ||
| 42 | |||
| 43 | /* | ||
| 44 | * check sigaction | ||
| 45 | */ | ||
| 46 | if (sigaction(SIGTHR, NULL, &sa) == 0) | ||
| 47 | errx(1, "sigaction(SIGTHR) succeeded"); | ||
| 48 | else if (errno != EINVAL) | ||
| 49 | err(1, "sigaction(SIGTHR) didn't fail with EINVAL"); | ||
| 50 | memset(&sa, 0, sizeof sa); | ||
| 51 | sa.sa_handler = sighandler; | ||
| 52 | sigfillset(&sa.sa_mask); | ||
| 53 | sa.sa_flags = 0; | ||
| 54 | if (sigaction(SIGTHR, &sa, NULL) == 0) | ||
| 55 | errx(1, "sigaction(SIGTHR) succeeded"); | ||
| 56 | else if (errno != EINVAL) | ||
| 57 | err(1, "sigaction(SIGTHR) didn't fail with EINVAL"); | ||
| 58 | if (sigaction(SIGUSR1, &sa, NULL)) | ||
| 59 | err(1, "sigaction(SIGUSR1)"); | ||
| 60 | if (sigaction(SIGUSR1, NULL, &sa)) | ||
| 61 | err(1, "sigaction(SIGUSR1)"); | ||
| 62 | if (sigismember(&sa.sa_mask, SIGTHR)) | ||
| 63 | errx(1, "SIGTHR blocked with sigaction"); | ||
| 64 | |||
| 65 | return 0; | ||
| 66 | } | ||
