1f08c3bdfSopenharmony_ci/******************************************************************************/
2f08c3bdfSopenharmony_ci/* Copyright (c) Crackerjack Project., 2007                                   */
3f08c3bdfSopenharmony_ci/*                                                                            */
4f08c3bdfSopenharmony_ci/* This program is free software;  you can redistribute it and/or modify      */
5f08c3bdfSopenharmony_ci/* it under the terms of the GNU General Public License as published by       */
6f08c3bdfSopenharmony_ci/* the Free Software Foundation; either version 2 of the License, or          */
7f08c3bdfSopenharmony_ci/* (at your option) any later version.                                        */
8f08c3bdfSopenharmony_ci/*                                                                            */
9f08c3bdfSopenharmony_ci/* This program is distributed in the hope that it will be useful,            */
10f08c3bdfSopenharmony_ci/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
11f08c3bdfSopenharmony_ci/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
12f08c3bdfSopenharmony_ci/* the GNU General Public License for more details.                           */
13f08c3bdfSopenharmony_ci/*                                                                            */
14f08c3bdfSopenharmony_ci/* You should have received a copy of the GNU General Public License          */
15f08c3bdfSopenharmony_ci/* along with this program;  if not, write to the Free Software Foundation,   */
16f08c3bdfSopenharmony_ci/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           */
17f08c3bdfSopenharmony_ci/*                                                                            */
18f08c3bdfSopenharmony_ci/* History:     Porting from Crackerjack to LTP is done by                    */
19f08c3bdfSopenharmony_ci/*              Manas Kumar Nayak maknayak@in.ibm.com>                        */
20f08c3bdfSopenharmony_ci/******************************************************************************/
21f08c3bdfSopenharmony_ci
22f08c3bdfSopenharmony_ci/******************************************************************************/
23f08c3bdfSopenharmony_ci/* Description: This tests the rt_sigprocmask() syscall                       */
24f08c3bdfSopenharmony_ci/*		rt_sigprocmask changes the list of currently blocked signals. */
25f08c3bdfSopenharmony_ci/*		The set value stores the signal mask of the pending signals.  */
26f08c3bdfSopenharmony_ci/*		The previous action on the signal is saved in oact. The value */
27f08c3bdfSopenharmony_ci/*		of how indicates how the call should behave; its values are   */
28f08c3bdfSopenharmony_ci/*		as follows:						      */
29f08c3bdfSopenharmony_ci/*									      */
30f08c3bdfSopenharmony_ci/*		SIG_BLOCK						      */
31f08c3bdfSopenharmony_ci/*		    The set of blocked signals is the union of the current set*/
32f08c3bdfSopenharmony_ci/*		    and the set argument. 				      */
33f08c3bdfSopenharmony_ci/*		SIG_UNBLOCK						      */
34f08c3bdfSopenharmony_ci/*		    The signals in set are removed from the current set of    */
35f08c3bdfSopenharmony_ci/*		    blocked signals. It is okay to unblock a signal that is   */
36f08c3bdfSopenharmony_ci/*		    not blocked. 					      */
37f08c3bdfSopenharmony_ci/*		SIG_SETMASK						      */
38f08c3bdfSopenharmony_ci/*		    The set of blocked signals is set to the set argument.    */
39f08c3bdfSopenharmony_ci/*		    sigsetsize should indicate the size of a sigset_t type.   */
40f08c3bdfSopenharmony_ci/* 									      */
41f08c3bdfSopenharmony_ci/* 		RETURN VALUE:i						      */
42f08c3bdfSopenharmony_ci/* 		rt_sigprocmask returns 0 on success; otherwise, rt_sigprocmask*/
43f08c3bdfSopenharmony_ci/* 		returns one of the errors listed in the "Errors" section.     */
44f08c3bdfSopenharmony_ci/* 									      */
45f08c3bdfSopenharmony_ci/* 		Errors:							      */
46f08c3bdfSopenharmony_ci/* 			-EINVAL						      */
47f08c3bdfSopenharmony_ci/* 			    sigsetsize was not equivalent to the size of a    */
48f08c3bdfSopenharmony_ci/* 			    sigset_t type or the value specified in how was   */
49f08c3bdfSopenharmony_ci/* 			    invalid. 					      */
50f08c3bdfSopenharmony_ci/* 			-EFAULT						      */
51f08c3bdfSopenharmony_ci/* 			    An invalid set, act, or oact was specified.       */
52f08c3bdfSopenharmony_ci/******************************************************************************/
53f08c3bdfSopenharmony_ci
54f08c3bdfSopenharmony_ci#include <stdio.h>
55f08c3bdfSopenharmony_ci#include <signal.h>
56f08c3bdfSopenharmony_ci#include <errno.h>
57f08c3bdfSopenharmony_ci
58f08c3bdfSopenharmony_ci#include "test.h"
59f08c3bdfSopenharmony_ci#include "lapi/syscalls.h"
60f08c3bdfSopenharmony_ci#include "ltp_signal.h"
61f08c3bdfSopenharmony_ci
62f08c3bdfSopenharmony_cichar *TCID = "rt_sigprocmask02";
63f08c3bdfSopenharmony_ciint TST_TOTAL = 2;
64f08c3bdfSopenharmony_ci
65f08c3bdfSopenharmony_cistatic void cleanup(void)
66f08c3bdfSopenharmony_ci{
67f08c3bdfSopenharmony_ci	tst_rmdir();
68f08c3bdfSopenharmony_ci}
69f08c3bdfSopenharmony_ci
70f08c3bdfSopenharmony_cistatic void setup(void)
71f08c3bdfSopenharmony_ci{
72f08c3bdfSopenharmony_ci	TEST_PAUSE;
73f08c3bdfSopenharmony_ci	tst_tmpdir();
74f08c3bdfSopenharmony_ci}
75f08c3bdfSopenharmony_ci
76f08c3bdfSopenharmony_cistatic sigset_t set;
77f08c3bdfSopenharmony_ci
78f08c3bdfSopenharmony_cistatic struct test_case_t {
79f08c3bdfSopenharmony_ci	sigset_t *ss;
80f08c3bdfSopenharmony_ci	int sssize;
81f08c3bdfSopenharmony_ci	int exp_errno;
82f08c3bdfSopenharmony_ci} test_cases[] = {
83f08c3bdfSopenharmony_ci	{
84f08c3bdfSopenharmony_ci	&set, 1, EINVAL}, {
85f08c3bdfSopenharmony_ci	(sigset_t *) - 1, SIGSETSIZE, EFAULT}
86f08c3bdfSopenharmony_ci};
87f08c3bdfSopenharmony_ci
88f08c3bdfSopenharmony_ciint test_count = sizeof(test_cases) / sizeof(struct test_case_t);
89f08c3bdfSopenharmony_ci
90f08c3bdfSopenharmony_ciint main(int ac, char **av)
91f08c3bdfSopenharmony_ci{
92f08c3bdfSopenharmony_ci	int i;
93f08c3bdfSopenharmony_ci	sigset_t s;
94f08c3bdfSopenharmony_ci
95f08c3bdfSopenharmony_ci	tst_parse_opts(ac, av, NULL, NULL);
96f08c3bdfSopenharmony_ci
97f08c3bdfSopenharmony_ci	setup();
98f08c3bdfSopenharmony_ci
99f08c3bdfSopenharmony_ci	tst_count = 0;
100f08c3bdfSopenharmony_ci
101f08c3bdfSopenharmony_ci	TEST(sigfillset(&s));
102f08c3bdfSopenharmony_ci	if (TEST_RETURN == -1)
103f08c3bdfSopenharmony_ci		tst_brkm(TFAIL | TTERRNO, cleanup,
104f08c3bdfSopenharmony_ci			"Call to sigfillset() failed.");
105f08c3bdfSopenharmony_ci
106f08c3bdfSopenharmony_ci	for (i = 0; i < test_count; i++) {
107f08c3bdfSopenharmony_ci		TEST(tst_syscall(__NR_rt_sigprocmask, SIG_BLOCK,
108f08c3bdfSopenharmony_ci			     &s, test_cases[i].ss, test_cases[i].sssize));
109f08c3bdfSopenharmony_ci		if (TEST_RETURN == 0) {
110f08c3bdfSopenharmony_ci			tst_resm(TFAIL | TTERRNO,
111f08c3bdfSopenharmony_ci				 "Call to rt_sigprocmask() succeeded, "
112f08c3bdfSopenharmony_ci				 "but should failed");
113f08c3bdfSopenharmony_ci		} else if (TEST_ERRNO == test_cases[i].exp_errno) {
114f08c3bdfSopenharmony_ci			tst_resm(TPASS | TTERRNO, "Got expected errno");
115f08c3bdfSopenharmony_ci		} else {
116f08c3bdfSopenharmony_ci			tst_resm(TFAIL | TTERRNO, "Got unexpected errno");
117f08c3bdfSopenharmony_ci		}
118f08c3bdfSopenharmony_ci
119f08c3bdfSopenharmony_ci	}
120f08c3bdfSopenharmony_ci
121f08c3bdfSopenharmony_ci	cleanup();
122f08c3bdfSopenharmony_ci	tst_exit();
123f08c3bdfSopenharmony_ci}
124