3 * Copyright (c) International Business Machines Corp., 2001
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.
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.
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
25 * wait402 - check for ECHILD errno when using an illegal pid value
28 * loop if that option was specified
29 * issue the system call with an illegal pid value
30 * check the errno value
31 * issue a PASS message if we get ECHILD
32 * otherwise, the tests fails
33 * issue a FAIL message
34 * break any remaining tests
37 * USAGE: <for command-line>
38 * wait402 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
39 * where, -c n : Run n copies concurrently.
40 * -e : Turn on errno logging.
41 * -i n : Execute test n times.
42 * -I x : Execute test for x seconds.
43 * -P x : Pause for x seconds between iterations.
44 * -t : Turn on syscall timing.
59 #include <sys/types.h>
60 #include <sys/resource.h>
64 * See the Makefile for comments about the following preprocessor code.
66 #if defined (__CYGWIN__)
67 #define PID_MAX 0xfffffffd
70 #include <linux/threads.h> /* for PID_MAX value - new */
72 #include <linux/tasks.h> /* for PID_MAX value - old */
79 char *TCID= "wait402()";
83 int exp_enos[] = {10, 0};
85 main(int ac, char **av)
87 int lc; /* loop counter */
88 const char *msg; /* message returned from parse_opts */
90 pid_t epid = PID_MAX + 1;
92 struct rusage *rusage=NULL;
94 /* parse standard options */
95 if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL) {
96 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
99 setup(); /* global setup */
101 /* The following loop checks looping state if -i option given */
103 for (lc = 0; TEST_LOOPING(lc); lc++) {
104 /* reset Tst_count in case we are looping */
109 * Allocate some space for the rusage structure.
112 if ((rusage = (struct rusage *)malloc(sizeof(struct rusage)))
114 tst_brkm(TBROK, cleanup, "malloc() failed");
120 tst_brkm(TBROK, cleanup, "fork() failed");
123 if (pid == 0) { /* this is the child */
125 * sleep for a moment to let us do the test
129 } else { /* this is the parent */
131 * call wait4 with the TEST() macro. epid is set
132 * to an illegal positive value. This should give
135 TEST(wait4(epid, &status, 0, rusage));
138 if (TEST_RETURN == 0) {
139 tst_brkm(TFAIL, cleanup, "call failed to produce expected error - errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO));
142 TEST_ERROR_LOG(TEST_ERRNO);
144 switch (TEST_ERRNO) {
146 tst_resm(TPASS, "received expected failure - errno = %d - %s",
147 TEST_ERRNO, strerror(TEST_ERRNO));
150 tst_brkm(TFAIL, cleanup, "call failed to produce expected "
151 "error - errno = %d - %s", TEST_ERRNO,
152 strerror(TEST_ERRNO));
156 * Clean up things in case we are looping.
159 wait4(pid, &status, 0, rusage);
171 * setup() - performs all the ONE TIME setup for this test.
176 /* capture signals */
177 tst_sig(FORK, DEF_HANDLER, cleanup);
179 /* Set up the expected error numbers for -e option */
180 TEST_EXP_ENOS(exp_enos);
182 /* Pause if that option was specified */
187 * cleanup() - performs all the ONE TIME cleanup for this test at completion
194 * print timing stats if that option was specified.
195 * print errno log if that option was specified.
199 /* exit with return code appropriate for results */