blob: 1834ae82a3dcea5594bab0e86d8488c803b9628c [file] [log] [blame]
robbiewbd756502002-12-04 23:16:31 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2002
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 Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiewbd756502002-12-04 23:16:31 +000018 */
19
20/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
21/* 10/30/2002 Port to LTP dbarrera@us.ibm.com */
22
23/*
24 * NAME
25 * mkdir.c - Stress test of mkdir call.
26 *
27 * CALLS
28 * mkdir, rmdir
29 *
30 * ALGORITHM
31 * Create multiple processes which create subdirectories in the
32 * same directory multiple times. On exit of all child processes,
33 * make sure all subdirectories can be removed.
34 *
35 * USAGE: mkdir09 -c # -t # -d #
36 * -c = number of children groups
37 * -t = number of seconds to run test
38 * -d = number of directories created in test directory
39 *
40 * RESTRICTIONS
41 *
42 */
43
subrata_modak56207ce2009-03-23 13:35:39 +000044#include <stdio.h> /* needed by testhead.h */
45#include <wait.h> /* needed by testhead.h */
robbiewbd756502002-12-04 23:16:31 +000046#include <sys/types.h>
47#include <sys/param.h>
48#include <sys/stat.h>
49#include <sys/mman.h>
50#include <errno.h>
51#include <signal.h>
52#include <unistd.h>
53#include <setjmp.h>
54#include "test.h"
55#include "usctest.h"
56
robbiewbd756502002-12-04 23:16:31 +000057#include <stdlib.h>
Garrett Cooperbacc8492011-01-14 00:36:17 -080058#include <stdlib.h>
robbiewbd756502002-12-04 23:16:31 +000059#include <string.h>
60
subrata_modakbdbaec52009-02-26 12:14:51 +000061#define NCHILD 3
robbiewbd756502002-12-04 23:16:31 +000062
63#define MODE_RWX 07770
64#define DIR_NAME "./X.%d"
65
66/* used by getopt */
67extern char *optarg;
68extern int optind, opterr;
69char *goodopts = "c:t:d:";
70int errflg;
71
robbiewbd756502002-12-04 23:16:31 +000072/*
73 * * These globals must be defined in the test.
74 * */
75
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020076char *TCID = "mkdir09";
77int TST_TOTAL = 1;
robbiewbd756502002-12-04 23:16:31 +000078
subrata_modak56207ce2009-03-23 13:35:39 +000079int exp_enos[] = { EFAULT, 0 }; /* List must end with 0 */
robbiewbd756502002-12-04 23:16:31 +000080
81int child_groups, test_time, nfiles;
82char testdir[MAXPATHLEN];
83int parent_pid, sigchld, sigterm, jump;
84void term();
85void chld();
subrata_modak56207ce2009-03-23 13:35:39 +000086int *pidlist, child_count;
robbiewbd756502002-12-04 23:16:31 +000087jmp_buf env_buf;
88
subrata_modak56207ce2009-03-23 13:35:39 +000089int getchild(int group, int child, int children);
robbiewbd756502002-12-04 23:16:31 +000090int dochild1();
91int dochild2();
92int dochild3(int group);
93int massmurder();
94int runtest();
95void setup();
96void cleanup();
97
robbiewd34d5812005-07-11 22:28:09 +000098#ifdef UCLINUX
99static char *argv0;
100void dochild1_uclinux();
101void dochild2_uclinux();
102void dochild3_uclinux();
103static int group_uclinux;
104#endif
105
robbiewbd756502002-12-04 23:16:31 +0000106/*--------------------------------------------------------------*/
107/*--------------------------------------------------------------*/
108/*--------------------------------------------------------------*/
subrata_modak56207ce2009-03-23 13:35:39 +0000109int main(argc, argv)
110int argc;
robbiewbd756502002-12-04 23:16:31 +0000111char *argv[];
112{
robbiewe0cf2e22002-12-11 20:29:15 +0000113 int c;
robbiewbd756502002-12-04 23:16:31 +0000114
robbiewd34d5812005-07-11 22:28:09 +0000115#ifdef UCLINUX
116 char *msg;
117
Wanlong Gao354ebb42012-12-07 10:10:04 +0800118 if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) {
robbiewd34d5812005-07-11 22:28:09 +0000119 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
120 }
121
122 argv0 = argv[0];
123 maybe_run_child(&dochild1_uclinux, "nd", 1, &nfiles);
124 maybe_run_child(&dochild2_uclinux, "n", 2);
125 maybe_run_child(&dochild3_uclinux, "nd", 3, &group_uclinux);
126#endif
127
robbiewbd756502002-12-04 23:16:31 +0000128 setup();
129
130 /* Set up to catch SIGTERM signal */
subrata_modak56207ce2009-03-23 13:35:39 +0000131 if (signal(SIGTERM, term) == SIG_ERR) {
132 tst_brkm(TFAIL, cleanup,
133 "Error setting up SIGTERM signal, ERRNO = %d", errno);
Garrett Cooper2c282152010-12-16 00:55:50 -0800134
robbiewbd756502002-12-04 23:16:31 +0000135 }
136
137 /* Set up to catch SIGCLD signal */
subrata_modak56207ce2009-03-23 13:35:39 +0000138 if (signal(SIGCLD, chld) == SIG_ERR) {
139 tst_brkm(TFAIL, cleanup,
140 "Error setting up SIGCLD signal, ERRNO = %d", errno);
Garrett Cooper2c282152010-12-16 00:55:50 -0800141
robbiewbd756502002-12-04 23:16:31 +0000142 }
143
144 /* Default argument settings. */
subrata_modakbdbaec52009-02-26 12:14:51 +0000145
robbiewbd756502002-12-04 23:16:31 +0000146 child_groups = 2;
subrata_modak56207ce2009-03-23 13:35:39 +0000147 test_time = 5; /* 0 = run forever or till signal */
robbiewbd756502002-12-04 23:16:31 +0000148 nfiles = 5;
149
150 /* Get command line options */
151
subrata_modak56207ce2009-03-23 13:35:39 +0000152 while ((c = getopt(argc, argv, goodopts)) != EOF) {
153 switch (c) {
154 case 'c':
155 child_groups = atoi(optarg);
156 break;
157 case 't':
158 test_time = atoi(optarg);
159 break;
160 case 'd':
161 nfiles = atoi(optarg);
162 break;
163 case '?':
164 errflg++;
165 break;
166 default:
167 break;
robbiewbd756502002-12-04 23:16:31 +0000168 }
169 }
subrata_modak56207ce2009-03-23 13:35:39 +0000170 if (errflg) {
171 tst_resm(TINFO,
172 "USAGE : mkdir09 -c #child_groups -t#test_time -d#directories");
vapiercff4af02006-02-11 04:46:30 +0000173 tst_resm(TINFO, "Bad argument count.");
Garrett Cooper2c282152010-12-16 00:55:50 -0800174
robbiewbd756502002-12-04 23:16:31 +0000175 }
176
robbiewbd756502002-12-04 23:16:31 +0000177 runtest();
178 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800179 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800180
robbiewbd756502002-12-04 23:16:31 +0000181}
subrata_modak56207ce2009-03-23 13:35:39 +0000182
robbiewbd756502002-12-04 23:16:31 +0000183/*--------------------------------------------------------------*/
184
185int runtest()
186{
187 int i, j;
subrata_modak56207ce2009-03-23 13:35:39 +0000188 int count, child, status;
robbiewbd756502002-12-04 23:16:31 +0000189 char tmpdir[MAXPATHLEN];
190
191 /* Create permanent directories with holes in directory structure */
192
subrata_modak56207ce2009-03-23 13:35:39 +0000193 for (j = 0; j < nfiles; j++) {
194 sprintf(tmpdir, DIR_NAME, j);
subrata_modak4bb656a2009-02-26 12:02:09 +0000195 TEST(mkdir(tmpdir, MODE_RWX));
robbiewbd756502002-12-04 23:16:31 +0000196
subrata_modak56207ce2009-03-23 13:35:39 +0000197 if (TEST_RETURN < 0) {
198 tst_brkm(TFAIL, cleanup,
199 "Error creating permanent directories, ERRNO = %d",
200 TEST_ERRNO);
201 tst_exit();
robbiewbd756502002-12-04 23:16:31 +0000202 }
subrata_modak56207ce2009-03-23 13:35:39 +0000203 if ((j % NCHILD) != 0) {
204 if (rmdir(tmpdir) < 0) {
205 tst_brkm(TFAIL, cleanup,
206 "Error removing directory, ERRNO = %d",
207 errno);
208 tst_exit();
robbiewbd756502002-12-04 23:16:31 +0000209 }
210 }
211 }
212
213 parent_pid = getpid();
214
215 /* allocate space for list of child pid's */
216
subrata_modak56207ce2009-03-23 13:35:39 +0000217 if ((pidlist =
218 (int *)malloc((child_groups * NCHILD) * sizeof(int))) ==
219 (int *)0) {
robbiewbd756502002-12-04 23:16:31 +0000220 tst_resm(TWARN, "\tMalloc failed (may be OK if under stress)");
subrata_modak56207ce2009-03-23 13:35:39 +0000221 tst_exit();
robbiewbd756502002-12-04 23:16:31 +0000222 }
223
224 child_count = 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000225 for (j = 0; j < child_groups; j++) {
226 for (i = 0; i < NCHILD; i++) {
227 getchild(j, i, child_count);
robbiewbd756502002-12-04 23:16:31 +0000228 child_count++;
229 }
230 }
231
subrata_modak56207ce2009-03-23 13:35:39 +0000232 /* If signal already received, skip to cleanup */
robbiewbd756502002-12-04 23:16:31 +0000233
subrata_modak56207ce2009-03-23 13:35:39 +0000234 if (!sigchld && !sigterm) {
235 if (test_time) {
robbiewbd756502002-12-04 23:16:31 +0000236 /* To get out of sleep if signal caught */
subrata_modak56207ce2009-03-23 13:35:39 +0000237 if (!setjmp(env_buf)) {
robbiewbd756502002-12-04 23:16:31 +0000238 jump++;
subrata_modak56207ce2009-03-23 13:35:39 +0000239 sleep(test_time);
robbiewbd756502002-12-04 23:16:31 +0000240 }
subrata_modak56207ce2009-03-23 13:35:39 +0000241 } else {
242 pause();
robbiewbd756502002-12-04 23:16:31 +0000243 }
subrata_modak56207ce2009-03-23 13:35:39 +0000244 }
robbiewbd756502002-12-04 23:16:31 +0000245
subrata_modak56207ce2009-03-23 13:35:39 +0000246 /* Reset signals since we are about to clean-up and to avoid
247 * problem with wait call * $
robbiewbd756502002-12-04 23:16:31 +0000248 * */
249
subrata_modak56207ce2009-03-23 13:35:39 +0000250 if (signal(SIGTERM, SIG_IGN) == SIG_ERR) {
251 tst_brkm(TFAIL, cleanup,
252 "Error resetting SIGTERM signal, ERRNO = %d", errno);
253 tst_exit();
254 }
255 if (signal(SIGCLD, SIG_DFL) == SIG_ERR) {
256 tst_brkm(TFAIL, cleanup,
257 "Error resetting SIGCLD signal, ERRNO = %d", errno);
258 tst_exit();
259 }
robbiewbd756502002-12-04 23:16:31 +0000260
subrata_modak56207ce2009-03-23 13:35:39 +0000261 if (test_time) {
262 sleep(test_time);
263 }
robbiewbd756502002-12-04 23:16:31 +0000264
265 /* Clean up children */
266 massmurder();
267 /*
268 * Watch children finish and show returns.
269 */
270
271 count = 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000272 while (1) {
273 if ((child = wait(&status)) > 0) {
274 if (status != 0) {
275 tst_resm(TWARN,
276 "\tChild{%d} exited status = %0x",
277 child, status);
278 tst_exit();
robbiewbd756502002-12-04 23:16:31 +0000279 }
280 count++;
subrata_modak56207ce2009-03-23 13:35:39 +0000281 } else {
282 if (errno != EINTR) {
robbiewbd756502002-12-04 23:16:31 +0000283 break;
284 }
vapiercff4af02006-02-11 04:46:30 +0000285 tst_resm(TINFO, "\tSignal detected during wait");
robbiewbd756502002-12-04 23:16:31 +0000286 }
287 }
288
289 /*
290 * Make sure correct number of children exited.
291 */
292
subrata_modak56207ce2009-03-23 13:35:39 +0000293 if (count != child_count) {
vapiercff4af02006-02-11 04:46:30 +0000294 tst_resm(TWARN, "\tWrong number of children waited on!");
295 tst_resm(TWARN, "\tSaw %d, expected %d", count, NCHILD);
robbiewbd756502002-12-04 23:16:31 +0000296 tst_exit();
297 }
298
299 /* Check for core file in test directory. */
300
subrata_modak56207ce2009-03-23 13:35:39 +0000301 if (access("core", 0) == 0) {
vapiercff4af02006-02-11 04:46:30 +0000302 tst_resm(TWARN, "\tCore file found in test directory.");
robbiewbd756502002-12-04 23:16:31 +0000303 tst_exit();
304 }
305
306 /* Remove expected files */
307
subrata_modak56207ce2009-03-23 13:35:39 +0000308 for (j = 0; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000309 sprintf(tmpdir, DIR_NAME, j);
subrata_modak56207ce2009-03-23 13:35:39 +0000310 if (rmdir(tmpdir) < 0) {
311 tst_resm(TWARN,
312 "\tError removing expected directory, ERRNO = %d",
313 errno);
robbiewbd756502002-12-04 23:16:31 +0000314 tst_exit();
315 }
316 }
317
subrata_modak56207ce2009-03-23 13:35:39 +0000318 tst_resm(TPASS, "PASS");
robbiewbd756502002-12-04 23:16:31 +0000319
subrata_modak43337a32009-02-26 11:43:51 +0000320 return 0;
robbiewbd756502002-12-04 23:16:31 +0000321}
322
323int getchild(group, child, children)
324int group, child, children;
325{
326 int pid;
327
robbiewd34d5812005-07-11 22:28:09 +0000328 pid = FORK_OR_VFORK();
robbiewbd756502002-12-04 23:16:31 +0000329
subrata_modak56207ce2009-03-23 13:35:39 +0000330 if (pid < 0) {
331
332 massmurder(); /* kill the kids */
333 tst_brkm(TBROK, cleanup,
334 "\tFork failed (may be OK if under stress)");
robbiewbd756502002-12-04 23:16:31 +0000335 tst_exit();
subrata_modak56207ce2009-03-23 13:35:39 +0000336 } else if (pid == 0) { /* child does this */
337 switch (children % NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000338 case 0:
robbiewd34d5812005-07-11 22:28:09 +0000339#ifdef UCLINUX
340 if (self_exec(argv0, "nd", 1, nfiles) < 0) {
341 massmurder();
342 tst_brkm(TBROK, cleanup, "\tself_exec failed");
343 tst_exit();
344 }
345#else
subrata_modak56207ce2009-03-23 13:35:39 +0000346 dochild1(); /* create existing directories */
robbiewd34d5812005-07-11 22:28:09 +0000347#endif
subrata_modak56207ce2009-03-23 13:35:39 +0000348 break; /* so lint won't complain */
robbiewbd756502002-12-04 23:16:31 +0000349 case 1:
robbiewd34d5812005-07-11 22:28:09 +0000350#ifdef UCLINUX
351 if (self_exec(argv0, "n", 2) < 0) {
352 massmurder();
353 tst_brkm(TBROK, cleanup, "\tself_exec failed");
354 tst_exit();
355 }
356#else
subrata_modak56207ce2009-03-23 13:35:39 +0000357 dochild2(); /* remove nonexistant directories */
robbiewd34d5812005-07-11 22:28:09 +0000358#endif
robbiewbd756502002-12-04 23:16:31 +0000359 break;
360 case 2:
robbiewd34d5812005-07-11 22:28:09 +0000361#ifdef UCLINUX
362 if (self_exec(argv0, "nd", 3, group) < 0) {
363 massmurder();
364 tst_brkm(TBROK, cleanup, "\tself_exec failed");
365 tst_exit();
366 }
367#else
subrata_modak56207ce2009-03-23 13:35:39 +0000368 dochild3(group); /* create/delete directories */
robbiewd34d5812005-07-11 22:28:09 +0000369#endif
robbiewbd756502002-12-04 23:16:31 +0000370 break;
371 default:
subrata_modak56207ce2009-03-23 13:35:39 +0000372 tst_brkm(TFAIL, cleanup,
373 "Test not inplemented for child %d", child);
robbiewbd756502002-12-04 23:16:31 +0000374 exit(1);
375 break;
376 }
subrata_modak56207ce2009-03-23 13:35:39 +0000377 exit(1); /* If child gets here, something wrong */
robbiewbd756502002-12-04 23:16:31 +0000378 }
379 pidlist[children] = pid;
subrata_modak43337a32009-02-26 11:43:51 +0000380 return 0;
robbiewbd756502002-12-04 23:16:31 +0000381}
382
383void term()
384{
385 /* Routine to handle SIGTERM signal. */
386
subrata_modak56207ce2009-03-23 13:35:39 +0000387 if (parent_pid == getpid()) {
vapiercff4af02006-02-11 04:46:30 +0000388 tst_resm(TWARN, "\tsignal SIGTERM received by parent.");
robbiewbd756502002-12-04 23:16:31 +0000389 tst_exit();
390 }
391 sigterm++;
subrata_modak56207ce2009-03-23 13:35:39 +0000392 if (jump) {
robbiewbd756502002-12-04 23:16:31 +0000393 longjmp(env_buf, 1);
394 }
395}
396
397void chld()
398{
399 /* Routine to handle SIGCLD signal. */
400
401 sigchld++;
subrata_modak56207ce2009-03-23 13:35:39 +0000402 if (jump) {
robbiewbd756502002-12-04 23:16:31 +0000403 longjmp(env_buf, 1);
404 }
405}
subrata_modakbdbaec52009-02-26 12:14:51 +0000406
robbiewbd756502002-12-04 23:16:31 +0000407int dochild1()
408{
409 /* Child routine which attempts to create directories in the test
410 * directory that already exist. Runs until a SIGTERM signal is
411 * received. Will exit with an error if it is able to create the
412 * directory or if the expected error is not received.
413 */
414
415 int j;
416 char tmpdir[MAXPATHLEN];
417
subrata_modak56207ce2009-03-23 13:35:39 +0000418 while (!sigterm) {
419 for (j = 0; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000420 sprintf(tmpdir, DIR_NAME, j);
subrata_modak4bb656a2009-02-26 12:02:09 +0000421 TEST(mkdir(tmpdir, MODE_RWX));
robbiewbd756502002-12-04 23:16:31 +0000422
subrata_modak56207ce2009-03-23 13:35:39 +0000423 if (TEST_RETURN < 0) {
robbiewbd756502002-12-04 23:16:31 +0000424
subrata_modak56207ce2009-03-23 13:35:39 +0000425 if (TEST_ERRNO != EEXIST) {
426 tst_brkm(TFAIL, cleanup,
427 "MKDIR %s, errno = %d; Wrong error detected.",
428 tmpdir, TEST_ERRNO);
robbiewbd756502002-12-04 23:16:31 +0000429 exit(1);
430 }
subrata_modak56207ce2009-03-23 13:35:39 +0000431 } else {
432 tst_brkm(TFAIL, cleanup,
433 "MKDIR %s succeded when it shoud have failed.",
434 tmpdir);
robbiewbd756502002-12-04 23:16:31 +0000435 exit(1);
436 }
437 }
438 }
439 exit(0);
440}
441
robbiewd34d5812005-07-11 22:28:09 +0000442#ifdef UCLINUX
443void dochild1_uclinux()
444{
445 /* Set up to catch SIGTERM signal */
subrata_modak56207ce2009-03-23 13:35:39 +0000446 if (signal(SIGTERM, term) == SIG_ERR) {
447 tst_brkm(TFAIL, cleanup,
448 "Error setting up SIGTERM signal, ERRNO = %d", errno);
449 tst_exit();
robbiewd34d5812005-07-11 22:28:09 +0000450 }
451
452 dochild1();
453}
454#endif
455
robbiewbd756502002-12-04 23:16:31 +0000456int dochild2()
457{
458 /* Child routine which attempts to remove directories from the
459 * test directory which do not exist. Runs until a SIGTERM
460 * signal is received. Exits with an error if the proper
461 * error is not detected or if the remove operation is
462 * successful.
463 */
464
465 int j;
466 char tmpdir[MAXPATHLEN];
467
subrata_modak56207ce2009-03-23 13:35:39 +0000468 while (!sigterm) {
469 for (j = 1; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000470 sprintf(tmpdir, DIR_NAME, j);
subrata_modak56207ce2009-03-23 13:35:39 +0000471 if (rmdir(tmpdir) < 0) {
472 if (errno != ENOENT) {
473 tst_brkm(TFAIL, cleanup,
474 "RMDIR %s, errno = %d; Wrong error detected.",
475 tmpdir, errno);
robbiewbd756502002-12-04 23:16:31 +0000476 exit(1);
subrata_modak4bb656a2009-02-26 12:02:09 +0000477 }
subrata_modak56207ce2009-03-23 13:35:39 +0000478 } else {
479 tst_brkm(TFAIL, cleanup,
480 "RMDIR %s succeded when it should have failed.",
481 tmpdir);
robbiewbd756502002-12-04 23:16:31 +0000482 exit(1);
483 }
484 }
485 }
486 exit(0);
subrata_modak43337a32009-02-26 11:43:51 +0000487 return 0;
robbiewbd756502002-12-04 23:16:31 +0000488}
489
robbiewd34d5812005-07-11 22:28:09 +0000490#ifdef UCLINUX
491void dochild2_uclinux()
492{
493 /* Set up to catch SIGTERM signal */
subrata_modak56207ce2009-03-23 13:35:39 +0000494 if (signal(SIGTERM, term) == SIG_ERR) {
495 tst_brkm(TFAIL, cleanup,
496 "Error setting up SIGTERM signal, ERRNO = %d", errno);
497 tst_exit();
robbiewd34d5812005-07-11 22:28:09 +0000498 }
499
500 dochild2();
501}
502#endif
503
robbiewbd756502002-12-04 23:16:31 +0000504int dochild3(group)
505int group;
506{
507 /* Child routine which creates and deletes directories in the
508 * test directory. Runs until a SIGTERM signal is received, then
509 * cleans up and exits. Detects error if the expected condition
510 * is not encountered.
511 */
512
513 int j;
subrata_modak56207ce2009-03-23 13:35:39 +0000514
robbiewbd756502002-12-04 23:16:31 +0000515 char tmpdir[MAXPATHLEN];
516 char tmp[MAXPATHLEN];
517
subrata_modak56207ce2009-03-23 13:35:39 +0000518 while (!sigterm) {
519 for (j = 2; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000520 strcpy(tmp, DIR_NAME);
521 strcat(tmp, ".%d");
522 sprintf(tmpdir, tmp, j, group);
523
subrata_modak4bb656a2009-02-26 12:02:09 +0000524 TEST(mkdir(tmpdir, MODE_RWX));
robbiewbd756502002-12-04 23:16:31 +0000525
subrata_modak56207ce2009-03-23 13:35:39 +0000526 if (TEST_RETURN < 0) {
527 tst_brkm(TFAIL, cleanup,
528 "MKDIR %s, errno = %d; Wrong error detected.",
529 tmpdir, TEST_ERRNO);
robbiewbd756502002-12-04 23:16:31 +0000530 exit(1);
531 }
532 }
subrata_modak56207ce2009-03-23 13:35:39 +0000533 for (j = 2; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000534 strcpy(tmp, DIR_NAME);
535 strcat(tmp, ".%d");
536 sprintf(tmpdir, tmp, j, group);
subrata_modak56207ce2009-03-23 13:35:39 +0000537 if (rmdir(tmpdir) < 0) {
538 tst_brkm(TFAIL, cleanup,
539 "RMDIR %s, errno = %d; Wrong error detected.",
540 tmpdir, errno);
robbiewbd756502002-12-04 23:16:31 +0000541 exit(1);
542 }
543 }
544 }
545 exit(0);
546}
robbiewd34d5812005-07-11 22:28:09 +0000547
548#ifdef UCLINUX
549void dochild3_uclinux()
550{
551 /* Set up to catch SIGTERM signal */
subrata_modak56207ce2009-03-23 13:35:39 +0000552 if (signal(SIGTERM, term) == SIG_ERR) {
553 tst_brkm(TFAIL, cleanup,
554 "Error setting up SIGTERM signal, ERRNO = %d", errno);
555 tst_exit();
robbiewd34d5812005-07-11 22:28:09 +0000556 }
557
558 dochild3(group_uclinux);
559}
560#endif
561
robbiewbd756502002-12-04 23:16:31 +0000562int massmurder()
563{
subrata_modak56207ce2009-03-23 13:35:39 +0000564 register int j;
565 for (j = 0; j < child_count; j++) {
566 if (pidlist[j] > 0) {
567 if (kill(pidlist[j], SIGTERM) < 0) {
568 tst_brkm(TFAIL, cleanup,
569 "Error killing child %d, ERRNO = %d",
570 j, errno);
robbiewbd756502002-12-04 23:16:31 +0000571 tst_exit();
572 }
573 }
574 }
subrata_modak56207ce2009-03-23 13:35:39 +0000575 return 0;
robbiewbd756502002-12-04 23:16:31 +0000576}
577
robbiewbd756502002-12-04 23:16:31 +0000578/***************************************************************
579 * * setup() - performs all ONE TIME setup for this test.
580 * ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000581void setup()
robbiewbd756502002-12-04 23:16:31 +0000582{
Garrett Cooper2c282152010-12-16 00:55:50 -0800583
subrata_modak56207ce2009-03-23 13:35:39 +0000584 tst_sig(NOFORK, DEF_HANDLER, cleanup);
robbiewbd756502002-12-04 23:16:31 +0000585
subrata_modak56207ce2009-03-23 13:35:39 +0000586 TEST_PAUSE;
robbiewbd756502002-12-04 23:16:31 +0000587
subrata_modak56207ce2009-03-23 13:35:39 +0000588 /* Create a temporary directory and make it current. */
589 tst_tmpdir();
robbiewbd756502002-12-04 23:16:31 +0000590
Garrett Cooper2c282152010-12-16 00:55:50 -0800591}
robbiewbd756502002-12-04 23:16:31 +0000592
593/***************************************************************
594 * * cleanup() - performs all ONE TIME cleanup for this test at
595 * * completion or premature exit.
596 * ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000597void cleanup()
robbiewbd756502002-12-04 23:16:31 +0000598{
subrata_modak56207ce2009-03-23 13:35:39 +0000599 /*
600 * * print timing stats if that option was specified.
601 * * print errno log if that option was specified.
602 * */
603 TEST_CLEANUP;
robbiewbd756502002-12-04 23:16:31 +0000604
subrata_modak56207ce2009-03-23 13:35:39 +0000605 /*
606 * * Remove the temporary directory.
607 * */
608 tst_rmdir();
robbiewbd756502002-12-04 23:16:31 +0000609
subrata_modak56207ce2009-03-23 13:35:39 +0000610 /*
611 * * Exit with return code appropriate for results.
612 * */
robbiewbd756502002-12-04 23:16:31 +0000613
Garrett Cooperbacc8492011-01-14 00:36:17 -0800614}