• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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>
48 #include <setjmp.h>
49 #include "test.h"
50 
51 char *TCID = "pipe05";
52 int TST_TOTAL = 1;
53 
54 intptr_t pipes;
55 void setup(void);
56 void cleanup(void);
57 jmp_buf sig11_recover;
58 void sig11_handler(int sig);
59 
main(int ac,char ** av)60 int main(int ac, char **av)
61 {
62 	volatile int lc;
63 	struct sigaction sa, osa;
64 
65 	tst_parse_opts(ac, av, NULL, NULL);
66 
67 	setup();
68 
69 	for (lc = 0; TEST_LOOPING(lc); lc++) {
70 
71 		/* reset tst_count in case we are looping */
72 		tst_count = 0;
73 		/* special sig11 case */
74 		sa.sa_handler = &sig11_handler;
75 		sigemptyset(&sa.sa_mask);
76 		sa.sa_flags = 0;
77 
78 		sigaction(SIGSEGV, NULL, &osa);
79 		sigaction(SIGSEGV, &sa, NULL);
80 
81 		if (setjmp(sig11_recover)) {
82 			TEST_RETURN = -1;
83 			TEST_ERRNO = EFAULT;
84 		} else {
85 			TEST(pipe((int *)pipes));
86 		}
87 		sigaction(SIGSEGV, &osa, NULL);
88 
89 		if (TEST_RETURN != -1) {
90 			tst_resm(TFAIL, "call succeeded unexpectedly");
91 		}
92 
93 		if (TEST_ERRNO != EFAULT) {
94 			tst_resm(TFAIL, "unexpected error - %d : %s - "
95 				 "expected EMFILE", TEST_ERRNO,
96 				 strerror(TEST_ERRNO));
97 		} else {
98 			tst_resm(TPASS, "expected failure - "
99 				 "errno = %d : %s", TEST_ERRNO,
100 				 strerror(TEST_ERRNO));
101 		}
102 
103 	}
104 	cleanup();
105 	tst_exit();
106 
107 }
108 
109 /*
110  * setup() - performs all ONE TIME setup for this test.
111  */
setup(void)112 void setup(void)
113 {
114 
115 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
116 
117 	TEST_PAUSE;
118 }
119 
120 /******************************************************************
121  * sig11_handler() - our segfault recover hack
122  ******************************************************************/
sig11_handler(int sig LTP_ATTRIBUTE_UNUSED)123 void sig11_handler(int sig LTP_ATTRIBUTE_UNUSED)
124 {
125 	longjmp(sig11_recover, 1);
126 }
127 
128 /*
129  * cleanup() - performs all ONE TIME cleanup for this test at
130  *	       completion or premature exit.
131  */
cleanup(void)132 void cleanup(void)
133 {
134 }
135