blob: 4cee988b12748992be096587f1f3a48aba85723a [file] [log] [blame]
subrata_modak654da392009-05-21 18:20:58 +00001/******************************************************************************/
yaberauneya5833cc62010-01-26 08:24:52 +00002/* Copyright (c) Crackerjack Project., 2007 */
3/* */
subrata_modak654da392009-05-21 18:20:58 +00004/* 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 */
yaberauneya5833cc62010-01-26 08:24:52 +00006/* 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 Kholmanskikh4d93b882014-06-17 13:08:16 +040015/* along with this program; if not, write to the Free Software Foundation, */
16/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
yaberauneya5833cc62010-01-26 08:24:52 +000017/* */
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040018/* History: Porting from Crackerjack to LTP is done by */
19/* Manas Kumar Nayak maknayak@in.ibm.com> */
subrata_modak654da392009-05-21 18:20:58 +000020/******************************************************************************/
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040021
subrata_modak654da392009-05-21 18:20:58 +000022/******************************************************************************/
yaberauneya5833cc62010-01-26 08:24:52 +000023/* Description: This tests the rt_sigaction() syscall */
subrata_modak654da392009-05-21 18:20:58 +000024/* rt_sigaction alters an action taken by a process on receipt */
yaberauneya5833cc62010-01-26 08:24:52 +000025/* of a particular signal. The action is specified by the */
subrata_modak654da392009-05-21 18:20:58 +000026/* sigaction structure. The previous action on the signal is */
yaberauneya5833cc62010-01-26 08:24:52 +000027/* saved in oact.sigsetsize should indicate the size of a */
28/* sigset_t type. */
subrata_modak654da392009-05-21 18:20:58 +000029/******************************************************************************/
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040030
subrata_modak654da392009-05-21 18:20:58 +000031#include <stdio.h>
32#include <stdlib.h>
33#include <unistd.h>
yaberauneya5833cc62010-01-26 08:24:52 +000034#include <signal.h>
subrata_modak654da392009-05-21 18:20:58 +000035#include <errno.h>
yaberauneya5833cc62010-01-26 08:24:52 +000036#include <sys/syscall.h>
subrata_modak654da392009-05-21 18:20:58 +000037#include <string.h>
38
subrata_modak654da392009-05-21 18:20:58 +000039#include "test.h"
subrata_modak654da392009-05-21 18:20:58 +000040#include "linux_syscall_numbers.h"
Stanislav Kholmanskikhea537012014-06-17 13:08:17 +040041#include "lapi/rt_sigaction.h"
subrata_modakbb190cd2009-07-06 15:24:06 +000042
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020043char *TCID = "rt_sigaction01";
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040044static int testno;
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020045int TST_TOTAL = 1;
yaberauneya402ec1f2009-11-30 20:38:48 +000046
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040047static void cleanup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080048{
Garrett Cooper64fd9672010-02-26 05:12:13 -080049 tst_rmdir();
subrata_modak654da392009-05-21 18:20:58 +000050}
51
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040052static void setup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080053{
Garrett Cooper64fd9672010-02-26 05:12:13 -080054 TEST_PAUSE;
55 tst_tmpdir();
subrata_modak654da392009-05-21 18:20:58 +000056}
57
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040058static int test_flags[] =
Wanlong Gao354ebb42012-12-07 10:10:04 +080059 { SA_RESETHAND | SA_SIGINFO, SA_RESETHAND, SA_RESETHAND | SA_SIGINFO,
60SA_RESETHAND | SA_SIGINFO, SA_NOMASK };
61char *test_flags_list[] =
62 { "SA_RESETHAND|SA_SIGINFO", "SA_RESETHAND", "SA_RESETHAND|SA_SIGINFO",
63"SA_RESETHAND|SA_SIGINFO", "SA_NOMASK" };
yaberauneya5833cc62010-01-26 08:24:52 +000064
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040065static void handler(int sig)
subrata_modak654da392009-05-21 18:20:58 +000066{
Garrett Cooper64fd9672010-02-26 05:12:13 -080067 tst_resm(TINFO, "Signal Handler Called with signal number %d\n", sig);
68 return;
subrata_modak654da392009-05-21 18:20:58 +000069}
70
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040071static int set_handler(int sig, int sig_to_mask, int mask_flags)
subrata_modak654da392009-05-21 18:20:58 +000072{
Garrett Cooper64fd9672010-02-26 05:12:13 -080073 struct sigaction sa, oldaction;
Stanislav Kholmanskikhea537012014-06-17 13:08:17 +040074
Garrett Cooper64fd9672010-02-26 05:12:13 -080075 sa.sa_handler = (void *)handler;
Garrett Cooper64fd9672010-02-26 05:12:13 -080076 sa.sa_flags = mask_flags;
77 sigemptyset(&sa.sa_mask);
78 sigaddset(&sa.sa_mask, sig);
subrata_modak654da392009-05-21 18:20:58 +000079
Stanislav Kholmanskikhea537012014-06-17 13:08:17 +040080 return ltp_rt_sigaction(sig, &sa, &oldaction, SIGSETSIZE);
subrata_modak654da392009-05-21 18:20:58 +000081}
82
Wanlong Gao354ebb42012-12-07 10:10:04 +080083int main(int ac, char **av)
84{
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040085 unsigned int flag;
86 int signal;
Cyril Hrubis89af32a2012-10-24 16:39:11 +020087 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020088 const char *msg;
Garrett Cooper2c282152010-12-16 00:55:50 -080089
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040090 msg = parse_opts(ac, av, NULL, NULL);
91 if (msg != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080092 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
yaberauneya1979ba32009-11-26 14:30:42 +000093
Garrett Cooper64fd9672010-02-26 05:12:13 -080094 setup();
yaberauneya1979ba32009-11-26 14:30:42 +000095
Garrett Cooper64fd9672010-02-26 05:12:13 -080096 for (lc = 0; TEST_LOOPING(lc); ++lc) {
97
Caspar Zhangd59a6592013-03-07 14:59:12 +080098 tst_count = 0;
Garrett Cooper64fd9672010-02-26 05:12:13 -080099
100 for (testno = 0; testno < TST_TOTAL; ++testno) {
101
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +0400102 for (signal = SIGRTMIN; signal <= SIGRTMAX; signal++) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800103 for (flag = 0;
104 flag <
105 (sizeof(test_flags) /
106 sizeof(test_flags[0])); flag++) {
Garrett Cooper64fd9672010-02-26 05:12:13 -0800107
Wanlong Gao354ebb42012-12-07 10:10:04 +0800108 TEST(set_handler
109 (signal, 0, test_flags[flag]));
Garrett Cooper64fd9672010-02-26 05:12:13 -0800110
111 if (TEST_RETURN == 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800112 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 Cooper64fd9672010-02-26 05:12:13 -0800121 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800122 tst_resm(TFAIL | TTERRNO,
123 "rt_sigaction call "
124 "failed");
125 }
yaberauneya1979ba32009-11-26 14:30:42 +0000126
Wanlong Gao354ebb42012-12-07 10:10:04 +0800127 }
yaberauneya402ec1f2009-11-30 20:38:48 +0000128
Garrett Cooper64fd9672010-02-26 05:12:13 -0800129 }
yaberauneya402ec1f2009-11-30 20:38:48 +0000130
Wanlong Gao354ebb42012-12-07 10:10:04 +0800131 }
Garrett Cooper64fd9672010-02-26 05:12:13 -0800132
Garrett Cooper2c282152010-12-16 00:55:50 -0800133 }
subrata_modakbb190cd2009-07-06 15:24:06 +0000134 cleanup();
Garrett Cooper2c282152010-12-16 00:55:50 -0800135 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700136}