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 */
76 void cleanup(void) __attribute__((noreturn));
79 const char *TCID= "wait402()";
83 int exp_enos[] = {10, 0};
86 main(int ac, char **av)
88 int lc; /* loop counter */
89 const char *msg; /* message returned from parse_opts */
91 pid_t epid = PID_MAX + 1;
93 struct rusage *rusage=NULL;
95 /* parse standard options */
96 if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL) {
97 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
100 setup(); /* global setup */
102 /* The following loop checks looping state if -i option given */
104 for (lc = 0; TEST_LOOPING(lc); lc++) {
105 /* reset Tst_count in case we are looping */
110 * Allocate some space for the rusage structure.
113 if ((rusage = (struct rusage *)malloc(sizeof(struct rusage)))
115 tst_brkm(TBROK, cleanup, "malloc() failed");
121 tst_brkm(TBROK, cleanup, "fork() failed");
124 if (pid == 0) { /* this is the child */
126 * sleep for a moment to let us do the test
130 } else { /* this is the parent */
132 * call wait4 with the TEST() macro. epid is set
133 * to an illegal positive value. This should give
136 TEST(wait4(epid, &status, 0, rusage));
139 if (TEST_RETURN == 0) {
140 tst_brkm(TFAIL, cleanup, "call failed to produce expected error - errno = %d - %s", TEST_ERRNO, strerror(TEST_ERRNO));
143 TEST_ERROR_LOG(TEST_ERRNO);
145 switch (TEST_ERRNO) {
147 tst_resm(TPASS, "received expected failure - errno = %d - %s",
148 TEST_ERRNO, strerror(TEST_ERRNO));
151 tst_brkm(TFAIL, cleanup, "call failed to produce expected "
152 "error - errno = %d - %s", TEST_ERRNO,
153 strerror(TEST_ERRNO));
157 * Clean up things in case we are looping.
160 wait4(pid, &status, 0, rusage);
172 * setup() - performs all the ONE TIME setup for this test.
177 /* capture signals */
178 tst_sig(FORK, DEF_HANDLER, cleanup);
180 /* Set up the expected error numbers for -e option */
181 TEST_EXP_ENOS(exp_enos);
183 /* Pause if that option was specified */
188 * cleanup() - performs all the ONE TIME cleanup for this test at completion
195 * print timing stats if that option was specified.
196 * print errno log if that option was specified.
200 /* exit with return code appropriate for results */