plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * NAME |
| 22 | * waitpid13.c |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 23 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 24 | * DESCRIPTION |
| 25 | * Tests to see if pid's returned from fork and waitpid are same |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 26 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 27 | * ALGORITHM |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 28 | * Check proper functioning of waitpid with pid = 0 and < -1 with arg |
| 29 | * WUNTRACED |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 30 | * |
| 31 | * USAGE: <for command-line> |
| 32 | * waitpid13 [-c n] [-t] |
| 33 | * where, -c n : Run n copies concurrently. |
| 34 | * -t : Turn on syscall timing. |
| 35 | * |
| 36 | * History |
| 37 | * 07/2001 John George |
| 38 | * -Ported |
robbiew | 4644c7e | 2002-04-26 14:33:32 +0000 | [diff] [blame] | 39 | * 04/2002 wjhuie sigset cleanups |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 40 | * |
| 41 | * Restrictions |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 42 | * None |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 43 | */ |
| 44 | |
| 45 | #include <sys/types.h> |
| 46 | #include <signal.h> |
| 47 | #include <errno.h> |
| 48 | #include <sys/wait.h> |
Garrett Cooper | e8530df | 2010-12-21 11:37:57 -0800 | [diff] [blame] | 49 | #include "test.h" |
| 50 | #include "usctest.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 51 | |
| 52 | #define MAXKIDS 8 |
| 53 | |
| 54 | char *TCID = "waitpid13"; |
| 55 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 56 | |
robbiew | 3d5c735 | 2003-01-13 17:49:51 +0000 | [diff] [blame] | 57 | volatile int intintr; |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 58 | static void setup(void); |
| 59 | static void cleanup(void); |
| 60 | static void inthandlr(); |
| 61 | static void wait_for_parent(void); |
| 62 | static void do_exit(void); |
| 63 | static void setup_sigint(void); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 64 | #ifdef UCLINUX |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 65 | static void do_exit_uclinux(void); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 66 | #endif |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 68 | static int fail; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 69 | |
plars | ac85d1c | 2002-06-10 14:52:37 +0000 | [diff] [blame] | 70 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 71 | { |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 72 | char *msg; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 73 | |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 74 | int kid_count, ret_val, status; |
| 75 | int i, j, k, found; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | int group1, group2; |
| 77 | int fork_kid_pid[MAXKIDS], wait_kid_pid[MAXKIDS]; |
| 78 | int pid; |
| 79 | |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 80 | msg = parse_opts(ac, av, NULL, NULL); |
| 81 | if (msg != NULL) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 82 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 83 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 84 | #ifdef UCLINUX |
| 85 | maybe_run_child(&do_exit_uclinux, ""); |
| 86 | #endif |
| 87 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | setup(); |
| 89 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 90 | tst_count = 0; |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 91 | fail = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 92 | |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 93 | /* |
| 94 | * Need to have test run from child as test driver causes |
| 95 | * test to be a session leader and setpgrp fails. |
| 96 | */ |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 97 | pid = FORK_OR_VFORK(); |
| 98 | if (pid > 0) { |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 99 | waitpid(pid, &status, 0); |
| 100 | if (WEXITSTATUS(status) != 0) { |
| 101 | tst_resm(TFAIL, "child returned bad status"); |
| 102 | fail = 1; |
| 103 | } |
| 104 | if (fail) |
| 105 | tst_resm(TFAIL, "%s FAILED", TCID); |
| 106 | else |
| 107 | tst_resm(TPASS, "%s PASSED", TCID); |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 108 | |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 109 | cleanup(); |
| 110 | tst_exit(); |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 111 | } else if (pid < 0) { |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 112 | tst_brkm(TBROK, cleanup, "fork failed"); |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 113 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 114 | |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 115 | /* |
| 116 | * Set up to catch SIGINT. The kids will wait till a SIGINT |
| 117 | * has been received before they proceed. |
| 118 | */ |
| 119 | setup_sigint(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 120 | |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 121 | group1 = getpgrp(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 122 | |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 123 | for (kid_count = 0; kid_count < MAXKIDS; kid_count++) { |
| 124 | if (kid_count == (MAXKIDS / 2)) |
| 125 | group2 = setpgrp(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 126 | |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 127 | intintr = 0; |
| 128 | ret_val = FORK_OR_VFORK(); |
| 129 | if (ret_val == 0) { |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 130 | #ifdef UCLINUX |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 131 | if (self_exec(av[0], "") < 0) { |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 132 | tst_resm(TFAIL | TERRNO, "self_exec kid %d " |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 133 | "failed", kid_count); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 134 | |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 135 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 136 | #else |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 137 | do_exit(); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 138 | #endif |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 141 | if (ret_val < 0) |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 142 | tst_resm(TFAIL | TERRNO, "forking kid %d failed", |
| 143 | kid_count); |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 144 | |
| 145 | /* parent */ |
| 146 | fork_kid_pid[kid_count] = ret_val; |
| 147 | } |
| 148 | |
| 149 | /* Check that waitpid with WNOHANG|WUNTRACED returns zero */ |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 150 | ret_val = waitpid(0, &status, WNOHANG | WUNTRACED); |
| 151 | if (ret_val != 0) { |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 152 | tst_resm(TFAIL, "Waitpid returned wrong value" |
| 153 | "from waitpid(WNOHANG|WUNTRACED)"); |
| 154 | tst_resm(TFAIL, "Expected 0 got %d", ret_val); |
| 155 | fail = 1; |
| 156 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 157 | #ifdef UCLINUX |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 158 | /* Give the kids a chance to setup SIGINT again, since this is |
| 159 | * cleared by exec(). |
| 160 | */ |
| 161 | sleep(3); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 162 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 163 | |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 164 | /* Now send all the kids a SIGINT to tell them to proceed */ |
| 165 | for (i = 0; i < MAXKIDS; i++) { |
| 166 | if (kill(fork_kid_pid[i], SIGINT) < 0) { |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 167 | tst_resm(TFAIL | TERRNO, "killing child %d failed", i); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 168 | fail = 1; |
| 169 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 170 | } |
robbiew | aa01abd | 2003-03-27 18:39:24 +0000 | [diff] [blame] | 171 | |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 172 | /* |
| 173 | * Wait till all kids have terminated. Stash away their |
| 174 | * pid's in an array. |
| 175 | */ |
| 176 | kid_count = 0; |
| 177 | errno = 0; |
| 178 | while (((ret_val = waitpid(0, &status, WUNTRACED)) != -1) || |
| 179 | (errno == EINTR)) { |
| 180 | if (ret_val == -1) |
| 181 | continue; |
| 182 | |
| 183 | if (!WIFEXITED(status)) { |
| 184 | if (!WIFSTOPPED(status)) { |
| 185 | tst_resm(TFAIL, "Child %d is not " |
| 186 | "stopped", ret_val); |
| 187 | fail = 1; |
| 188 | } else { |
| 189 | if (WSTOPSIG(status) != SIGSTOP) { |
| 190 | tst_resm(TFAIL, "Child %d " |
| 191 | "exited with wrong " |
| 192 | "status", ret_val); |
| 193 | tst_resm(TFAIL, "Expected " |
| 194 | "SIGSTOP got %d", |
| 195 | WEXITSTATUS(status)); |
| 196 | fail = 1; |
| 197 | } |
| 198 | } |
| 199 | if (kill(ret_val, SIGCONT) < 0) { |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 200 | tst_resm(TFAIL | TERRNO, |
| 201 | "killing child %d failed", ret_val); |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 202 | fail = 1; |
| 203 | } |
| 204 | } |
| 205 | found = 0; |
| 206 | for (j = 0; j < kid_count; j++) { |
| 207 | if (ret_val == wait_kid_pid[j]) { |
| 208 | found = 1; |
| 209 | break; |
| 210 | } |
| 211 | } |
| 212 | if (!found) |
| 213 | wait_kid_pid[kid_count++] = ret_val; |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | * Check that for every entry in the fork_kid_pid array, |
| 218 | * there is a matching pid in the wait_kid_pid array. If |
| 219 | * not, it's an error. |
| 220 | */ |
| 221 | for (i = 0; i < kid_count; i++) { |
| 222 | found = 0; |
| 223 | for (j = (MAXKIDS / 2); j < MAXKIDS; j++) { |
| 224 | if (fork_kid_pid[j] == wait_kid_pid[i]) { |
| 225 | found = 1; |
| 226 | break; |
| 227 | } |
| 228 | } |
| 229 | if (!found) { |
| 230 | tst_resm(TFAIL, "Did not find a wait_kid_pid " |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 231 | "for the fork_kid_pid of %d", wait_kid_pid[i]); |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 232 | for (k = 0; k < MAXKIDS; k++) |
| 233 | tst_resm(TFAIL, "fork_kid_pid[%d] = " |
| 234 | "%d", k, fork_kid_pid[k]); |
| 235 | for (k = 0; k < kid_count; k++) |
| 236 | tst_resm(TFAIL, "wait_kid_pid[%d] = " |
| 237 | "%d", k, wait_kid_pid[k]); |
| 238 | fail = 1; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | if (kid_count != (MAXKIDS / 2)) { |
| 243 | tst_resm(TFAIL, "Wrong number of children waited on " |
| 244 | "for pid = 0"); |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 245 | tst_resm(TFAIL, "Expected %d got %d", MAXKIDS, kid_count); |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 246 | fail = 1; |
| 247 | } |
| 248 | |
| 249 | /* Make sure can pickup children in a diff. process group */ |
| 250 | |
| 251 | kid_count = 0; |
| 252 | errno = 0; |
| 253 | while (((ret_val = waitpid(-(group1), &status, WUNTRACED)) != |
| 254 | -1) || (errno == EINTR)) { |
| 255 | if (ret_val == -1) |
| 256 | continue; |
| 257 | if (!WIFEXITED(status)) { |
| 258 | if (!WIFSTOPPED(status)) { |
| 259 | tst_resm(TFAIL, "Child %d is not " |
| 260 | "stopped", ret_val); |
| 261 | fail = 1; |
| 262 | } else { |
| 263 | if (WSTOPSIG(status) != SIGSTOP) { |
| 264 | tst_resm(TFAIL, "Child %d " |
| 265 | "exited with wrong " |
| 266 | "status", ret_val); |
| 267 | tst_resm(TFAIL, "Expected " |
| 268 | "SIGSTOP got %d", |
| 269 | WEXITSTATUS(status)); |
| 270 | fail = 1; |
| 271 | } |
| 272 | } |
| 273 | if (kill(ret_val, SIGCONT) < 0) { |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 274 | tst_resm(TFAIL | TERRNO, |
| 275 | "Killing child %d failed", ret_val); |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 276 | fail = 1; |
| 277 | } |
| 278 | } |
| 279 | found = 0; |
| 280 | for (j = 0; j < kid_count; j++) { |
| 281 | if (ret_val == wait_kid_pid[j]) { |
| 282 | found = 1; |
| 283 | break; |
| 284 | } |
| 285 | } |
| 286 | if (!found) |
| 287 | wait_kid_pid[kid_count++] = ret_val; |
| 288 | } |
| 289 | |
| 290 | /* |
| 291 | * Check that for every entry in the fork_kid_pid array, |
| 292 | * there is a matching pid in the wait_kid_pid array. If |
| 293 | * not, it's an error. |
| 294 | */ |
| 295 | for (i = 0; i < kid_count; i++) { |
| 296 | found = 0; |
| 297 | for (j = 0; j < (MAXKIDS / 2); j++) { |
| 298 | if (fork_kid_pid[j] == wait_kid_pid[i]) { |
| 299 | found = 1; |
| 300 | break; |
| 301 | } |
| 302 | } |
| 303 | if (!found) { |
| 304 | tst_resm(TFAIL, "Did not find a wait_kid_pid " |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 305 | "for the fork_kid_pid of %d", fork_kid_pid[j]); |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 306 | for (k = 0; k < MAXKIDS; k++) |
| 307 | tst_resm(TFAIL, "fork_kid_pid[%d] = " |
| 308 | "%d", k, fork_kid_pid[k]); |
| 309 | for (k = 0; k < kid_count; k++) |
| 310 | tst_resm(TFAIL, "wait_kid_pid[%d] = " |
| 311 | "%d", k, wait_kid_pid[k]); |
| 312 | fail = 1; |
| 313 | } |
| 314 | } |
| 315 | if (kid_count != (MAXKIDS / 2)) { |
| 316 | tst_resm(TFAIL, "Wrong number of children waited on " |
| 317 | "for pid = 0"); |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 318 | tst_resm(TFAIL, "Expected %d got %d", MAXKIDS, kid_count); |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 319 | fail = 1; |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | * Check that waitpid(WUNTRACED) returns -1 when no stopped |
| 324 | * children |
| 325 | */ |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 326 | ret_val = waitpid(-1, &status, WUNTRACED); |
| 327 | if (ret_val != -1) { |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 328 | tst_resm(TFAIL, "Waitpid returned wrong value."); |
| 329 | tst_resm(TFAIL, "Expected -1 got %d", ret_val); |
| 330 | fail = 1; |
| 331 | } |
| 332 | |
| 333 | if (errno != ECHILD) { |
| 334 | tst_resm(TFAIL, "Expected ECHILD from waitpid(WUNTRACED)"); |
| 335 | fail = 1; |
| 336 | } |
| 337 | |
| 338 | if (fail) |
| 339 | tst_resm(TFAIL, "Test FAILED"); |
| 340 | else |
| 341 | tst_resm(TPASS, "Test PASSED"); |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 342 | |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 343 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 346 | static void setup_sigint(void) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 347 | { |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 348 | if (signal(SIGINT, inthandlr) == SIG_ERR) |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 349 | tst_brkm(TFAIL | TERRNO, NULL, "signal SIGINT failed"); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 352 | static void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 353 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 354 | TEST_PAUSE; |
| 355 | } |
| 356 | |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 357 | static void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 358 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 359 | TEST_CLEANUP; |
Garrett Cooper | c548a31 | 2011-03-04 02:12:05 -0800 | [diff] [blame] | 360 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 361 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame^] | 362 | static void inthandlr(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 363 | { |
| 364 | intintr++; |
| 365 | } |
| 366 | |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 367 | static void wait_for_parent(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 368 | { |
| 369 | int testvar; |
| 370 | |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 371 | while (!intintr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 372 | testvar = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 375 | static void do_exit(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 376 | { |
| 377 | wait_for_parent(); |
| 378 | kill(getpid(), SIGSTOP); |
| 379 | exit(3); |
| 380 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 381 | |
| 382 | #ifdef UCLINUX |
Wanlong Gao | 04cfe1b | 2012-11-20 10:32:33 +0800 | [diff] [blame] | 383 | static void do_exit_uclinux(void) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 384 | { |
| 385 | setup_sigint(); |
| 386 | do_exit(); |
| 387 | } |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 388 | #endif |