blob: e5cb67e21e759b0462a629db59776fee916341e0 [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
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
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"
50#include "usctest.h"
51
52char *TCID = "pipe05";
53int TST_TOTAL = 1;
54extern int Tst_count;
55
subrata_modak56207ce2009-03-23 13:35:39 +000056int exp_enos[] = { EFAULT, 0 };
plars865695b2001-08-27 22:15:12 +000057
plars74948ad2002-11-14 16:16:14 +000058intptr_t pipes;
plars865695b2001-08-27 22:15:12 +000059void setup(void);
60void cleanup(void);
robbiew0c87cd82003-04-29 15:01:27 +000061jmp_buf sig11_recover;
62void sig11_handler(int sig);
63
plars74948ad2002-11-14 16:16:14 +000064int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000065{
subrata_modak56207ce2009-03-23 13:35:39 +000066 int lc; /* loop counter */
67 char *msg; /* message returned from parse_opts */
robbiew0c87cd82003-04-29 15:01:27 +000068 struct sigaction sa, osa;
plars865695b2001-08-27 22:15:12 +000069
70 /* parse standard options */
Garrett Coopere1f008e2010-12-14 00:21:59 -080071 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
plars865695b2001-08-27 22:15:12 +000072 tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
subrata_modak56207ce2009-03-23 13:35:39 +000073 /*NOTREACHED*/}
plars865695b2001-08-27 22:15:12 +000074
75 setup();
76
77 TEST_EXP_ENOS(exp_enos);
78
79 for (lc = 0; TEST_LOOPING(lc); lc++) {
80
81 /* reset Tst_count in case we are looping */
82 Tst_count = 0;
subrata_modak56207ce2009-03-23 13:35:39 +000083 /* special sig11 case */
84 sa.sa_handler = &sig11_handler;
85 sigemptyset(&sa.sa_mask);
86 sa.sa_flags = 0;
plars865695b2001-08-27 22:15:12 +000087
subrata_modak56207ce2009-03-23 13:35:39 +000088 sigaction(SIGSEGV, NULL, &osa);
89 sigaction(SIGSEGV, &sa, NULL);
robbiew0c87cd82003-04-29 15:01:27 +000090
subrata_modak56207ce2009-03-23 13:35:39 +000091 if (setjmp(sig11_recover)) {
92 TEST_RETURN = -1;
93 TEST_ERRNO = EFAULT;
94 } else {
95 TEST(pipe((int *)pipes));
96 }
97 sigaction(SIGSEGV, &osa, NULL);
subrata_modakbdbaec52009-02-26 12:14:51 +000098
plars865695b2001-08-27 22:15:12 +000099 if (TEST_RETURN != -1) {
100 tst_resm(TFAIL, "call succeeded unexpectedly");
101 }
102
103 TEST_ERROR_LOG(TEST_ERRNO);
104
105 if (TEST_ERRNO != EFAULT) {
106 tst_resm(TFAIL, "unexpected error - %d : %s - "
107 "expected EMFILE", TEST_ERRNO,
108 strerror(TEST_ERRNO));
109 } else {
110 tst_resm(TPASS, "expected failure - "
111 "errno = %d : %s", TEST_ERRNO,
subrata_modak56207ce2009-03-23 13:35:39 +0000112 strerror(TEST_ERRNO));
plars865695b2001-08-27 22:15:12 +0000113 }
114
115 }
116 cleanup();
subrata_modak43337a32009-02-26 11:43:51 +0000117 return 0;
plars865695b2001-08-27 22:15:12 +0000118}
119
120/*
121 * setup() - performs all ONE TIME setup for this test.
122 */
subrata_modak56207ce2009-03-23 13:35:39 +0000123void setup()
plars865695b2001-08-27 22:15:12 +0000124{
125 /* capture signals */
126 tst_sig(NOFORK, DEF_HANDLER, cleanup);
127
128 /* Pause if that option was specified */
129 TEST_PAUSE;
130}
subrata_modak56207ce2009-03-23 13:35:39 +0000131
robbiew0c87cd82003-04-29 15:01:27 +0000132/******************************************************************
133 * sig11_handler() - our segfault recover hack
134 ******************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000135void sig11_handler(int sig)
robbiew0c87cd82003-04-29 15:01:27 +0000136{
subrata_modak56207ce2009-03-23 13:35:39 +0000137 longjmp(sig11_recover, 1);
robbiew0c87cd82003-04-29 15:01:27 +0000138}
139
plars865695b2001-08-27 22:15:12 +0000140/*
141 * cleanup() - performs all ONE TIME cleanup for this test at
142 * completion or premature exit.
143 */
subrata_modak56207ce2009-03-23 13:35:39 +0000144void cleanup()
plars865695b2001-08-27 22:15:12 +0000145{
146 /*
147 * print timing stats if that option was specified.
148 * print errno log if that option was specified.
149 */
150 TEST_CLEANUP;
151
152 /* exit with return code appropriate for results */
153 tst_exit();
154}