subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 2 | /* Copyright (c) Crackerjack Project., 2007 */ |
| 3 | /* */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 4 | /* This program is free software; you can redistribute it and/or modify */ |
| 5 | /* it under the terms of the GNU General Public License as published by */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 6 | /* the Free Software Foundation; either version 2 of the License, or */ |
| 7 | /* (at your option) any later version. */ |
| 8 | /* */ |
| 9 | /* This program is distributed in the hope that it will be useful, */ |
| 10 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 11 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ |
| 12 | /* the GNU General Public License for more details. */ |
| 13 | /* */ |
| 14 | /* You should have received a copy of the GNU General Public License */ |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 15 | /* along with this program; if not, write to the Free Software Foundation, */ |
| 16 | /* Inc., 59 Temple Place, Suite TEST_SIG0, Boston, MA 02111-1307 USA */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 17 | /* */ |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 18 | /* History: Porting from Crackerjack to LTP is done by */ |
| 19 | /* Manas Kumar Nayak <maknayak@in.ibm.com> */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 20 | /******************************************************************************/ |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 21 | |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 22 | /******************************************************************************/ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 23 | /* Description: This tests the rt_sigprocmask() syscall */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 24 | /* rt_sigprocmask changes the list of currently blocked signals. */ |
| 25 | /* The set value stores the signal mask of the pending signals. */ |
| 26 | /* The previous action on the signal is saved in oact. The value */ |
| 27 | /* of how indicates how the call should behave; its values are */ |
| 28 | /* as follows: */ |
| 29 | /* */ |
| 30 | /* SIG_BLOCK */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 31 | /* The set of blocked signals is the union of the current set*/ |
Cyril Hrubis | 22f069f | 2014-06-26 16:31:05 +0200 | [diff] [blame] | 32 | /* and the set argument. */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 33 | /* SIG_UNBLOCK */ |
| 34 | /* The signals in set are removed from the current set of */ |
| 35 | /* blocked signals. It is okay to unblock a signal that is */ |
Cyril Hrubis | 22f069f | 2014-06-26 16:31:05 +0200 | [diff] [blame] | 36 | /* not blocked. */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 37 | /* SIG_SETMASK */ |
| 38 | /* The set of blocked signals is set to the set argument. */ |
| 39 | /* sigsetsize should indicate the size of a sigset_t type. */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 40 | /******************************************************************************/ |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 41 | |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 42 | #include <stdio.h> |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 43 | #include <signal.h> |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 44 | #include <errno.h> |
| 45 | |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 46 | #include "test.h" |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 47 | #include "linux_syscall_numbers.h" |
Stanislav Kholmanskikh | ea53701 | 2014-06-17 13:08:17 +0400 | [diff] [blame] | 48 | #include "lapi/rt_sigaction.h" |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 49 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 50 | char *TCID = "rt_sigprocmask01"; |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 51 | static int testno; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 52 | int TST_TOTAL = 8; |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 53 | |
Cyril Hrubis | 22f069f | 2014-06-26 16:31:05 +0200 | [diff] [blame] | 54 | static volatile sig_atomic_t sig_count; |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 55 | |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 56 | #define TEST_SIG SIGRTMIN+1 |
| 57 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 58 | static void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 59 | { |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 60 | tst_rmdir(); |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 63 | static void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 64 | { |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 65 | TEST_PAUSE; |
| 66 | tst_tmpdir(); |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 67 | } |
| 68 | |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 69 | void sig_handler(int sig) |
| 70 | { |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 71 | sig_count++; |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 74 | int main(int ac, char **av) |
| 75 | { |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 76 | struct sigaction act, oact; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 77 | memset(&act, 0, sizeof(act)); |
| 78 | memset(&oact, 0, sizeof(oact)); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 79 | act.sa_handler = sig_handler; |
Stanislav Kholmanskikh | ea53701 | 2014-06-17 13:08:17 +0400 | [diff] [blame] | 80 | |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 81 | sigset_t set, oset; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 82 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 83 | const char *msg; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 84 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 85 | msg = parse_opts(ac, av, NULL, NULL); |
| 86 | if (msg != NULL) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 87 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 88 | |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 89 | setup(); |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 90 | |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 91 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 92 | tst_count = 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 93 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 94 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 95 | if (sigemptyset(&set) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 96 | tst_brkm(TFAIL | TERRNO, cleanup, |
| 97 | "sigemptyset call failed"); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 98 | |
| 99 | if (sigaddset(&set, TEST_SIG) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 100 | tst_brkm(TFAIL | TERRNO, cleanup, |
| 101 | "sigaddset call failed"); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 102 | |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 103 | /* call rt_sigaction() */ |
Stanislav Kholmanskikh | ea53701 | 2014-06-17 13:08:17 +0400 | [diff] [blame] | 104 | TEST(ltp_rt_sigaction(TEST_SIG, &act, &oact, |
| 105 | SIGSETSIZE)); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 106 | if (TEST_RETURN < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 107 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 108 | "rt_sigaction call failed"); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 109 | |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 110 | /* call rt_sigprocmask() to block signal#TEST_SIG */ |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 111 | TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_BLOCK, &set, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 112 | &oset, SIGSETSIZE)); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 113 | if (TEST_RETURN == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 114 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 115 | "rt_sigprocmask call failed"); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 116 | |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 117 | /* Make sure that the masked process is indeed |
| 118 | * masked. */ |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 119 | if (kill(getpid(), TEST_SIG) < 0) |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 120 | tst_brkm(TFAIL | TERRNO, cleanup, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 121 | "call to kill() failed"); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 122 | |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 123 | if (sig_count) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 124 | tst_brkm(TFAIL | TERRNO, cleanup, |
| 125 | "rt_sigprocmask() failed to change " |
| 126 | "the process's signal mask"); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 127 | } else { |
| 128 | /* call rt_sigpending() */ |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 129 | TEST(ltp_syscall(__NR_rt_sigpending, &oset, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 130 | SIGSETSIZE)); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 131 | if (TEST_RETURN == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 132 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 133 | "rt_sigpending call failed"); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 134 | |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 135 | TEST(sigismember(&oset, TEST_SIG)); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 136 | if (TEST_RETURN == 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 137 | tst_brkm(TFAIL | TTERRNO, |
| 138 | cleanup, |
| 139 | "sigismember call failed"); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 140 | |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 141 | /* call rt_sigprocmask() to unblock |
| 142 | * signal#TEST_SIG */ |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 143 | TEST(ltp_syscall(__NR_rt_sigprocmask, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 144 | SIG_UNBLOCK, &set, &oset, |
| 145 | SIGSETSIZE)); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 146 | if (TEST_RETURN == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 147 | tst_brkm(TFAIL | TTERRNO, |
| 148 | cleanup, |
| 149 | "rt_sigprocmask call failed"); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 150 | |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 151 | if (sig_count) { |
| 152 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 153 | "rt_sigprocmask " |
| 154 | "functionality passed"); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 155 | break; |
| 156 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 157 | tst_brkm(TFAIL | TERRNO, |
| 158 | cleanup, |
| 159 | "rt_sigprocmask " |
| 160 | "functionality failed"); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 161 | } |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 162 | } |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 163 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 164 | } |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 165 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 166 | tst_count++; |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 167 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 168 | } |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 169 | |
| 170 | cleanup(); |
Garrett Cooper | 2e3781d | 2011-01-20 01:05:22 -0800 | [diff] [blame] | 171 | tst_exit(); |
| 172 | } |