subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 2 | /* Copyright (c) Crackerjack Project., 2007 */ |
| 3 | /* */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 20 | /******************************************************************************/ |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 21 | |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 22 | /******************************************************************************/ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 23 | /* Description: This tests the rt_sigaction() syscall */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 24 | /* rt_sigaction alters an action taken by a process on receipt */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 25 | /* of a particular signal. The action is specified by the */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 26 | /* sigaction structure. The previous action on the signal is */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 27 | /* saved in oact.sigsetsize should indicate the size of a */ |
| 28 | /* sigset_t type. */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 29 | /******************************************************************************/ |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 30 | |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 31 | #include <stdio.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <unistd.h> |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 34 | #include <signal.h> |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 35 | #include <errno.h> |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 36 | #include <sys/syscall.h> |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 37 | #include <string.h> |
| 38 | |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 39 | #include "test.h" |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 40 | #include "linux_syscall_numbers.h" |
Stanislav Kholmanskikh | ea53701 | 2014-06-17 13:08:17 +0400 | [diff] [blame] | 41 | #include "lapi/rt_sigaction.h" |
subrata_modak | bb190cd | 2009-07-06 15:24:06 +0000 | [diff] [blame] | 42 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 43 | char *TCID = "rt_sigaction01"; |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 44 | static int testno; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 45 | int TST_TOTAL = 1; |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 46 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 47 | static void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 48 | { |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 49 | tst_rmdir(); |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 52 | static void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 53 | { |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 54 | TEST_PAUSE; |
| 55 | tst_tmpdir(); |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 58 | static int test_flags[] = |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 59 | { SA_RESETHAND | SA_SIGINFO, SA_RESETHAND, SA_RESETHAND | SA_SIGINFO, |
| 60 | SA_RESETHAND | SA_SIGINFO, SA_NOMASK }; |
| 61 | char *test_flags_list[] = |
| 62 | { "SA_RESETHAND|SA_SIGINFO", "SA_RESETHAND", "SA_RESETHAND|SA_SIGINFO", |
| 63 | "SA_RESETHAND|SA_SIGINFO", "SA_NOMASK" }; |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 64 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 65 | static void handler(int sig) |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 66 | { |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 67 | tst_resm(TINFO, "Signal Handler Called with signal number %d\n", sig); |
| 68 | return; |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 71 | static int set_handler(int sig, int sig_to_mask, int mask_flags) |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 72 | { |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 73 | struct sigaction sa, oldaction; |
Stanislav Kholmanskikh | ea53701 | 2014-06-17 13:08:17 +0400 | [diff] [blame] | 74 | |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 75 | sa.sa_handler = (void *)handler; |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 76 | sa.sa_flags = mask_flags; |
| 77 | sigemptyset(&sa.sa_mask); |
| 78 | sigaddset(&sa.sa_mask, sig); |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 79 | |
Stanislav Kholmanskikh | ea53701 | 2014-06-17 13:08:17 +0400 | [diff] [blame] | 80 | return ltp_rt_sigaction(sig, &sa, &oldaction, SIGSETSIZE); |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 83 | int main(int ac, char **av) |
| 84 | { |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 85 | unsigned int flag; |
| 86 | int signal; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 87 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 88 | const char *msg; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 89 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 90 | msg = parse_opts(ac, av, NULL, NULL); |
| 91 | if (msg != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 92 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
yaberauneya | 1979ba3 | 2009-11-26 14:30:42 +0000 | [diff] [blame] | 93 | |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 94 | setup(); |
yaberauneya | 1979ba3 | 2009-11-26 14:30:42 +0000 | [diff] [blame] | 95 | |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 96 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
| 97 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 98 | tst_count = 0; |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 99 | |
| 100 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
| 101 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 102 | for (signal = SIGRTMIN; signal <= SIGRTMAX; signal++) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 103 | for (flag = 0; |
| 104 | flag < |
| 105 | (sizeof(test_flags) / |
| 106 | sizeof(test_flags[0])); flag++) { |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 107 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 108 | TEST(set_handler |
| 109 | (signal, 0, test_flags[flag])); |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 110 | |
| 111 | if (TEST_RETURN == 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 112 | tst_resm(TINFO, "signal: %d ", |
| 113 | signal); |
| 114 | tst_resm(TPASS, |
| 115 | "rt_sigaction call succeeded: result = %ld ", |
| 116 | TEST_RETURN); |
| 117 | tst_resm(TINFO, |
| 118 | "sa.sa_flags = %s ", |
| 119 | test_flags_list[flag]); |
| 120 | kill(getpid(), signal); |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 121 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 122 | tst_resm(TFAIL | TTERRNO, |
| 123 | "rt_sigaction call " |
| 124 | "failed"); |
| 125 | } |
yaberauneya | 1979ba3 | 2009-11-26 14:30:42 +0000 | [diff] [blame] | 126 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 127 | } |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 128 | |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 129 | } |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 130 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 131 | } |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 132 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 133 | } |
subrata_modak | bb190cd | 2009-07-06 15:24:06 +0000 | [diff] [blame] | 134 | cleanup(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 135 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 136 | } |