1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker *
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker *
5*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker * it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker * the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker * (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker *
10*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13*49cdfc7eSAndroid Build Coastguard Worker * the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker *
15*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker * along with this program; if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker */
19*49cdfc7eSAndroid Build Coastguard Worker
20*49cdfc7eSAndroid Build Coastguard Worker /*
21*49cdfc7eSAndroid Build Coastguard Worker * NAME
22*49cdfc7eSAndroid Build Coastguard Worker * pipe05.c
23*49cdfc7eSAndroid Build Coastguard Worker *
24*49cdfc7eSAndroid Build Coastguard Worker * DESCRIPTION
25*49cdfc7eSAndroid Build Coastguard Worker * Check what happens when pipe is passed a bad file descriptor.
26*49cdfc7eSAndroid Build Coastguard Worker *
27*49cdfc7eSAndroid Build Coastguard Worker * ALGORITHM
28*49cdfc7eSAndroid Build Coastguard Worker * Issue the pipe call with a bad file descriptor.
29*49cdfc7eSAndroid Build Coastguard Worker * Check that we get EFAULT.
30*49cdfc7eSAndroid Build Coastguard Worker *
31*49cdfc7eSAndroid Build Coastguard Worker * USAGE: <for command-line>
32*49cdfc7eSAndroid Build Coastguard Worker * pipe05 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
33*49cdfc7eSAndroid Build Coastguard Worker * where, -c n : Run n copies concurrently.
34*49cdfc7eSAndroid Build Coastguard Worker * -e : Turn on errno logging.
35*49cdfc7eSAndroid Build Coastguard Worker * -i n : Execute test n times.
36*49cdfc7eSAndroid Build Coastguard Worker * -I x : Execute test for x seconds.
37*49cdfc7eSAndroid Build Coastguard Worker * -P x : Pause for x seconds between iterations.
38*49cdfc7eSAndroid Build Coastguard Worker * -t : Turn on syscall timing.
39*49cdfc7eSAndroid Build Coastguard Worker *
40*49cdfc7eSAndroid Build Coastguard Worker * HISTORY
41*49cdfc7eSAndroid Build Coastguard Worker * 07/2001 Ported by Wayne Boyer
42*49cdfc7eSAndroid Build Coastguard Worker *
43*49cdfc7eSAndroid Build Coastguard Worker * RESTRICTIONS
44*49cdfc7eSAndroid Build Coastguard Worker * None
45*49cdfc7eSAndroid Build Coastguard Worker */
46*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
47*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
48*49cdfc7eSAndroid Build Coastguard Worker #include <setjmp.h>
49*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
50*49cdfc7eSAndroid Build Coastguard Worker
51*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "pipe05";
52*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1;
53*49cdfc7eSAndroid Build Coastguard Worker
54*49cdfc7eSAndroid Build Coastguard Worker intptr_t pipes;
55*49cdfc7eSAndroid Build Coastguard Worker void setup(void);
56*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void);
57*49cdfc7eSAndroid Build Coastguard Worker jmp_buf sig11_recover;
58*49cdfc7eSAndroid Build Coastguard Worker void sig11_handler(int sig);
59*49cdfc7eSAndroid Build Coastguard Worker
main(int ac,char ** av)60*49cdfc7eSAndroid Build Coastguard Worker int main(int ac, char **av)
61*49cdfc7eSAndroid Build Coastguard Worker {
62*49cdfc7eSAndroid Build Coastguard Worker volatile int lc;
63*49cdfc7eSAndroid Build Coastguard Worker struct sigaction sa, osa;
64*49cdfc7eSAndroid Build Coastguard Worker
65*49cdfc7eSAndroid Build Coastguard Worker tst_parse_opts(ac, av, NULL, NULL);
66*49cdfc7eSAndroid Build Coastguard Worker
67*49cdfc7eSAndroid Build Coastguard Worker setup();
68*49cdfc7eSAndroid Build Coastguard Worker
69*49cdfc7eSAndroid Build Coastguard Worker for (lc = 0; TEST_LOOPING(lc); lc++) {
70*49cdfc7eSAndroid Build Coastguard Worker
71*49cdfc7eSAndroid Build Coastguard Worker /* reset tst_count in case we are looping */
72*49cdfc7eSAndroid Build Coastguard Worker tst_count = 0;
73*49cdfc7eSAndroid Build Coastguard Worker /* special sig11 case */
74*49cdfc7eSAndroid Build Coastguard Worker sa.sa_handler = &sig11_handler;
75*49cdfc7eSAndroid Build Coastguard Worker sigemptyset(&sa.sa_mask);
76*49cdfc7eSAndroid Build Coastguard Worker sa.sa_flags = 0;
77*49cdfc7eSAndroid Build Coastguard Worker
78*49cdfc7eSAndroid Build Coastguard Worker sigaction(SIGSEGV, NULL, &osa);
79*49cdfc7eSAndroid Build Coastguard Worker sigaction(SIGSEGV, &sa, NULL);
80*49cdfc7eSAndroid Build Coastguard Worker
81*49cdfc7eSAndroid Build Coastguard Worker if (setjmp(sig11_recover)) {
82*49cdfc7eSAndroid Build Coastguard Worker TEST_RETURN = -1;
83*49cdfc7eSAndroid Build Coastguard Worker TEST_ERRNO = EFAULT;
84*49cdfc7eSAndroid Build Coastguard Worker } else {
85*49cdfc7eSAndroid Build Coastguard Worker TEST(pipe((int *)pipes));
86*49cdfc7eSAndroid Build Coastguard Worker }
87*49cdfc7eSAndroid Build Coastguard Worker sigaction(SIGSEGV, &osa, NULL);
88*49cdfc7eSAndroid Build Coastguard Worker
89*49cdfc7eSAndroid Build Coastguard Worker if (TEST_RETURN != -1) {
90*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "call succeeded unexpectedly");
91*49cdfc7eSAndroid Build Coastguard Worker }
92*49cdfc7eSAndroid Build Coastguard Worker
93*49cdfc7eSAndroid Build Coastguard Worker if (TEST_ERRNO != EFAULT) {
94*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "unexpected error - %d : %s - "
95*49cdfc7eSAndroid Build Coastguard Worker "expected EMFILE", TEST_ERRNO,
96*49cdfc7eSAndroid Build Coastguard Worker strerror(TEST_ERRNO));
97*49cdfc7eSAndroid Build Coastguard Worker } else {
98*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TPASS, "expected failure - "
99*49cdfc7eSAndroid Build Coastguard Worker "errno = %d : %s", TEST_ERRNO,
100*49cdfc7eSAndroid Build Coastguard Worker strerror(TEST_ERRNO));
101*49cdfc7eSAndroid Build Coastguard Worker }
102*49cdfc7eSAndroid Build Coastguard Worker
103*49cdfc7eSAndroid Build Coastguard Worker }
104*49cdfc7eSAndroid Build Coastguard Worker cleanup();
105*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
106*49cdfc7eSAndroid Build Coastguard Worker
107*49cdfc7eSAndroid Build Coastguard Worker }
108*49cdfc7eSAndroid Build Coastguard Worker
109*49cdfc7eSAndroid Build Coastguard Worker /*
110*49cdfc7eSAndroid Build Coastguard Worker * setup() - performs all ONE TIME setup for this test.
111*49cdfc7eSAndroid Build Coastguard Worker */
setup(void)112*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
113*49cdfc7eSAndroid Build Coastguard Worker {
114*49cdfc7eSAndroid Build Coastguard Worker
115*49cdfc7eSAndroid Build Coastguard Worker tst_sig(NOFORK, DEF_HANDLER, cleanup);
116*49cdfc7eSAndroid Build Coastguard Worker
117*49cdfc7eSAndroid Build Coastguard Worker TEST_PAUSE;
118*49cdfc7eSAndroid Build Coastguard Worker }
119*49cdfc7eSAndroid Build Coastguard Worker
120*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************
121*49cdfc7eSAndroid Build Coastguard Worker * sig11_handler() - our segfault recover hack
122*49cdfc7eSAndroid Build Coastguard Worker ******************************************************************/
sig11_handler(int sig LTP_ATTRIBUTE_UNUSED)123*49cdfc7eSAndroid Build Coastguard Worker void sig11_handler(int sig LTP_ATTRIBUTE_UNUSED)
124*49cdfc7eSAndroid Build Coastguard Worker {
125*49cdfc7eSAndroid Build Coastguard Worker longjmp(sig11_recover, 1);
126*49cdfc7eSAndroid Build Coastguard Worker }
127*49cdfc7eSAndroid Build Coastguard Worker
128*49cdfc7eSAndroid Build Coastguard Worker /*
129*49cdfc7eSAndroid Build Coastguard Worker * cleanup() - performs all ONE TIME cleanup for this test at
130*49cdfc7eSAndroid Build Coastguard Worker * completion or premature exit.
131*49cdfc7eSAndroid Build Coastguard Worker */
cleanup(void)132*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void)
133*49cdfc7eSAndroid Build Coastguard Worker {
134*49cdfc7eSAndroid Build Coastguard Worker }
135