blob: 1cd5fb2af2ee1e0da30c80ef2cd8e5f4952aa44c [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"
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
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200107 const char *msg;
robbiewd34d5812005-07-11 22:28:09 +0000108
Wanlong Gao354ebb42012-12-07 10:10:04 +0800109 if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) {
robbiewd34d5812005-07-11 22:28:09 +0000110 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
111 }
112
113 argv0 = argv[0];
114 maybe_run_child(&dochild1_uclinux, "nd", 1, &nfiles);
115 maybe_run_child(&dochild2_uclinux, "n", 2);
116 maybe_run_child(&dochild3_uclinux, "nd", 3, &group_uclinux);
117#endif
118
robbiewbd756502002-12-04 23:16:31 +0000119 setup();
120
121 /* Set up to catch SIGTERM signal */
subrata_modak56207ce2009-03-23 13:35:39 +0000122 if (signal(SIGTERM, term) == SIG_ERR) {
123 tst_brkm(TFAIL, cleanup,
124 "Error setting up SIGTERM signal, ERRNO = %d", errno);
Garrett Cooper2c282152010-12-16 00:55:50 -0800125
robbiewbd756502002-12-04 23:16:31 +0000126 }
127
128 /* Set up to catch SIGCLD signal */
subrata_modak56207ce2009-03-23 13:35:39 +0000129 if (signal(SIGCLD, chld) == SIG_ERR) {
130 tst_brkm(TFAIL, cleanup,
131 "Error setting up SIGCLD signal, ERRNO = %d", errno);
Garrett Cooper2c282152010-12-16 00:55:50 -0800132
robbiewbd756502002-12-04 23:16:31 +0000133 }
134
135 /* Default argument settings. */
subrata_modakbdbaec52009-02-26 12:14:51 +0000136
robbiewbd756502002-12-04 23:16:31 +0000137 child_groups = 2;
subrata_modak56207ce2009-03-23 13:35:39 +0000138 test_time = 5; /* 0 = run forever or till signal */
robbiewbd756502002-12-04 23:16:31 +0000139 nfiles = 5;
140
141 /* Get command line options */
142
subrata_modak56207ce2009-03-23 13:35:39 +0000143 while ((c = getopt(argc, argv, goodopts)) != EOF) {
144 switch (c) {
145 case 'c':
146 child_groups = atoi(optarg);
147 break;
148 case 't':
149 test_time = atoi(optarg);
150 break;
151 case 'd':
152 nfiles = atoi(optarg);
153 break;
154 case '?':
155 errflg++;
156 break;
157 default:
158 break;
robbiewbd756502002-12-04 23:16:31 +0000159 }
160 }
subrata_modak56207ce2009-03-23 13:35:39 +0000161 if (errflg) {
162 tst_resm(TINFO,
163 "USAGE : mkdir09 -c #child_groups -t#test_time -d#directories");
vapiercff4af02006-02-11 04:46:30 +0000164 tst_resm(TINFO, "Bad argument count.");
Garrett Cooper2c282152010-12-16 00:55:50 -0800165
robbiewbd756502002-12-04 23:16:31 +0000166 }
167
robbiewbd756502002-12-04 23:16:31 +0000168 runtest();
169 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800170 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800171
robbiewbd756502002-12-04 23:16:31 +0000172}
subrata_modak56207ce2009-03-23 13:35:39 +0000173
robbiewbd756502002-12-04 23:16:31 +0000174/*--------------------------------------------------------------*/
175
Mike Frysingerc57fba52014-04-09 18:56:30 -0400176int runtest(void)
robbiewbd756502002-12-04 23:16:31 +0000177{
178 int i, j;
subrata_modak56207ce2009-03-23 13:35:39 +0000179 int count, child, status;
robbiewbd756502002-12-04 23:16:31 +0000180 char tmpdir[MAXPATHLEN];
181
182 /* Create permanent directories with holes in directory structure */
183
subrata_modak56207ce2009-03-23 13:35:39 +0000184 for (j = 0; j < nfiles; j++) {
185 sprintf(tmpdir, DIR_NAME, j);
subrata_modak4bb656a2009-02-26 12:02:09 +0000186 TEST(mkdir(tmpdir, MODE_RWX));
robbiewbd756502002-12-04 23:16:31 +0000187
subrata_modak56207ce2009-03-23 13:35:39 +0000188 if (TEST_RETURN < 0) {
189 tst_brkm(TFAIL, cleanup,
190 "Error creating permanent directories, ERRNO = %d",
191 TEST_ERRNO);
robbiewbd756502002-12-04 23:16:31 +0000192 }
subrata_modak56207ce2009-03-23 13:35:39 +0000193 if ((j % NCHILD) != 0) {
194 if (rmdir(tmpdir) < 0) {
195 tst_brkm(TFAIL, cleanup,
196 "Error removing directory, ERRNO = %d",
197 errno);
robbiewbd756502002-12-04 23:16:31 +0000198 }
199 }
200 }
201
202 parent_pid = getpid();
203
204 /* allocate space for list of child pid's */
205
Cyril Hrubisd218f342014-09-23 13:14:56 +0200206 if ((pidlist = malloc((child_groups * NCHILD) * sizeof(int))) ==
Cyril Hrubis4e2bab82014-09-24 16:34:35 +0200207 NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100208 tst_brkm(TWARN, NULL,
209 "\tMalloc failed (may be OK if under stress)");
robbiewbd756502002-12-04 23:16:31 +0000210 }
211
212 child_count = 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000213 for (j = 0; j < child_groups; j++) {
214 for (i = 0; i < NCHILD; i++) {
215 getchild(j, i, child_count);
robbiewbd756502002-12-04 23:16:31 +0000216 child_count++;
217 }
218 }
219
subrata_modak56207ce2009-03-23 13:35:39 +0000220 /* If signal already received, skip to cleanup */
robbiewbd756502002-12-04 23:16:31 +0000221
subrata_modak56207ce2009-03-23 13:35:39 +0000222 if (!sigchld && !sigterm) {
223 if (test_time) {
robbiewbd756502002-12-04 23:16:31 +0000224 /* To get out of sleep if signal caught */
subrata_modak56207ce2009-03-23 13:35:39 +0000225 if (!setjmp(env_buf)) {
robbiewbd756502002-12-04 23:16:31 +0000226 jump++;
subrata_modak56207ce2009-03-23 13:35:39 +0000227 sleep(test_time);
robbiewbd756502002-12-04 23:16:31 +0000228 }
subrata_modak56207ce2009-03-23 13:35:39 +0000229 } else {
230 pause();
robbiewbd756502002-12-04 23:16:31 +0000231 }
subrata_modak56207ce2009-03-23 13:35:39 +0000232 }
robbiewbd756502002-12-04 23:16:31 +0000233
subrata_modak56207ce2009-03-23 13:35:39 +0000234 /* Reset signals since we are about to clean-up and to avoid
235 * problem with wait call * $
robbiewbd756502002-12-04 23:16:31 +0000236 * */
237
subrata_modak56207ce2009-03-23 13:35:39 +0000238 if (signal(SIGTERM, SIG_IGN) == SIG_ERR) {
239 tst_brkm(TFAIL, cleanup,
240 "Error resetting SIGTERM signal, ERRNO = %d", errno);
subrata_modak56207ce2009-03-23 13:35:39 +0000241 }
242 if (signal(SIGCLD, SIG_DFL) == SIG_ERR) {
243 tst_brkm(TFAIL, cleanup,
244 "Error resetting SIGCLD signal, ERRNO = %d", errno);
subrata_modak56207ce2009-03-23 13:35:39 +0000245 }
robbiewbd756502002-12-04 23:16:31 +0000246
subrata_modak56207ce2009-03-23 13:35:39 +0000247 if (test_time) {
248 sleep(test_time);
249 }
robbiewbd756502002-12-04 23:16:31 +0000250
251 /* Clean up children */
252 massmurder();
253 /*
254 * Watch children finish and show returns.
255 */
256
257 count = 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000258 while (1) {
259 if ((child = wait(&status)) > 0) {
260 if (status != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100261 tst_brkm(TWARN,
262 NULL,
subrata_modak56207ce2009-03-23 13:35:39 +0000263 "\tChild{%d} exited status = %0x",
264 child, status);
robbiewbd756502002-12-04 23:16:31 +0000265 }
266 count++;
subrata_modak56207ce2009-03-23 13:35:39 +0000267 } else {
268 if (errno != EINTR) {
robbiewbd756502002-12-04 23:16:31 +0000269 break;
270 }
vapiercff4af02006-02-11 04:46:30 +0000271 tst_resm(TINFO, "\tSignal detected during wait");
robbiewbd756502002-12-04 23:16:31 +0000272 }
273 }
274
275 /*
276 * Make sure correct number of children exited.
277 */
278
subrata_modak56207ce2009-03-23 13:35:39 +0000279 if (count != child_count) {
vapiercff4af02006-02-11 04:46:30 +0000280 tst_resm(TWARN, "\tWrong number of children waited on!");
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100281 tst_brkm(TWARN, NULL, "\tSaw %d, expected %d", count,
282 NCHILD);
robbiewbd756502002-12-04 23:16:31 +0000283 }
284
285 /* Check for core file in test directory. */
286
subrata_modak56207ce2009-03-23 13:35:39 +0000287 if (access("core", 0) == 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100288 tst_brkm(TWARN, NULL, "\tCore file found in test directory.");
robbiewbd756502002-12-04 23:16:31 +0000289 }
290
291 /* Remove expected files */
292
subrata_modak56207ce2009-03-23 13:35:39 +0000293 for (j = 0; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000294 sprintf(tmpdir, DIR_NAME, j);
subrata_modak56207ce2009-03-23 13:35:39 +0000295 if (rmdir(tmpdir) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100296 tst_brkm(TWARN,
297 NULL,
subrata_modak56207ce2009-03-23 13:35:39 +0000298 "\tError removing expected directory, ERRNO = %d",
299 errno);
robbiewbd756502002-12-04 23:16:31 +0000300 }
301 }
302
subrata_modak56207ce2009-03-23 13:35:39 +0000303 tst_resm(TPASS, "PASS");
robbiewbd756502002-12-04 23:16:31 +0000304
subrata_modak43337a32009-02-26 11:43:51 +0000305 return 0;
robbiewbd756502002-12-04 23:16:31 +0000306}
307
Mike Frysingerc57fba52014-04-09 18:56:30 -0400308int getchild(int group, int child, int children)
robbiewbd756502002-12-04 23:16:31 +0000309{
310 int pid;
311
robbiewd34d5812005-07-11 22:28:09 +0000312 pid = FORK_OR_VFORK();
robbiewbd756502002-12-04 23:16:31 +0000313
subrata_modak56207ce2009-03-23 13:35:39 +0000314 if (pid < 0) {
315
316 massmurder(); /* kill the kids */
317 tst_brkm(TBROK, cleanup,
318 "\tFork failed (may be OK if under stress)");
subrata_modak56207ce2009-03-23 13:35:39 +0000319 } else if (pid == 0) { /* child does this */
320 switch (children % NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000321 case 0:
robbiewd34d5812005-07-11 22:28:09 +0000322#ifdef UCLINUX
323 if (self_exec(argv0, "nd", 1, nfiles) < 0) {
324 massmurder();
325 tst_brkm(TBROK, cleanup, "\tself_exec failed");
robbiewd34d5812005-07-11 22:28:09 +0000326 }
327#else
subrata_modak56207ce2009-03-23 13:35:39 +0000328 dochild1(); /* create existing directories */
robbiewd34d5812005-07-11 22:28:09 +0000329#endif
subrata_modak56207ce2009-03-23 13:35:39 +0000330 break; /* so lint won't complain */
robbiewbd756502002-12-04 23:16:31 +0000331 case 1:
robbiewd34d5812005-07-11 22:28:09 +0000332#ifdef UCLINUX
333 if (self_exec(argv0, "n", 2) < 0) {
334 massmurder();
335 tst_brkm(TBROK, cleanup, "\tself_exec failed");
robbiewd34d5812005-07-11 22:28:09 +0000336 }
337#else
subrata_modak56207ce2009-03-23 13:35:39 +0000338 dochild2(); /* remove nonexistant directories */
robbiewd34d5812005-07-11 22:28:09 +0000339#endif
robbiewbd756502002-12-04 23:16:31 +0000340 break;
341 case 2:
robbiewd34d5812005-07-11 22:28:09 +0000342#ifdef UCLINUX
343 if (self_exec(argv0, "nd", 3, group) < 0) {
344 massmurder();
345 tst_brkm(TBROK, cleanup, "\tself_exec failed");
robbiewd34d5812005-07-11 22:28:09 +0000346 }
347#else
subrata_modak56207ce2009-03-23 13:35:39 +0000348 dochild3(group); /* create/delete directories */
robbiewd34d5812005-07-11 22:28:09 +0000349#endif
robbiewbd756502002-12-04 23:16:31 +0000350 break;
351 default:
subrata_modak56207ce2009-03-23 13:35:39 +0000352 tst_brkm(TFAIL, cleanup,
353 "Test not inplemented for child %d", child);
robbiewbd756502002-12-04 23:16:31 +0000354 exit(1);
355 break;
356 }
subrata_modak56207ce2009-03-23 13:35:39 +0000357 exit(1); /* If child gets here, something wrong */
robbiewbd756502002-12-04 23:16:31 +0000358 }
359 pidlist[children] = pid;
subrata_modak43337a32009-02-26 11:43:51 +0000360 return 0;
robbiewbd756502002-12-04 23:16:31 +0000361}
362
Mike Frysingere61ddba2014-04-09 23:24:32 -0400363void term(int sig)
robbiewbd756502002-12-04 23:16:31 +0000364{
365 /* Routine to handle SIGTERM signal. */
366
subrata_modak56207ce2009-03-23 13:35:39 +0000367 if (parent_pid == getpid()) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100368 tst_brkm(TWARN, NULL, "\tsignal SIGTERM received by parent.");
robbiewbd756502002-12-04 23:16:31 +0000369 }
370 sigterm++;
subrata_modak56207ce2009-03-23 13:35:39 +0000371 if (jump) {
robbiewbd756502002-12-04 23:16:31 +0000372 longjmp(env_buf, 1);
373 }
374}
375
Mike Frysingere61ddba2014-04-09 23:24:32 -0400376void chld(int sig)
robbiewbd756502002-12-04 23:16:31 +0000377{
378 /* Routine to handle SIGCLD signal. */
379
380 sigchld++;
subrata_modak56207ce2009-03-23 13:35:39 +0000381 if (jump) {
robbiewbd756502002-12-04 23:16:31 +0000382 longjmp(env_buf, 1);
383 }
384}
subrata_modakbdbaec52009-02-26 12:14:51 +0000385
Mike Frysingerc57fba52014-04-09 18:56:30 -0400386int dochild1(void)
robbiewbd756502002-12-04 23:16:31 +0000387{
388 /* Child routine which attempts to create directories in the test
389 * directory that already exist. Runs until a SIGTERM signal is
390 * received. Will exit with an error if it is able to create the
391 * directory or if the expected error is not received.
392 */
393
394 int j;
395 char tmpdir[MAXPATHLEN];
396
subrata_modak56207ce2009-03-23 13:35:39 +0000397 while (!sigterm) {
398 for (j = 0; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000399 sprintf(tmpdir, DIR_NAME, j);
subrata_modak4bb656a2009-02-26 12:02:09 +0000400 TEST(mkdir(tmpdir, MODE_RWX));
robbiewbd756502002-12-04 23:16:31 +0000401
subrata_modak56207ce2009-03-23 13:35:39 +0000402 if (TEST_RETURN < 0) {
robbiewbd756502002-12-04 23:16:31 +0000403
subrata_modak56207ce2009-03-23 13:35:39 +0000404 if (TEST_ERRNO != EEXIST) {
405 tst_brkm(TFAIL, cleanup,
406 "MKDIR %s, errno = %d; Wrong error detected.",
407 tmpdir, TEST_ERRNO);
robbiewbd756502002-12-04 23:16:31 +0000408 exit(1);
409 }
subrata_modak56207ce2009-03-23 13:35:39 +0000410 } else {
411 tst_brkm(TFAIL, cleanup,
412 "MKDIR %s succeded when it shoud have failed.",
413 tmpdir);
robbiewbd756502002-12-04 23:16:31 +0000414 exit(1);
415 }
416 }
417 }
418 exit(0);
419}
420
robbiewd34d5812005-07-11 22:28:09 +0000421#ifdef UCLINUX
Mike Frysingerc57fba52014-04-09 18:56:30 -0400422void dochild1_uclinux(void)
robbiewd34d5812005-07-11 22:28:09 +0000423{
424 /* Set up to catch SIGTERM signal */
subrata_modak56207ce2009-03-23 13:35:39 +0000425 if (signal(SIGTERM, term) == SIG_ERR) {
426 tst_brkm(TFAIL, cleanup,
427 "Error setting up SIGTERM signal, ERRNO = %d", errno);
robbiewd34d5812005-07-11 22:28:09 +0000428 }
429
430 dochild1();
431}
432#endif
433
Mike Frysingerc57fba52014-04-09 18:56:30 -0400434int dochild2(void)
robbiewbd756502002-12-04 23:16:31 +0000435{
436 /* Child routine which attempts to remove directories from the
437 * test directory which do not exist. Runs until a SIGTERM
438 * signal is received. Exits with an error if the proper
439 * error is not detected or if the remove operation is
440 * successful.
441 */
442
443 int j;
444 char tmpdir[MAXPATHLEN];
445
subrata_modak56207ce2009-03-23 13:35:39 +0000446 while (!sigterm) {
447 for (j = 1; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000448 sprintf(tmpdir, DIR_NAME, j);
subrata_modak56207ce2009-03-23 13:35:39 +0000449 if (rmdir(tmpdir) < 0) {
450 if (errno != ENOENT) {
451 tst_brkm(TFAIL, cleanup,
452 "RMDIR %s, errno = %d; Wrong error detected.",
453 tmpdir, errno);
robbiewbd756502002-12-04 23:16:31 +0000454 exit(1);
subrata_modak4bb656a2009-02-26 12:02:09 +0000455 }
subrata_modak56207ce2009-03-23 13:35:39 +0000456 } else {
457 tst_brkm(TFAIL, cleanup,
458 "RMDIR %s succeded when it should have failed.",
459 tmpdir);
robbiewbd756502002-12-04 23:16:31 +0000460 exit(1);
461 }
462 }
463 }
464 exit(0);
subrata_modak43337a32009-02-26 11:43:51 +0000465 return 0;
robbiewbd756502002-12-04 23:16:31 +0000466}
467
robbiewd34d5812005-07-11 22:28:09 +0000468#ifdef UCLINUX
Mike Frysingerc57fba52014-04-09 18:56:30 -0400469void dochild2_uclinux(void)
robbiewd34d5812005-07-11 22:28:09 +0000470{
471 /* Set up to catch SIGTERM signal */
subrata_modak56207ce2009-03-23 13:35:39 +0000472 if (signal(SIGTERM, term) == SIG_ERR) {
473 tst_brkm(TFAIL, cleanup,
474 "Error setting up SIGTERM signal, ERRNO = %d", errno);
robbiewd34d5812005-07-11 22:28:09 +0000475 }
476
477 dochild2();
478}
479#endif
480
Mike Frysingerc57fba52014-04-09 18:56:30 -0400481int dochild3(int group)
robbiewbd756502002-12-04 23:16:31 +0000482{
483 /* Child routine which creates and deletes directories in the
484 * test directory. Runs until a SIGTERM signal is received, then
485 * cleans up and exits. Detects error if the expected condition
486 * is not encountered.
487 */
488
489 int j;
subrata_modak56207ce2009-03-23 13:35:39 +0000490
robbiewbd756502002-12-04 23:16:31 +0000491 char tmpdir[MAXPATHLEN];
492 char tmp[MAXPATHLEN];
493
subrata_modak56207ce2009-03-23 13:35:39 +0000494 while (!sigterm) {
495 for (j = 2; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000496 strcpy(tmp, DIR_NAME);
497 strcat(tmp, ".%d");
498 sprintf(tmpdir, tmp, j, group);
499
subrata_modak4bb656a2009-02-26 12:02:09 +0000500 TEST(mkdir(tmpdir, MODE_RWX));
robbiewbd756502002-12-04 23:16:31 +0000501
subrata_modak56207ce2009-03-23 13:35:39 +0000502 if (TEST_RETURN < 0) {
503 tst_brkm(TFAIL, cleanup,
504 "MKDIR %s, errno = %d; Wrong error detected.",
505 tmpdir, TEST_ERRNO);
robbiewbd756502002-12-04 23:16:31 +0000506 exit(1);
507 }
508 }
subrata_modak56207ce2009-03-23 13:35:39 +0000509 for (j = 2; j < nfiles; j += NCHILD) {
robbiewbd756502002-12-04 23:16:31 +0000510 strcpy(tmp, DIR_NAME);
511 strcat(tmp, ".%d");
512 sprintf(tmpdir, tmp, j, group);
subrata_modak56207ce2009-03-23 13:35:39 +0000513 if (rmdir(tmpdir) < 0) {
514 tst_brkm(TFAIL, cleanup,
515 "RMDIR %s, errno = %d; Wrong error detected.",
516 tmpdir, errno);
robbiewbd756502002-12-04 23:16:31 +0000517 exit(1);
518 }
519 }
520 }
521 exit(0);
522}
robbiewd34d5812005-07-11 22:28:09 +0000523
524#ifdef UCLINUX
Mike Frysingerc57fba52014-04-09 18:56:30 -0400525void dochild3_uclinux(void)
robbiewd34d5812005-07-11 22:28:09 +0000526{
527 /* Set up to catch SIGTERM signal */
subrata_modak56207ce2009-03-23 13:35:39 +0000528 if (signal(SIGTERM, term) == SIG_ERR) {
529 tst_brkm(TFAIL, cleanup,
530 "Error setting up SIGTERM signal, ERRNO = %d", errno);
robbiewd34d5812005-07-11 22:28:09 +0000531 }
532
533 dochild3(group_uclinux);
534}
535#endif
536
Mike Frysingerc57fba52014-04-09 18:56:30 -0400537int massmurder(void)
robbiewbd756502002-12-04 23:16:31 +0000538{
subrata_modak56207ce2009-03-23 13:35:39 +0000539 register int j;
540 for (j = 0; j < child_count; j++) {
541 if (pidlist[j] > 0) {
542 if (kill(pidlist[j], SIGTERM) < 0) {
543 tst_brkm(TFAIL, cleanup,
544 "Error killing child %d, ERRNO = %d",
545 j, errno);
robbiewbd756502002-12-04 23:16:31 +0000546 }
547 }
548 }
subrata_modak56207ce2009-03-23 13:35:39 +0000549 return 0;
robbiewbd756502002-12-04 23:16:31 +0000550}
551
robbiewbd756502002-12-04 23:16:31 +0000552/***************************************************************
553 * * setup() - performs all ONE TIME setup for this test.
554 * ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400555void setup(void)
robbiewbd756502002-12-04 23:16:31 +0000556{
Garrett Cooper2c282152010-12-16 00:55:50 -0800557
subrata_modak56207ce2009-03-23 13:35:39 +0000558 tst_sig(NOFORK, DEF_HANDLER, cleanup);
robbiewbd756502002-12-04 23:16:31 +0000559
subrata_modak56207ce2009-03-23 13:35:39 +0000560 TEST_PAUSE;
robbiewbd756502002-12-04 23:16:31 +0000561
subrata_modak56207ce2009-03-23 13:35:39 +0000562 /* Create a temporary directory and make it current. */
563 tst_tmpdir();
robbiewbd756502002-12-04 23:16:31 +0000564
Garrett Cooper2c282152010-12-16 00:55:50 -0800565}
robbiewbd756502002-12-04 23:16:31 +0000566
567/***************************************************************
568 * * cleanup() - performs all ONE TIME cleanup for this test at
569 * * completion or premature exit.
570 * ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400571void cleanup(void)
robbiewbd756502002-12-04 23:16:31 +0000572{
robbiewbd756502002-12-04 23:16:31 +0000573
subrata_modak56207ce2009-03-23 13:35:39 +0000574 /*
575 * * Remove the temporary directory.
576 * */
577 tst_rmdir();
robbiewbd756502002-12-04 23:16:31 +0000578
subrata_modak56207ce2009-03-23 13:35:39 +0000579 /*
580 * * Exit with return code appropriate for results.
581 * */
robbiewbd756502002-12-04 23:16:31 +0000582
Garrett Cooperbacc8492011-01-14 00:36:17 -0800583}