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