2 Copyright (C) 2004 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
32 /* First thing, we stop ourselves. */
35 /* Hey, we got continued! */
43 # define WSTOPPED WUNTRACED
47 do_test (int argc, char *argv[])
52 error (0, errno, "fork");
61 /* Give the child a chance to stop. */
64 /* Now try a wait that should not succeed. */
66 info.si_signo = 0; /* A successful call sets it to SIGCHLD. */
67 int fail = waitid (P_PID, pid, &info, WEXITED|WCONTINUED|WNOHANG);
71 error (0, 0, "waitid returned bogus value %d\n", fail);
74 error (0, errno, "waitid WNOHANG on stopped");
75 return errno == ENOTSUP ? EXIT_SUCCESS : EXIT_FAILURE;
77 if (info.si_signo == 0)
79 if (info.si_signo == SIGCHLD)
80 error (0, 0, "waitid WNOHANG on stopped status %d\n", info.si_status);
82 error (0, 0, "waitid WNOHANG on stopped signal %d\n", info.si_signo);
86 /* Next the wait that should succeed right away. */
87 info.si_signo = 0; /* A successful call sets it to SIGCHLD. */
90 fail = waitid (P_PID, pid, &info, WSTOPPED|WNOHANG);
94 error (0, 0, "waitid WSTOPPED|WNOHANG returned bogus value %d\n", fail);
97 error (0, errno, "waitid WSTOPPED|WNOHANG on stopped");
98 return errno == ENOTSUP ? EXIT_SUCCESS : EXIT_FAILURE;
100 if (info.si_signo != SIGCHLD)
102 error (0, 0, "waitid WSTOPPED|WNOHANG on stopped signal %d\n",
106 if (info.si_code != CLD_STOPPED)
108 error (0, 0, "waitid WSTOPPED|WNOHANG on stopped code %d\n",
112 if (info.si_status != SIGSTOP)
114 error (0, 0, "waitid WSTOPPED|WNOHANG on stopped status %d\n",
118 if (info.si_pid != pid)
120 error (0, 0, "waitid WSTOPPED|WNOHANG on stopped pid %d != %d\n",
126 if (kill (pid, SIGCONT) != 0)
128 error (0, errno, "kill (%d, SIGCONT)", pid);
132 /* Wait for the child to have continued. */
136 info.si_signo = 0; /* A successful call sets it to SIGCHLD. */
139 fail = waitid (P_PID, pid, &info, WCONTINUED);
143 error (0, 0, "waitid WCONTINUED returned bogus value %d\n", fail);
146 error (0, errno, "waitid WCONTINUED on continued");
147 return errno == ENOTSUP ? EXIT_SUCCESS : EXIT_FAILURE;
149 if (info.si_signo != SIGCHLD)
151 error (0, 0, "waitid WCONTINUED on continued signal %d\n",
155 if (info.si_code != CLD_CONTINUED)
157 error (0, 0, "waitid WCONTINUED on continued code %d\n",
161 if (info.si_status != SIGCONT)
163 error (0, 0, "waitid WCONTINUED on continued status %d\n",
167 if (info.si_pid != pid)
169 error (0, 0, "waitid WCONTINUED on continued pid %d != %d\n",
176 /* Die, child, die! */
177 if (kill (pid, SIGKILL) != 0)
179 error (0, errno, "kill (%d, SIGKILL)", pid);
184 info.si_signo = 0; /* A successful call sets it to SIGCHLD. */
187 fail = waitid (P_PID, pid, &info, WEXITED|WNOWAIT);
191 error (0, 0, "waitid WNOWAIT returned bogus value %d\n", fail);
194 error (0, errno, "waitid WNOWAIT on killed");
195 return errno == ENOTSUP ? EXIT_SUCCESS : EXIT_FAILURE;
197 if (info.si_signo != SIGCHLD)
199 error (0, 0, "waitid WNOWAIT on killed signal %d\n",
203 if (info.si_code != CLD_KILLED)
205 error (0, 0, "waitid WNOWAIT on killed code %d\n",
209 if (info.si_status != SIGKILL)
211 error (0, 0, "waitid WNOWAIT on killed status %d\n",
215 if (info.si_pid != pid)
217 error (0, 0, "waitid WNOWAIT on killed pid %d != %d\n",
223 /* Allow enough time to be sure the child died; we didn't synchronize. */
227 info.si_signo = 0; /* A successful call sets it to SIGCHLD. */
230 fail = waitid (P_PID, pid, &info, WEXITED|WNOHANG);
234 error (0, 0, "waitid WNOHANG returned bogus value %d\n", fail);
237 error (0, errno, "waitid WNOHANG on killed");
240 if (info.si_signo != SIGCHLD)
242 error (0, 0, "waitid WNOHANG on killed signal %d\n",
246 if (info.si_code != CLD_KILLED)
248 error (0, 0, "waitid WNOHANG on killed code %d\n",
252 if (info.si_status != SIGKILL)
254 error (0, 0, "waitid WNOHANG on killed status %d\n",
258 if (info.si_pid != pid)
260 error (0, 0, "waitid WNOHANG on killed pid %d != %d\n",
266 fail = waitid (P_PID, pid, &info, WEXITED);
271 error (0, errno, "waitid WEXITED on killed");
277 error (0, 0, "waitid WEXITED returned bogus value %d\n", fail);
284 #include "../test-skeleton.c"