blob: e5fdf67650e31acab413f4d321044b97cc62c50f [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * NAME
22 * pipe05.c
23 *
24 * DESCRIPTION
25 * Check what happens when pipe is passed a bad file descriptor.
26 *
27 * ALGORITHM
28 * Issue the pipe call with a bad file descriptor.
29 * Check that we get EFAULT.
30 *
31 * USAGE: <for command-line>
32 * pipe05 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
33 * where, -c n : Run n copies concurrently.
34 * -e : Turn on errno logging.
35 * -i n : Execute test n times.
36 * -I x : Execute test for x seconds.
37 * -P x : Pause for x seconds between iterations.
38 * -t : Turn on syscall timing.
39 *
40 * HISTORY
41 * 07/2001 Ported by Wayne Boyer
42 *
43 * RESTRICTIONS
44 * None
45 */
46#include <fcntl.h>
47#include <errno.h>
robbiew0c87cd82003-04-29 15:01:27 +000048#include <setjmp.h>
plars865695b2001-08-27 22:15:12 +000049#include "test.h"
plars865695b2001-08-27 22:15:12 +000050
51char *TCID = "pipe05";
52int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000053
plars74948ad2002-11-14 16:16:14 +000054intptr_t pipes;
plars865695b2001-08-27 22:15:12 +000055void setup(void);
56void cleanup(void);
robbiew0c87cd82003-04-29 15:01:27 +000057jmp_buf sig11_recover;
58void sig11_handler(int sig);
59
plars74948ad2002-11-14 16:16:14 +000060int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000061{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020062 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020063 const char *msg;
robbiew0c87cd82003-04-29 15:01:27 +000064 struct sigaction sa, osa;
plars865695b2001-08-27 22:15:12 +000065
Garrett Cooper53740502010-12-16 00:04:01 -080066 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080067 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000068
69 setup();
70
plars865695b2001-08-27 22:15:12 +000071 for (lc = 0; TEST_LOOPING(lc); lc++) {
72
Caspar Zhangd59a6592013-03-07 14:59:12 +080073 /* reset tst_count in case we are looping */
74 tst_count = 0;
subrata_modak56207ce2009-03-23 13:35:39 +000075 /* special sig11 case */
76 sa.sa_handler = &sig11_handler;
77 sigemptyset(&sa.sa_mask);
78 sa.sa_flags = 0;
plars865695b2001-08-27 22:15:12 +000079
subrata_modak56207ce2009-03-23 13:35:39 +000080 sigaction(SIGSEGV, NULL, &osa);
81 sigaction(SIGSEGV, &sa, NULL);
robbiew0c87cd82003-04-29 15:01:27 +000082
subrata_modak56207ce2009-03-23 13:35:39 +000083 if (setjmp(sig11_recover)) {
84 TEST_RETURN = -1;
85 TEST_ERRNO = EFAULT;
86 } else {
87 TEST(pipe((int *)pipes));
88 }
89 sigaction(SIGSEGV, &osa, NULL);
subrata_modakbdbaec52009-02-26 12:14:51 +000090
plars865695b2001-08-27 22:15:12 +000091 if (TEST_RETURN != -1) {
92 tst_resm(TFAIL, "call succeeded unexpectedly");
93 }
94
plars865695b2001-08-27 22:15:12 +000095 if (TEST_ERRNO != EFAULT) {
96 tst_resm(TFAIL, "unexpected error - %d : %s - "
97 "expected EMFILE", TEST_ERRNO,
98 strerror(TEST_ERRNO));
99 } else {
100 tst_resm(TPASS, "expected failure - "
101 "errno = %d : %s", TEST_ERRNO,
subrata_modak56207ce2009-03-23 13:35:39 +0000102 strerror(TEST_ERRNO));
plars865695b2001-08-27 22:15:12 +0000103 }
104
105 }
106 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800107 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800108
plars865695b2001-08-27 22:15:12 +0000109}
110
111/*
112 * setup() - performs all ONE TIME setup for this test.
113 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400114void setup(void)
plars865695b2001-08-27 22:15:12 +0000115{
Garrett Cooper2c282152010-12-16 00:55:50 -0800116
plars865695b2001-08-27 22:15:12 +0000117 tst_sig(NOFORK, DEF_HANDLER, cleanup);
118
plars865695b2001-08-27 22:15:12 +0000119 TEST_PAUSE;
120}
subrata_modak56207ce2009-03-23 13:35:39 +0000121
robbiew0c87cd82003-04-29 15:01:27 +0000122/******************************************************************
123 * sig11_handler() - our segfault recover hack
124 ******************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000125void sig11_handler(int sig)
robbiew0c87cd82003-04-29 15:01:27 +0000126{
subrata_modak56207ce2009-03-23 13:35:39 +0000127 longjmp(sig11_recover, 1);
robbiew0c87cd82003-04-29 15:01:27 +0000128}
129
plars865695b2001-08-27 22:15:12 +0000130/*
131 * cleanup() - performs all ONE TIME cleanup for this test at
132 * completion or premature exit.
133 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400134void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000135{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700136}