1 /******************************************************************************/ 2 /* Copyright (c) Crackerjack Project., 2007 */ 3 /* */ 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 */ 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 */ 15 /* along with this program; if not, write to the Free Software Foundation, */ 16 /* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ 17 /* */ 18 /* History: Porting from Crackerjack to LTP is done by */ 19 /* Manas Kumar Nayak maknayak (at) in.ibm.com> */ 20 /******************************************************************************/ 21 22 /******************************************************************************/ 23 /* Description: This tests the rt_sigprocmask() syscall */ 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 */ 31 /* The set of blocked signals is the union of the current set*/ 32 /* and the set argument. */ 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 */ 36 /* not blocked. */ 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. */ 40 /* */ 41 /* RETURN VALUE:i */ 42 /* rt_sigprocmask returns 0 on success; otherwise, rt_sigprocmask*/ 43 /* returns one of the errors listed in the "Errors" section. */ 44 /* */ 45 /* Errors: */ 46 /* -EINVAL */ 47 /* sigsetsize was not equivalent to the size of a */ 48 /* sigset_t type or the value specified in how was */ 49 /* invalid. */ 50 /* -EFAULT */ 51 /* An invalid set, act, or oact was specified. */ 52 /******************************************************************************/ 53 54 #include <stdio.h> 55 #include <signal.h> 56 #include <errno.h> 57 58 #include "test.h" 59 #include "linux_syscall_numbers.h" 60 #include "ltp_signal.h" 61 62 char *TCID = "rt_sigprocmask02"; 63 int TST_TOTAL = 2; 64 65 static void cleanup(void) 66 { 67 tst_rmdir(); 68 } 69 70 static void setup(void) 71 { 72 TEST_PAUSE; 73 tst_tmpdir(); 74 } 75 76 static sigset_t set; 77 78 static struct test_case_t { 79 sigset_t *ss; 80 int sssize; 81 int exp_errno; 82 } test_cases[] = { 83 { 84 &set, 1, EINVAL}, { 85 (sigset_t *) - 1, SIGSETSIZE, EFAULT} 86 }; 87 88 int test_count = sizeof(test_cases) / sizeof(struct test_case_t); 89 90 int main(int ac, char **av) 91 { 92 int i; 93 sigset_t s; 94 95 tst_parse_opts(ac, av, NULL, NULL); 96 97 setup(); 98 99 tst_count = 0; 100 101 TEST(sigfillset(&s)); 102 if (TEST_RETURN == -1) 103 tst_brkm(TFAIL | TTERRNO, cleanup, 104 "Call to sigfillset() failed."); 105 106 for (i = 0; i < test_count; i++) { 107 TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_BLOCK, 108 &s, test_cases[i].ss, test_cases[i].sssize)); 109 if (TEST_RETURN == 0) { 110 tst_resm(TFAIL | TTERRNO, 111 "Call to rt_sigprocmask() succeeded, " 112 "but should failed"); 113 } else if (TEST_ERRNO == test_cases[i].exp_errno) { 114 tst_resm(TPASS | TTERRNO, "Got expected errno"); 115 } else { 116 tst_resm(TFAIL | TTERRNO, "Got unexpected errno"); 117 } 118 119 } 120 121 cleanup(); 122 tst_exit(); 123 } 124