blob: 809b0d70f5a429c09337b84f61e82d8210307c84 [file] [log] [blame]
robbiew24e30ab2003-01-07 20:53:21 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2002
subrata_modak04f47a12009-09-18 17:44:08 +00004 * Copyright (c) Cyril Hrubis chrubis@suse.cz 2009
robbiew24e30ab2003-01-07 20:53:21 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 * the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiew24e30ab2003-01-07 20:53:21 +000019 */
20
21/*
22 * NAME
23 * ftest06.c -- test inode things (ported from SPIE section2/filesuite/ftest7.c, by Airong Zhang)
24 *
25 * this is the same as ftest2, except that it uses lseek64
26 *
27 * CALLS
28 * open, close, read, write, llseek,
29 * unlink, chdir
subrata_modakbdbaec52009-02-26 12:14:51 +000030 *
robbiew24e30ab2003-01-07 20:53:21 +000031 *
32 * ALGORITHM
33 *
34 * This was tino.c by rbk. Moved to test suites by dale.
35 *
36 * ftest06 [-f tmpdirname] nchild iterations [partition]
37 *
38 * This forks some child processes, they do some random operations
39 * which use lots of directory operations.
40 *
41 * RESTRICTIONS
42 * Runs a long time with default args - can take others on input
43 * line. Use with "term mode".
44 * If run on vax the ftruncate will not be random - will always go to
45 * start of file. NOTE: produces a very high load average!!
46 *
47 */
48
subrata_modak04f47a12009-09-18 17:44:08 +000049#define _LARGEFILE64_SOURCE 1
50#include <stdio.h>
robbiew24e30ab2003-01-07 20:53:21 +000051#include <sys/types.h>
52#include <sys/param.h>
53#include <fcntl.h>
54#include <sys/stat.h>
55#include <sys/mount.h>
56#include <sys/wait.h>
vapierf81795e2006-02-15 06:28:58 +000057#include <errno.h>
subrata_modak04f47a12009-09-18 17:44:08 +000058#include <signal.h>
robbiew24e30ab2003-01-07 20:53:21 +000059#include <unistd.h>
60#include "test.h"
subrata_modak04f47a12009-09-18 17:44:08 +000061#include "libftest.h"
robbiew24e30ab2003-01-07 20:53:21 +000062
63char *TCID = "ftest06";
64int TST_TOTAL = 1;
robbiew24e30ab2003-01-07 20:53:21 +000065
66#define PASSED 1
67#define FAILED 0
68
subrata_modak04f47a12009-09-18 17:44:08 +000069static void crfile(int, int);
70static void unlfile(int, int);
71static void fussdir(int, int);
72static void dotest(int, int);
Wanlong Gao354ebb42012-12-07 10:10:04 +080073static void dowarn(int, char *, char *);
subrata_modak04f47a12009-09-18 17:44:08 +000074static void term(int sig);
75static void cleanup(void);
robbiew24e30ab2003-01-07 20:53:21 +000076
subrata_modak04f47a12009-09-18 17:44:08 +000077#define MAXCHILD 25
robbiew24e30ab2003-01-07 20:53:21 +000078#define K_1 1024
79#define K_2 2048
80#define K_4 4096
81
subrata_modak04f47a12009-09-18 17:44:08 +000082static int local_flag;
robbiew24e30ab2003-01-07 20:53:21 +000083
robbiew24e30ab2003-01-07 20:53:21 +000084#define M (1024*1024)
85
subrata_modak04f47a12009-09-18 17:44:08 +000086static int iterations;
87static int nchild;
88static int parent_pid;
89static int pidlist[MAXCHILD];
robbiew24e30ab2003-01-07 20:53:21 +000090
subrata_modak04f47a12009-09-18 17:44:08 +000091static char homedir[MAXPATHLEN];
92static char dirname[MAXPATHLEN];
subrata_modak04f47a12009-09-18 17:44:08 +000093static int dirlen;
94static int mnt = 0;
95static char startdir[MAXPATHLEN], mntpoint[MAXPATHLEN];
96static char *partition;
97static char *cwd;
98static char *fstyp;
robbiew24e30ab2003-01-07 20:53:21 +000099
subrata_modak04f47a12009-09-18 17:44:08 +0000100int main(int ac, char *av[])
robbiew24e30ab2003-01-07 20:53:21 +0000101{
subrata_modak04f47a12009-09-18 17:44:08 +0000102 int pid, child, status, count, k, j;
103 char name[3];
robbiew24e30ab2003-01-07 20:53:21 +0000104
Garrett Cooper7a73eab2010-11-09 22:45:42 -0800105 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200106 const char *msg;
robbiew24e30ab2003-01-07 20:53:21 +0000107
Garrett Cooper7a73eab2010-11-09 22:45:42 -0800108 /*
109 * parse standard options
110 */
Garrett Cooper0ff96ab2011-03-15 05:16:05 -0700111 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper7a73eab2010-11-09 22:45:42 -0800112 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew24e30ab2003-01-07 20:53:21 +0000113
robbiew24e30ab2003-01-07 20:53:21 +0000114 /*
115 * Default values for run conditions.
116 */
robbiew24e30ab2003-01-07 20:53:21 +0000117 iterations = 50;
118 nchild = 5;
119
subrata_modak04f47a12009-09-18 17:44:08 +0000120 if (signal(SIGTERM, term) == SIG_ERR) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800121 tst_resm(TBROK, "first signal failed");
Garrett Cooper2c282152010-12-16 00:55:50 -0800122
robbiew24e30ab2003-01-07 20:53:21 +0000123 }
124
125 /* use the default values for run conditions */
subrata_modak4bb656a2009-02-26 12:02:09 +0000126 for (lc = 0; TEST_LOOPING(lc); lc++) {
robbiew24e30ab2003-01-07 20:53:21 +0000127
128 local_flag = PASSED;
129 /*
130 * Make a directory to do this in; ignore error if already exists.
131 */
robbiew24e30ab2003-01-07 20:53:21 +0000132 parent_pid = getpid();
133 tst_tmpdir();
134
135 if (!startdir[0]) {
136 if (getcwd(startdir, MAXPATHLEN) == NULL) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800137 tst_brkm(TFAIL | TERRNO, NULL, "getcwd failed");
robbiew24e30ab2003-01-07 20:53:21 +0000138 }
subrata_modak04f47a12009-09-18 17:44:08 +0000139 }
robbiew24e30ab2003-01-07 20:53:21 +0000140 cwd = startdir;
Chris Dearman37550cf2012-10-17 19:54:01 -0700141
Cyril Hrubisa33bc182011-03-16 14:41:10 +0100142 snprintf(dirname, ARRAY_SIZE(dirname),
Wanlong Gao354ebb42012-12-07 10:10:04 +0800143 "%s/ftest06.%d", cwd, getpid());
Cyril Hrubisa33bc182011-03-16 14:41:10 +0100144 snprintf(homedir, ARRAY_SIZE(homedir),
Wanlong Gao354ebb42012-12-07 10:10:04 +0800145 "%s/ftest06h.%d", cwd, getpid());
robbiew24e30ab2003-01-07 20:53:21 +0000146
147 mkdir(dirname, 0755);
148 mkdir(homedir, 0755);
Cyril Hrubisa33bc182011-03-16 14:41:10 +0100149
150 if (chdir(dirname) < 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800151 tst_brkm(TFAIL | TERRNO, cleanup, "\tCan't chdir(%s)",
152 dirname);
Chris Dearman37550cf2012-10-17 19:54:01 -0700153
robbiew24e30ab2003-01-07 20:53:21 +0000154 dirlen = strlen(dirname);
Cyril Hrubisa33bc182011-03-16 14:41:10 +0100155
156 if (chdir(homedir) < 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800157 tst_brkm(TFAIL | TERRNO, cleanup, "\tCan't chdir(%s)",
158 homedir);
robbiew24e30ab2003-01-07 20:53:21 +0000159
160 /* enter block */
subrata_modak04f47a12009-09-18 17:44:08 +0000161 for (k = 0; k < nchild; k++) {
162 if ((child = fork()) == 0) {
163 dotest(k, iterations);
Garrett Cooper0ff96ab2011-03-15 05:16:05 -0700164 tst_exit();
robbiew24e30ab2003-01-07 20:53:21 +0000165 }
166 if (child < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800167 tst_brkm(TBROK | TERRNO, cleanup,
168 "fork failed");
robbiew24e30ab2003-01-07 20:53:21 +0000169 }
170 pidlist[k] = child;
171 }
172
173 /*
174 * Wait for children to finish.
175 */
robbiew24e30ab2003-01-07 20:53:21 +0000176 count = 0;
subrata_modak04f47a12009-09-18 17:44:08 +0000177 while ((child = wait(&status)) > 0) {
vapieraf64a872006-02-15 06:47:36 +0000178 //tst_resm(TINFO,"Test{%d} exited status = 0x%x", child, status);
179 //fprintf(stdout, "status is %d",status);
robbiew24e30ab2003-01-07 20:53:21 +0000180 if (status) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800181 tst_resm(TFAIL,
182 "Test{%d} failed, expected 0 exit.",
183 child);
robbiew24e30ab2003-01-07 20:53:21 +0000184 local_flag = FAILED;
185 }
186 ++count;
187 }
188
189 /*
190 * Should have collected all children.
191 */
robbiew24e30ab2003-01-07 20:53:21 +0000192 if (count != nchild) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800193 tst_resm(TFAIL,
194 "Wrong # children waited on, count = %d",
195 count);
robbiew24e30ab2003-01-07 20:53:21 +0000196 local_flag = FAILED;
197 }
198
subrata_modak04f47a12009-09-18 17:44:08 +0000199 if (local_flag == PASSED)
200 tst_resm(TPASS, "Test passed.");
201 else
202 tst_resm(TFAIL, "Test failed.");
robbiew24e30ab2003-01-07 20:53:21 +0000203
204 if (iterations > 26)
205 iterations = 26;
subrata_modak04f47a12009-09-18 17:44:08 +0000206
207 for (k = 0; k < nchild; k++)
208 for (j = 0; j < iterations + 1; j++) {
209 ft_mkname(name, dirname, k, j);
robbiew24e30ab2003-01-07 20:53:21 +0000210 rmdir(name);
211 unlink(name);
212 }
213
Cyril Hrubisa33bc182011-03-16 14:41:10 +0100214 if (chdir(startdir) < 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800215 tst_brkm(TFAIL | TERRNO, cleanup, "Can't chdir(%s)",
216 startdir);
robbiew24e30ab2003-01-07 20:53:21 +0000217
218 pid = fork();
219 if (pid < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800220 tst_brkm(TBROK | TERRNO, NULL, "fork failed");
robbiew24e30ab2003-01-07 20:53:21 +0000221 }
subrata_modak04f47a12009-09-18 17:44:08 +0000222
robbiew24e30ab2003-01-07 20:53:21 +0000223 if (pid == 0) {
robbiew7fdd5142005-02-07 19:39:54 +0000224 execl("/bin/rm", "rm", "-rf", homedir, NULL);
Garrett Cooper2c282152010-12-16 00:55:50 -0800225
robbiew24e30ab2003-01-07 20:53:21 +0000226 } else
227 wait(&status);
subrata_modak04f47a12009-09-18 17:44:08 +0000228
robbiew24e30ab2003-01-07 20:53:21 +0000229 if (status)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800230 tst_resm(TINFO,
231 "CAUTION - ftest06, '%s' may not have been removed.",
232 homedir);
robbiew24e30ab2003-01-07 20:53:21 +0000233
234 pid = fork();
235 if (pid < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800236 tst_brkm(TBROK | TERRNO, NULL, "fork failed");
robbiew24e30ab2003-01-07 20:53:21 +0000237 }
238 if (pid == 0) {
robbiew7fdd5142005-02-07 19:39:54 +0000239 execl("/bin/rm", "rm", "-rf", dirname, NULL);
Garrett Cooper7a73eab2010-11-09 22:45:42 -0800240 exit(1);
robbiew24e30ab2003-01-07 20:53:21 +0000241 } else
242 wait(&status);
243 if (status) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800244 tst_resm(TWARN,
245 "CAUTION - ftest06, '%s' may not have been removed.",
246 dirname);
robbiew24e30ab2003-01-07 20:53:21 +0000247 }
248
subrata_modak04f47a12009-09-18 17:44:08 +0000249 sync();
robbiew24e30ab2003-01-07 20:53:21 +0000250
subrata_modak04f47a12009-09-18 17:44:08 +0000251 }
252
253 if (local_flag == FAILED)
Garrett Cooper7a73eab2010-11-09 22:45:42 -0800254 tst_resm(TFAIL, "Test failed.");
255 else
256 tst_resm(TPASS, "Test passed.");
robbiew24e30ab2003-01-07 20:53:21 +0000257
258 cleanup();
Garrett Cooperb0a973a2011-01-21 01:15:32 -0800259 tst_exit();
robbiew24e30ab2003-01-07 20:53:21 +0000260}
261
subrata_modak04f47a12009-09-18 17:44:08 +0000262#define warn(val,m1,m2) if ((val) < 0) dowarn(me,m1,m2)
robbiew24e30ab2003-01-07 20:53:21 +0000263
264/*
265 * crfile()
266 * Create a file and write something into it.
267 */
subrata_modak04f47a12009-09-18 17:44:08 +0000268static char crmsg[] = "Gee, let's write something in the file!\n";
robbiew24e30ab2003-01-07 20:53:21 +0000269
subrata_modak04f47a12009-09-18 17:44:08 +0000270static void crfile(int me, int count)
robbiew24e30ab2003-01-07 20:53:21 +0000271{
Wanlong Gao354ebb42012-12-07 10:10:04 +0800272 int fd;
robbiew24e30ab2003-01-07 20:53:21 +0000273 off64_t seekval;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800274 int val;
275 char fname[MAXPATHLEN];
276 char buf[MAXPATHLEN];
robbiew24e30ab2003-01-07 20:53:21 +0000277
subrata_modak04f47a12009-09-18 17:44:08 +0000278 ft_mkname(fname, dirname, me, count);
robbiew24e30ab2003-01-07 20:53:21 +0000279
Wanlong Gao354ebb42012-12-07 10:10:04 +0800280 fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
robbiew24e30ab2003-01-07 20:53:21 +0000281 if (fd < 0 && errno == EISDIR) {
282 val = rmdir(fname);
283 warn(val, "rmdir", fname);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800284 fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
robbiew24e30ab2003-01-07 20:53:21 +0000285 }
286 warn(fd, "creating", fname);
287
Wanlong Gao354ebb42012-12-07 10:10:04 +0800288 seekval = lseek64(fd, (off64_t) (rand() % M), 0);
robbiew24e30ab2003-01-07 20:53:21 +0000289 warn(seekval, "lseek64", 0);
290
Wanlong Gao354ebb42012-12-07 10:10:04 +0800291 val = write(fd, crmsg, sizeof(crmsg) - 1);
robbiew24e30ab2003-01-07 20:53:21 +0000292 warn(val, "write", 0);
293
Wanlong Gao354ebb42012-12-07 10:10:04 +0800294 seekval = lseek(fd, -((off64_t) sizeof(crmsg) - 1), 1);
robbiew24e30ab2003-01-07 20:53:21 +0000295 warn(seekval, "lseek64", 0);
296
Wanlong Gao354ebb42012-12-07 10:10:04 +0800297 val = read(fd, buf, sizeof(crmsg) - 1);
robbiew24e30ab2003-01-07 20:53:21 +0000298 warn(val, "read", 0);
299
Wanlong Gao354ebb42012-12-07 10:10:04 +0800300 if (strncmp(crmsg, buf, sizeof(crmsg) - 1))
subrata_modak04f47a12009-09-18 17:44:08 +0000301 dowarn(me, "compare", 0);
robbiew24e30ab2003-01-07 20:53:21 +0000302
303 val = close(fd);
304 warn(val, "close", 0);
305}
306
307/*
308 * unlfile()
309 * Unlink some of the files.
310 */
subrata_modak04f47a12009-09-18 17:44:08 +0000311static void unlfile(int me, int count)
robbiew24e30ab2003-01-07 20:53:21 +0000312{
subrata_modak04f47a12009-09-18 17:44:08 +0000313 int val, i;
Garrett Cooperfde57722010-08-16 23:37:16 -0700314 char fname[MAXPATHLEN];
robbiew24e30ab2003-01-07 20:53:21 +0000315
316 i = count - 10;
317 if (i < 0)
318 i = 0;
subrata_modak04f47a12009-09-18 17:44:08 +0000319 for (; i < count; i++) {
320 ft_mkname(fname, dirname, me, i);
robbiew24e30ab2003-01-07 20:53:21 +0000321 val = rmdir(fname);
Garrett Cooper8fb1cdb2010-11-28 22:56:35 -0800322 if (val < 0)
robbiew24e30ab2003-01-07 20:53:21 +0000323 val = unlink(fname);
324 if (val == 0 || errno == ENOENT)
325 continue;
subrata_modak04f47a12009-09-18 17:44:08 +0000326 dowarn(me, "unlink", fname);
robbiew24e30ab2003-01-07 20:53:21 +0000327 }
328}
329
330/*
331 * fussdir()
332 * Make a directory, put stuff in it, remove it, and remove directory.
333 *
334 * Randomly leave the directory there.
335 */
subrata_modak04f47a12009-09-18 17:44:08 +0000336static void fussdir(int me, int count)
robbiew24e30ab2003-01-07 20:53:21 +0000337{
subrata_modak04f47a12009-09-18 17:44:08 +0000338 int val;
Garrett Cooperfde57722010-08-16 23:37:16 -0700339 char dir[MAXPATHLEN], fname[MAXPATHLEN], savedir[MAXPATHLEN];
robbiew24e30ab2003-01-07 20:53:21 +0000340
subrata_modak04f47a12009-09-18 17:44:08 +0000341 ft_mkname(dir, dirname, me, count);
342 rmdir(dir);
343 unlink(dir);
robbiew24e30ab2003-01-07 20:53:21 +0000344
345 val = mkdir(dir, 0755);
346 warn(val, "mkdir", dir);
347
348 /*
349 * Arrange to create files in the directory.
350 */
robbiew24e30ab2003-01-07 20:53:21 +0000351 strcpy(savedir, dirname);
352 strcpy(dirname, "");
353
354 val = chdir(dir);
355 warn(val, "chdir", dir);
356
357 crfile(me, count);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800358 crfile(me, count + 1);
robbiew24e30ab2003-01-07 20:53:21 +0000359
360 val = chdir("..");
361 warn(val, "chdir", "..");
362
363 val = rmdir(dir);
subrata_modak04f47a12009-09-18 17:44:08 +0000364
robbiew24e30ab2003-01-07 20:53:21 +0000365 if (val >= 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100366 tst_brkm(TFAIL, NULL,
367 "Test[%d]: rmdir of non-empty %s succeeds!", me,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800368 dir);
robbiew24e30ab2003-01-07 20:53:21 +0000369 }
370
371 val = chdir(dir);
372 warn(val, "chdir", dir);
373
subrata_modak04f47a12009-09-18 17:44:08 +0000374 ft_mkname(fname, dirname, me, count);
robbiew24e30ab2003-01-07 20:53:21 +0000375 val = unlink(fname);
376 warn(val, "unlink", fname);
377
Wanlong Gao354ebb42012-12-07 10:10:04 +0800378 ft_mkname(fname, dirname, me, count + 1);
robbiew24e30ab2003-01-07 20:53:21 +0000379 val = unlink(fname);
380 warn(val, "unlink", fname);
381
382 val = chdir(homedir);
383 warn(val, "chdir", homedir);
384
385 if (rand() & 0x01) {
386 val = rmdir(dir);
387 warn(val, "rmdir", dir);
388 }
389
390 strcpy(dirname, savedir);
391}
392
robbiew24e30ab2003-01-07 20:53:21 +0000393/*
394 * dotest()
395 * Children execute this.
396 *
397 * Randomly do an inode thing; loop for # iterations.
398 */
robbiew24e30ab2003-01-07 20:53:21 +0000399#define THING(p) {p, "p"}
400
Wanlong Gao354ebb42012-12-07 10:10:04 +0800401struct ino_thing {
402 void (*it_proc) ();
403 char *it_name;
404} ino_thing[] = {
405THING(crfile), THING(unlfile), THING(fussdir), THING(sync),};
robbiew24e30ab2003-01-07 20:53:21 +0000406
407#define NTHING (sizeof(ino_thing) / sizeof(ino_thing[0]))
408
Wanlong Gao354ebb42012-12-07 10:10:04 +0800409int thing_cnt[NTHING];
410int thing_last[NTHING];
robbiew24e30ab2003-01-07 20:53:21 +0000411
subrata_modak04f47a12009-09-18 17:44:08 +0000412static void dotest(int me, int count)
robbiew24e30ab2003-01-07 20:53:21 +0000413{
subrata_modak04f47a12009-09-18 17:44:08 +0000414 int thing, i;
robbiew24e30ab2003-01-07 20:53:21 +0000415
vapieraf64a872006-02-15 06:47:36 +0000416 //tst_resm(TINFO,"Test %d pid %d starting.", me, getpid());
robbiew24e30ab2003-01-07 20:53:21 +0000417
418 srand(getpid());
subrata_modak04f47a12009-09-18 17:44:08 +0000419
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800420 for (i = 0; i < count; i++) {
robbiew24e30ab2003-01-07 20:53:21 +0000421 thing = (rand() >> 3) % NTHING;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800422 (*ino_thing[thing].it_proc) (me, i, ino_thing[thing].it_name);
robbiew24e30ab2003-01-07 20:53:21 +0000423 ++thing_cnt[thing];
424 }
425
vapieraf64a872006-02-15 06:47:36 +0000426 //tst_resm(TINFO,"Test %d pid %d exiting.", me, getpid());
robbiew24e30ab2003-01-07 20:53:21 +0000427}
428
subrata_modak04f47a12009-09-18 17:44:08 +0000429static void dowarn(int me, char *m1, char *m2)
robbiew24e30ab2003-01-07 20:53:21 +0000430{
subrata_modak04f47a12009-09-18 17:44:08 +0000431 int err = errno;
robbiew24e30ab2003-01-07 20:53:21 +0000432
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100433 tst_brkm(TFAIL, NULL, "Test[%d]: error %d on %s %s",
Wanlong Gao354ebb42012-12-07 10:10:04 +0800434 me, err, m1, (m2 ? m2 : ""));
robbiew24e30ab2003-01-07 20:53:21 +0000435}
436
subrata_modak04f47a12009-09-18 17:44:08 +0000437static void term(int sig LTP_ATTRIBUTE_UNUSED)
robbiew24e30ab2003-01-07 20:53:21 +0000438{
subrata_modak04f47a12009-09-18 17:44:08 +0000439 int i;
robbiew24e30ab2003-01-07 20:53:21 +0000440
vapieraf64a872006-02-15 06:47:36 +0000441 tst_resm(TINFO, "\tterm -[%d]- got sig term.", getpid());
subrata_modakbdbaec52009-02-26 12:14:51 +0000442
robbiew24e30ab2003-01-07 20:53:21 +0000443 if (parent_pid == getpid()) {
subrata_modak04f47a12009-09-18 17:44:08 +0000444 for (i = 0; i < nchild; i++)
445 if (pidlist[i])
robbiew24e30ab2003-01-07 20:53:21 +0000446 kill(pidlist[i], SIGTERM);
subrata_modak04f47a12009-09-18 17:44:08 +0000447 return;
robbiew24e30ab2003-01-07 20:53:21 +0000448 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000449
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100450 tst_brkm(TBROK, NULL, "Term: Child process exiting.");
robbiew24e30ab2003-01-07 20:53:21 +0000451}
452
subrata_modak04f47a12009-09-18 17:44:08 +0000453static void cleanup(void)
robbiew24e30ab2003-01-07 20:53:21 +0000454{
455 char mount_buffer[1024];
456
457 if (mnt == 1) {
458 if (chdir(startdir) < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800459 tst_resm(TINFO, "Could not change to %s ", startdir);
robbiew24e30ab2003-01-07 20:53:21 +0000460 }
461 if (!strcmp(fstyp, "cfs")) {
subrata_modak04f47a12009-09-18 17:44:08 +0000462 sprintf(mount_buffer, "/bin/umount %s", partition);
robbiew24e30ab2003-01-07 20:53:21 +0000463 if (system(mount_buffer) != 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800464 tst_resm(TINFO, "Unable to unmount %s from %s ",
465 partition, mntpoint);
robbiew24e30ab2003-01-07 20:53:21 +0000466 if (umount(partition)) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800467 tst_resm(TINFO,
468 "Unable to unmount %s from %s ",
469 partition, mntpoint);
470 } else {
471 tst_resm(TINFO,
472 "Forced umount for %s, /etc/mtab now dirty",
473 partition);
robbiew24e30ab2003-01-07 20:53:21 +0000474 }
475 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800476 } else {
robbiew24e30ab2003-01-07 20:53:21 +0000477 if (umount(partition)) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800478 tst_resm(TINFO, "Unable to unmount %s from %s ",
479 partition, mntpoint);
robbiew24e30ab2003-01-07 20:53:21 +0000480 }
481 }
482 if (rmdir(mntpoint) != 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800483 tst_resm(TINFO, "Unable to rmdir %s ", mntpoint);
robbiew24e30ab2003-01-07 20:53:21 +0000484 }
485 }
486 tst_rmdir();
Garrett Cooper2c282152010-12-16 00:55:50 -0800487
Garrett Cooperb0a973a2011-01-21 01:15:32 -0800488}