blob: de1cb6971651c5162d69b96bdd8f5c430632ec8a [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 */
Steven Jackson249f4052016-12-13 16:16:00 +000045#include <sys/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"
robbiewbd756502002-12-04 23:16:31 +000055
robbiewbd756502002-12-04 23:16:31 +000056#include <stdlib.h>
Garrett Cooperbacc8492011-01-14 00:36:17 -080057#include <stdlib.h>
robbiewbd756502002-12-04 23:16:31 +000058#include <string.h>
59
subrata_modakbdbaec52009-02-26 12:14:51 +000060#define NCHILD 3
robbiewbd756502002-12-04 23:16:31 +000061
62#define MODE_RWX 07770
63#define DIR_NAME "./X.%d"
64
65/* used by getopt */
66extern char *optarg;
67extern int optind, opterr;
68char *goodopts = "c:t:d:";
69int errflg;
70
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020071char *TCID = "mkdir09";
72int TST_TOTAL = 1;
robbiewbd756502002-12-04 23:16:31 +000073
robbiewbd756502002-12-04 23:16:31 +000074int child_groups, test_time, nfiles;
75char testdir[MAXPATHLEN];
76int parent_pid, sigchld, sigterm, jump;
Mike Frysingere61ddba2014-04-09 23:24:32 -040077void term(int sig);
78void chld(int sig);
subrata_modak56207ce2009-03-23 13:35:39 +000079int *pidlist, child_count;
robbiewbd756502002-12-04 23:16:31 +000080jmp_buf env_buf;
81
subrata_modak56207ce2009-03-23 13:35:39 +000082int getchild(int group, int child, int children);
Mike Frysingerc57fba52014-04-09 18:56:30 -040083int dochild1(void);
84int dochild2(void);
robbiewbd756502002-12-04 23:16:31 +000085int dochild3(int group);
Mike Frysingerc57fba52014-04-09 18:56:30 -040086int massmurder(void);
87int runtest(void);
88void setup(void);
89void cleanup(void);
robbiewbd756502002-12-04 23:16:31 +000090
robbiewd34d5812005-07-11 22:28:09 +000091#ifdef UCLINUX
92static char *argv0;
Mike Frysingerc57fba52014-04-09 18:56:30 -040093void dochild1_uclinux(void);
94void dochild2_uclinux(void);
95void dochild3_uclinux(void);
robbiewd34d5812005-07-11 22:28:09 +000096static int group_uclinux;
97#endif
98
robbiewbd756502002-12-04 23:16:31 +000099/*--------------------------------------------------------------*/
100/*--------------------------------------------------------------*/
101/*--------------------------------------------------------------*/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400102int main(int argc, char *argv[])
robbiewbd756502002-12-04 23:16:31 +0000103{
robbiewe0cf2e22002-12-11 20:29:15 +0000104 int c;
robbiewbd756502002-12-04 23:16:31 +0000105
robbiewd34d5812005-07-11 22:28:09 +0000106#ifdef UCLINUX
robbiewd34d5812005-07-11 22:28:09 +0000107
Cyril Hrubisd6d11d02015-03-09 17:35:43 +0100108 tst_parse_opts(argc, argv, NULL, NULL);
robbiewd34d5812005-07-11 22:28:09 +0000109
110 argv0 = argv[0];
111 maybe_run_child(&dochild1_uclinux, "nd", 1, &nfiles);
112 maybe_run_child(&dochild2_uclinux, "n", 2);
113 maybe_run_child(&dochild3_uclinux, "nd", 3, &group_uclinux);
114#endif
115
robbiewbd756502002-12-04 23:16:31 +0000116 setup();
117
118 /* Set up to catch SIGTERM signal */
subrata_modak56207ce2009-03-23 13:35:39 +0000119 if (signal(SIGTERM, term) == SIG_ERR) {
120 tst_brkm(TFAIL, cleanup,
121 "Error setting up SIGTERM signal, ERRNO = %d", errno);
Garrett Cooper2c282152010-12-16 00:55:50 -0800122
robbiewbd756502002-12-04 23:16:31 +0000123 }
124
Khem Rajad33a3d2016-07-21 21:26:51 -0700125 /* Set up to catch SIGCHLD signal */
126 if (signal(SIGCHLD, chld) == SIG_ERR) {
subrata_modak56207ce2009-03-23 13:35:39 +0000127 tst_brkm(TFAIL, cleanup,
Khem Rajad33a3d2016-07-21 21:26:51 -0700128 "Error setting up SIGCHLD signal, ERRNO = %d", errno);
Garrett Cooper2c282152010-12-16 00:55:50 -0800129
robbiewbd756502002-12-04 23:16:31 +0000130 }
131
132 /* Default argument settings. */
subrata_modakbdbaec52009-02-26 12:14:51 +0000133
robbiewbd756502002-12-04 23:16:31 +0000134 child_groups = 2;
subrata_modak56207ce2009-03-23 13:35:39 +0000135 test_time = 5; /* 0 = run forever or till signal */
robbiewbd756502002-12-04 23:16:31 +0000136 nfiles = 5;
137
138 /* Get command line options */
139
subrata_modak56207ce2009-03-23 13:35:39 +0000140 while ((c = getopt(argc, argv, goodopts)) != EOF) {
141 switch (c) {
142 case 'c':
143 child_groups = atoi(optarg);
144 break;
145 case 't':
146 test_time = atoi(optarg);
147 break;
148 case 'd':
149 nfiles = atoi(optarg);
150 break;
151 case '?':
152 errflg++;
153 break;
154 default:
155 break;
robbiewbd756502002-12-04 23:16:31 +0000156 }
157 }
subrata_modak56207ce2009-03-23 13:35:39 +0000158 if (errflg) {
159 tst_resm(TINFO,
160 "USAGE : mkdir09 -c #child_groups -t#test_time -d#directories");
vapiercff4af02006-02-11 04:46:30 +0000161 tst_resm(TINFO, "Bad argument count.");
Garrett Cooper2c282152010-12-16 00:55:50 -0800162
robbiewbd756502002-12-04 23:16:31 +0000163 }
164
robbiewbd756502002-12-04 23:16:31 +0000165 runtest();
166 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800167 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800168
robbiewbd756502002-12-04 23:16:31 +0000169}
subrata_modak56207ce2009-03-23 13:35:39 +0000170
robbiewbd756502002-12-04 23:16:31 +0000171/*--------------------------------------------------------------*/
172
Mike Frysingerc57fba52014-04-09 18:56:30 -0400173int runtest(void)
robbiewbd756502002-12-04 23:16:31 +0000174{
175 int i, j;
subrata_modak56207ce2009-03-23 13:35:39 +0000176 int count, child, status;
robbiewbd756502002-12-04 23:16:31 +0000177 char tmpdir[MAXPATHLEN];
178
179 /* Create permanent directories with holes in directory structure */
180
subrata_modak56207ce2009-03-23 13:35:39 +0000181 for (j = 0; j < nfiles; j++) {
182 sprintf(tmpdir, DIR_NAME, j);
subrata_modak4bb656a2009-02-26 12:02:09 +0000183 TEST(mkdir(tmpdir, MODE_RWX));
robbiewbd756502002-12-04 23:16:31 +0000184
subrata_modak56207ce2009-03-23 13:35:39 +0000185 if (TEST_RETURN < 0) {
186 tst_brkm(TFAIL, cleanup,
187 "Error creating permanent directories, ERRNO = %d",
188 TEST_ERRNO);
robbiewbd756502002-12-04 23:16:31 +0000189 }
subrata_modak56207ce2009-03-23 13:35:39 +0000190 if ((j % NCHILD) != 0) {
191 if (rmdir(tmpdir) < 0) {
192 tst_brkm(TFAIL, cleanup,
193 "Error removing directory, ERRNO = %d",
194 errno);
robbiewbd756502002-12-04 23:16:31 +0000195 }
196 }
197 }
198
199 parent_pid = getpid();
200
201 /* allocate space for list of child pid's */
202
Cyril Hrubisd218f342014-09-23 13:14:56 +0200203 if ((pidlist = malloc((child_groups * NCHILD) * sizeof(int))) ==
Cyril Hrubis4e2bab82014-09-24 16:34:35 +0200204 NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100205 tst_brkm(TWARN, NULL,
206 "\tMalloc failed (may be OK if under stress)");
robbiewbd756502002-12-04 23:16:31 +0000207 }
208
209 child_count = 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000210 for (j = 0; j < child_groups; j++) {
211 for (i = 0; i < NCHILD; i++) {
212 getchild(j, i, child_count);
robbiewbd756502002-12-04 23:16:31 +0000213 child_count++;
214 }
215 }
216
subrata_modak56207ce2009-03-23 13:35:39 +0000217 /* If signal already received, skip to cleanup */
robbiewbd756502002-12-04 23:16:31 +0000218
subrata_modak56207ce2009-03-23 13:35:39 +0000219 if (!sigchld && !sigterm) {
220 if (test_time) {
robbiewbd756502002-12-04 23:16:31 +0000221 /* To get out of sleep if signal caught */
subrata_modak56207ce2009-03-23 13:35:39 +0000222 if (!setjmp(env_buf)) {
robbiewbd756502002-12-04 23:16:31 +0000223 jump++;
subrata_modak56207ce2009-03-23 13:35:39 +0000224 sleep(test_time);
robbiewbd756502002-12-04 23:16:31 +0000225 }
subrata_modak56207ce2009-03-23 13:35:39 +0000226 } else {
227 pause();
robbiewbd756502002-12-04 23:16:31 +0000228 }
subrata_modak56207ce2009-03-23 13:35:39 +0000229 }
robbiewbd756502002-12-04 23:16:31 +0000230
subrata_modak56207ce2009-03-23 13:35:39 +0000231 /* Reset signals since we are about to clean-up and to avoid
232 * problem with wait call * $
robbiewbd756502002-12-04 23:16:31 +0000233 * */
234
subrata_modak56207ce2009-03-23 13:35:39 +0000235 if (signal(SIGTERM, SIG_IGN) == SIG_ERR) {
236 tst_brkm(TFAIL, cleanup,
237 "Error resetting SIGTERM signal, ERRNO = %d", errno);
subrata_modak56207ce2009-03-23 13:35:39 +0000238 }
Khem Rajad33a3d2016-07-21 21:26:51 -0700239 if (signal(SIGCHLD, SIG_DFL) == SIG_ERR) {
subrata_modak56207ce2009-03-23 13:35:39 +0000240 tst_brkm(TFAIL, cleanup,
Khem Rajad33a3d2016-07-21 21:26:51 -0700241 "Error resetting SIGCHLD signal, ERRNO = %d", errno);
subrata_modak56207ce2009-03-23 13:35:39 +0000242 }
robbiewbd756502002-12-04 23:16:31 +0000243
subrata_modak56207ce2009-03-23 13:35:39 +0000244 if (test_time) {
245 sleep(test_time);
246 }
robbiewbd756502002-12-04 23:16:31 +0000247
248 /* Clean up children */
249 massmurder();
250 /*
251 * Watch children finish and show returns.
252 */
253
254 count = 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000255 while (1) {
256 if ((child = wait(&status)) > 0) {
257 if (status != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100258 tst_brkm(TWARN,
259 NULL,
subrata_modak56207ce2009-03-23 13:35:39 +0000260 "\tChild{%d} exited status = %0x",
261 child, status);
robbiewbd756502002-12-04 23:16:31 +0000262 }
263 count++;
subrata_modak56207ce2009-03-23 13:35:39 +0000264 } else {
265 if (errno != EINTR) {
robbiewbd756502002-12-04 23:16:31 +0000266 break;
267 }
vapiercff4af02006-02-11 04:46:30 +0000268 tst_resm(TINFO, "\tSignal detected during wait");
robbiewbd756502002-12-04 23:16:31 +0000269 }
270 }
271
272 /*
273 * Make sure correct number of children exited.
274 */
275
subrata_modak56207ce2009-03-23 13:35:39 +0000276 if (count != child_count) {
vapiercff4af02006-02-11 04:46:30 +0000277 tst_resm(TWARN, "\tWrong number of children waited on!");
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100278 tst_brkm(TWARN, NULL, "\tSaw %d, expected %d", count,
279 NCHILD);
robbiewbd756502002-12-04 23:16:31 +0000280 }
281
282 /* Check for core file in test directory. */
283
subrata_modak56207ce2009-03-23 13:35:39 +0000284 if (access("core", 0) == 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100285 tst_brkm(TWARN, NULL, "\tCore file found in test directory.");
robbiewbd756502002-12-04 23:16:31 +0000286 }
287
288 /* Remove expected files */
289
subrata_modak56207ce2009-03-23 13:35:39 +0000290 for (j = 0; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000291 sprintf(tmpdir, DIR_NAME, j);
subrata_modak56207ce2009-03-23 13:35:39 +0000292 if (rmdir(tmpdir) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100293 tst_brkm(TWARN,
294 NULL,
subrata_modak56207ce2009-03-23 13:35:39 +0000295 "\tError removing expected directory, ERRNO = %d",
296 errno);
robbiewbd756502002-12-04 23:16:31 +0000297 }
298 }
299
subrata_modak56207ce2009-03-23 13:35:39 +0000300 tst_resm(TPASS, "PASS");
robbiewbd756502002-12-04 23:16:31 +0000301
subrata_modak43337a32009-02-26 11:43:51 +0000302 return 0;
robbiewbd756502002-12-04 23:16:31 +0000303}
304
Mike Frysingerc57fba52014-04-09 18:56:30 -0400305int getchild(int group, int child, int children)
robbiewbd756502002-12-04 23:16:31 +0000306{
307 int pid;
308
robbiewd34d5812005-07-11 22:28:09 +0000309 pid = FORK_OR_VFORK();
robbiewbd756502002-12-04 23:16:31 +0000310
subrata_modak56207ce2009-03-23 13:35:39 +0000311 if (pid < 0) {
312
313 massmurder(); /* kill the kids */
314 tst_brkm(TBROK, cleanup,
315 "\tFork failed (may be OK if under stress)");
subrata_modak56207ce2009-03-23 13:35:39 +0000316 } else if (pid == 0) { /* child does this */
317 switch (children % NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000318 case 0:
robbiewd34d5812005-07-11 22:28:09 +0000319#ifdef UCLINUX
320 if (self_exec(argv0, "nd", 1, nfiles) < 0) {
321 massmurder();
322 tst_brkm(TBROK, cleanup, "\tself_exec failed");
robbiewd34d5812005-07-11 22:28:09 +0000323 }
324#else
subrata_modak56207ce2009-03-23 13:35:39 +0000325 dochild1(); /* create existing directories */
robbiewd34d5812005-07-11 22:28:09 +0000326#endif
subrata_modak56207ce2009-03-23 13:35:39 +0000327 break; /* so lint won't complain */
robbiewbd756502002-12-04 23:16:31 +0000328 case 1:
robbiewd34d5812005-07-11 22:28:09 +0000329#ifdef UCLINUX
330 if (self_exec(argv0, "n", 2) < 0) {
331 massmurder();
332 tst_brkm(TBROK, cleanup, "\tself_exec failed");
robbiewd34d5812005-07-11 22:28:09 +0000333 }
334#else
subrata_modak56207ce2009-03-23 13:35:39 +0000335 dochild2(); /* remove nonexistant directories */
robbiewd34d5812005-07-11 22:28:09 +0000336#endif
robbiewbd756502002-12-04 23:16:31 +0000337 break;
338 case 2:
robbiewd34d5812005-07-11 22:28:09 +0000339#ifdef UCLINUX
340 if (self_exec(argv0, "nd", 3, group) < 0) {
341 massmurder();
342 tst_brkm(TBROK, cleanup, "\tself_exec failed");
robbiewd34d5812005-07-11 22:28:09 +0000343 }
344#else
subrata_modak56207ce2009-03-23 13:35:39 +0000345 dochild3(group); /* create/delete directories */
robbiewd34d5812005-07-11 22:28:09 +0000346#endif
robbiewbd756502002-12-04 23:16:31 +0000347 break;
348 default:
subrata_modak56207ce2009-03-23 13:35:39 +0000349 tst_brkm(TFAIL, cleanup,
350 "Test not inplemented for child %d", child);
robbiewbd756502002-12-04 23:16:31 +0000351 exit(1);
352 break;
353 }
subrata_modak56207ce2009-03-23 13:35:39 +0000354 exit(1); /* If child gets here, something wrong */
robbiewbd756502002-12-04 23:16:31 +0000355 }
356 pidlist[children] = pid;
subrata_modak43337a32009-02-26 11:43:51 +0000357 return 0;
robbiewbd756502002-12-04 23:16:31 +0000358}
359
Mike Frysingere61ddba2014-04-09 23:24:32 -0400360void term(int sig)
robbiewbd756502002-12-04 23:16:31 +0000361{
362 /* Routine to handle SIGTERM signal. */
363
subrata_modak56207ce2009-03-23 13:35:39 +0000364 if (parent_pid == getpid()) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100365 tst_brkm(TWARN, NULL, "\tsignal SIGTERM received by parent.");
robbiewbd756502002-12-04 23:16:31 +0000366 }
367 sigterm++;
subrata_modak56207ce2009-03-23 13:35:39 +0000368 if (jump) {
robbiewbd756502002-12-04 23:16:31 +0000369 longjmp(env_buf, 1);
370 }
371}
372
Mike Frysingere61ddba2014-04-09 23:24:32 -0400373void chld(int sig)
robbiewbd756502002-12-04 23:16:31 +0000374{
Khem Rajad33a3d2016-07-21 21:26:51 -0700375 /* Routine to handle SIGCHLD signal. */
robbiewbd756502002-12-04 23:16:31 +0000376
377 sigchld++;
subrata_modak56207ce2009-03-23 13:35:39 +0000378 if (jump) {
robbiewbd756502002-12-04 23:16:31 +0000379 longjmp(env_buf, 1);
380 }
381}
subrata_modakbdbaec52009-02-26 12:14:51 +0000382
Mike Frysingerc57fba52014-04-09 18:56:30 -0400383int dochild1(void)
robbiewbd756502002-12-04 23:16:31 +0000384{
385 /* Child routine which attempts to create directories in the test
386 * directory that already exist. Runs until a SIGTERM signal is
387 * received. Will exit with an error if it is able to create the
388 * directory or if the expected error is not received.
389 */
390
391 int j;
392 char tmpdir[MAXPATHLEN];
393
subrata_modak56207ce2009-03-23 13:35:39 +0000394 while (!sigterm) {
395 for (j = 0; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000396 sprintf(tmpdir, DIR_NAME, j);
subrata_modak4bb656a2009-02-26 12:02:09 +0000397 TEST(mkdir(tmpdir, MODE_RWX));
robbiewbd756502002-12-04 23:16:31 +0000398
subrata_modak56207ce2009-03-23 13:35:39 +0000399 if (TEST_RETURN < 0) {
robbiewbd756502002-12-04 23:16:31 +0000400
subrata_modak56207ce2009-03-23 13:35:39 +0000401 if (TEST_ERRNO != EEXIST) {
402 tst_brkm(TFAIL, cleanup,
403 "MKDIR %s, errno = %d; Wrong error detected.",
404 tmpdir, TEST_ERRNO);
robbiewbd756502002-12-04 23:16:31 +0000405 exit(1);
406 }
subrata_modak56207ce2009-03-23 13:35:39 +0000407 } else {
408 tst_brkm(TFAIL, cleanup,
409 "MKDIR %s succeded when it shoud have failed.",
410 tmpdir);
robbiewbd756502002-12-04 23:16:31 +0000411 exit(1);
412 }
413 }
414 }
415 exit(0);
416}
417
robbiewd34d5812005-07-11 22:28:09 +0000418#ifdef UCLINUX
Mike Frysingerc57fba52014-04-09 18:56:30 -0400419void dochild1_uclinux(void)
robbiewd34d5812005-07-11 22:28:09 +0000420{
421 /* Set up to catch SIGTERM signal */
subrata_modak56207ce2009-03-23 13:35:39 +0000422 if (signal(SIGTERM, term) == SIG_ERR) {
423 tst_brkm(TFAIL, cleanup,
424 "Error setting up SIGTERM signal, ERRNO = %d", errno);
robbiewd34d5812005-07-11 22:28:09 +0000425 }
426
427 dochild1();
428}
429#endif
430
Mike Frysingerc57fba52014-04-09 18:56:30 -0400431int dochild2(void)
robbiewbd756502002-12-04 23:16:31 +0000432{
433 /* Child routine which attempts to remove directories from the
434 * test directory which do not exist. Runs until a SIGTERM
435 * signal is received. Exits with an error if the proper
436 * error is not detected or if the remove operation is
437 * successful.
438 */
439
440 int j;
441 char tmpdir[MAXPATHLEN];
442
subrata_modak56207ce2009-03-23 13:35:39 +0000443 while (!sigterm) {
444 for (j = 1; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000445 sprintf(tmpdir, DIR_NAME, j);
subrata_modak56207ce2009-03-23 13:35:39 +0000446 if (rmdir(tmpdir) < 0) {
447 if (errno != ENOENT) {
448 tst_brkm(TFAIL, cleanup,
449 "RMDIR %s, errno = %d; Wrong error detected.",
450 tmpdir, errno);
robbiewbd756502002-12-04 23:16:31 +0000451 exit(1);
subrata_modak4bb656a2009-02-26 12:02:09 +0000452 }
subrata_modak56207ce2009-03-23 13:35:39 +0000453 } else {
454 tst_brkm(TFAIL, cleanup,
455 "RMDIR %s succeded when it should have failed.",
456 tmpdir);
robbiewbd756502002-12-04 23:16:31 +0000457 exit(1);
458 }
459 }
460 }
461 exit(0);
subrata_modak43337a32009-02-26 11:43:51 +0000462 return 0;
robbiewbd756502002-12-04 23:16:31 +0000463}
464
robbiewd34d5812005-07-11 22:28:09 +0000465#ifdef UCLINUX
Mike Frysingerc57fba52014-04-09 18:56:30 -0400466void dochild2_uclinux(void)
robbiewd34d5812005-07-11 22:28:09 +0000467{
468 /* Set up to catch SIGTERM signal */
subrata_modak56207ce2009-03-23 13:35:39 +0000469 if (signal(SIGTERM, term) == SIG_ERR) {
470 tst_brkm(TFAIL, cleanup,
471 "Error setting up SIGTERM signal, ERRNO = %d", errno);
robbiewd34d5812005-07-11 22:28:09 +0000472 }
473
474 dochild2();
475}
476#endif
477
Mike Frysingerc57fba52014-04-09 18:56:30 -0400478int dochild3(int group)
robbiewbd756502002-12-04 23:16:31 +0000479{
480 /* Child routine which creates and deletes directories in the
481 * test directory. Runs until a SIGTERM signal is received, then
482 * cleans up and exits. Detects error if the expected condition
483 * is not encountered.
484 */
485
486 int j;
subrata_modak56207ce2009-03-23 13:35:39 +0000487
robbiewbd756502002-12-04 23:16:31 +0000488 char tmpdir[MAXPATHLEN];
489 char tmp[MAXPATHLEN];
490
subrata_modak56207ce2009-03-23 13:35:39 +0000491 while (!sigterm) {
492 for (j = 2; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000493 strcpy(tmp, DIR_NAME);
494 strcat(tmp, ".%d");
495 sprintf(tmpdir, tmp, j, group);
496
subrata_modak4bb656a2009-02-26 12:02:09 +0000497 TEST(mkdir(tmpdir, MODE_RWX));
robbiewbd756502002-12-04 23:16:31 +0000498
subrata_modak56207ce2009-03-23 13:35:39 +0000499 if (TEST_RETURN < 0) {
500 tst_brkm(TFAIL, cleanup,
501 "MKDIR %s, errno = %d; Wrong error detected.",
502 tmpdir, TEST_ERRNO);
robbiewbd756502002-12-04 23:16:31 +0000503 exit(1);
504 }
505 }
subrata_modak56207ce2009-03-23 13:35:39 +0000506 for (j = 2; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000507 strcpy(tmp, DIR_NAME);
508 strcat(tmp, ".%d");
509 sprintf(tmpdir, tmp, j, group);
subrata_modak56207ce2009-03-23 13:35:39 +0000510 if (rmdir(tmpdir) < 0) {
511 tst_brkm(TFAIL, cleanup,
512 "RMDIR %s, errno = %d; Wrong error detected.",
513 tmpdir, errno);
robbiewbd756502002-12-04 23:16:31 +0000514 exit(1);
515 }
516 }
517 }
518 exit(0);
519}
robbiewd34d5812005-07-11 22:28:09 +0000520
521#ifdef UCLINUX
Mike Frysingerc57fba52014-04-09 18:56:30 -0400522void dochild3_uclinux(void)
robbiewd34d5812005-07-11 22:28:09 +0000523{
524 /* Set up to catch SIGTERM signal */
subrata_modak56207ce2009-03-23 13:35:39 +0000525 if (signal(SIGTERM, term) == SIG_ERR) {
526 tst_brkm(TFAIL, cleanup,
527 "Error setting up SIGTERM signal, ERRNO = %d", errno);
robbiewd34d5812005-07-11 22:28:09 +0000528 }
529
530 dochild3(group_uclinux);
531}
532#endif
533
Mike Frysingerc57fba52014-04-09 18:56:30 -0400534int massmurder(void)
robbiewbd756502002-12-04 23:16:31 +0000535{
subrata_modak56207ce2009-03-23 13:35:39 +0000536 register int j;
537 for (j = 0; j < child_count; j++) {
538 if (pidlist[j] > 0) {
539 if (kill(pidlist[j], SIGTERM) < 0) {
540 tst_brkm(TFAIL, cleanup,
541 "Error killing child %d, ERRNO = %d",
542 j, errno);
robbiewbd756502002-12-04 23:16:31 +0000543 }
544 }
545 }
subrata_modak56207ce2009-03-23 13:35:39 +0000546 return 0;
robbiewbd756502002-12-04 23:16:31 +0000547}
548
robbiewbd756502002-12-04 23:16:31 +0000549/***************************************************************
550 * * setup() - performs all ONE TIME setup for this test.
551 * ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400552void setup(void)
robbiewbd756502002-12-04 23:16:31 +0000553{
Garrett Cooper2c282152010-12-16 00:55:50 -0800554
subrata_modak56207ce2009-03-23 13:35:39 +0000555 tst_sig(NOFORK, DEF_HANDLER, cleanup);
robbiewbd756502002-12-04 23:16:31 +0000556
subrata_modak56207ce2009-03-23 13:35:39 +0000557 TEST_PAUSE;
robbiewbd756502002-12-04 23:16:31 +0000558
subrata_modak56207ce2009-03-23 13:35:39 +0000559 /* Create a temporary directory and make it current. */
560 tst_tmpdir();
robbiewbd756502002-12-04 23:16:31 +0000561
Garrett Cooper2c282152010-12-16 00:55:50 -0800562}
robbiewbd756502002-12-04 23:16:31 +0000563
564/***************************************************************
565 * * cleanup() - performs all ONE TIME cleanup for this test at
566 * * completion or premature exit.
567 * ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400568void cleanup(void)
robbiewbd756502002-12-04 23:16:31 +0000569{
robbiewbd756502002-12-04 23:16:31 +0000570
subrata_modak56207ce2009-03-23 13:35:39 +0000571 /*
572 * * Remove the temporary directory.
573 * */
574 tst_rmdir();
robbiewbd756502002-12-04 23:16:31 +0000575
subrata_modak56207ce2009-03-23 13:35:39 +0000576 /*
577 * * Exit with return code appropriate for results.
578 * */
robbiewbd756502002-12-04 23:16:31 +0000579
Garrett Cooperbacc8492011-01-14 00:36:17 -0800580}