xref: /aosp_15_r20/external/ltp/testcases/kernel/fs/inode/inode02.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker  *
3*49cdfc7eSAndroid Build Coastguard Worker  *   Copyright (c) International Business Machines  Corp., 2002
4*49cdfc7eSAndroid Build Coastguard Worker  *
5*49cdfc7eSAndroid Build Coastguard Worker  *   This program is free software;  you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker  *   it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker  *   the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker  *   (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker  *
10*49cdfc7eSAndroid Build Coastguard Worker  *   This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13*49cdfc7eSAndroid Build Coastguard Worker  *   the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker  *
15*49cdfc7eSAndroid Build Coastguard Worker  *   You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker  *   along with this program;  if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker  */
19*49cdfc7eSAndroid Build Coastguard Worker 
20*49cdfc7eSAndroid Build Coastguard Worker /* 11/01/2002	Port to LTP	[email protected] */
21*49cdfc7eSAndroid Build Coastguard Worker /* 06/30/2001	Port to Linux	[email protected] */
22*49cdfc7eSAndroid Build Coastguard Worker 
23*49cdfc7eSAndroid Build Coastguard Worker 			   /*inode02.c */
24*49cdfc7eSAndroid Build Coastguard Worker /*======================================================================
25*49cdfc7eSAndroid Build Coastguard Worker 	=================== TESTPLAN SEGMENT ===================
26*49cdfc7eSAndroid Build Coastguard Worker CALLS:	mkdir, stat, open
27*49cdfc7eSAndroid Build Coastguard Worker 
28*49cdfc7eSAndroid Build Coastguard Worker 	Run with TERM mode.
29*49cdfc7eSAndroid Build Coastguard Worker 
30*49cdfc7eSAndroid Build Coastguard Worker >KEYS:  < file system and I/O management, system resource constraints.
31*49cdfc7eSAndroid Build Coastguard Worker >WHAT:  < Can the system handle a heavy load on the file system I/O
32*49cdfc7eSAndroid Build Coastguard Worker 	< functions?
33*49cdfc7eSAndroid Build Coastguard Worker >HOW:   < Create several identical process that call inode02.c.  This
34*49cdfc7eSAndroid Build Coastguard Worker 	< will simulate the multi-user environment, and hopefully uncover
35*49cdfc7eSAndroid Build Coastguard Worker 	< conflicts that might occur in "real life" use.
36*49cdfc7eSAndroid Build Coastguard Worker >BUGS:  <
37*49cdfc7eSAndroid Build Coastguard Worker ======================================================================*/
38*49cdfc7eSAndroid Build Coastguard Worker 
39*49cdfc7eSAndroid Build Coastguard Worker #define PATH_STRING_LENGTH  1024
40*49cdfc7eSAndroid Build Coastguard Worker #define NAME_LENGTH  8
41*49cdfc7eSAndroid Build Coastguard Worker #define MAX_PATH_STRING_LENGTH  (PATH_STRING_LENGTH - NAME_LENGTH - 40)
42*49cdfc7eSAndroid Build Coastguard Worker #define DIRECTORY_MODE  00777
43*49cdfc7eSAndroid Build Coastguard Worker #define FILE_MODE       00777
44*49cdfc7eSAndroid Build Coastguard Worker 
45*49cdfc7eSAndroid Build Coastguard Worker #define MKDIR_STRING_LENGTH  (MAX_PATH_STRING_LENGTH + 7)
46*49cdfc7eSAndroid Build Coastguard Worker 
47*49cdfc7eSAndroid Build Coastguard Worker /* #define DEBUG	 you can watch the generation with this flag */
48*49cdfc7eSAndroid Build Coastguard Worker 
49*49cdfc7eSAndroid Build Coastguard Worker #define TRUE  1
50*49cdfc7eSAndroid Build Coastguard Worker #define FALSE 0
51*49cdfc7eSAndroid Build Coastguard Worker #define READ  0
52*49cdfc7eSAndroid Build Coastguard Worker #define WRITE 1
53*49cdfc7eSAndroid Build Coastguard Worker 
54*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
55*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
56*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
57*49cdfc7eSAndroid Build Coastguard Worker #include <sys/stat.h>
58*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
59*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
60*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
61*49cdfc7eSAndroid Build Coastguard Worker #include <sys/wait.h>
62*49cdfc7eSAndroid Build Coastguard Worker 
63*49cdfc7eSAndroid Build Coastguard Worker #ifdef LINUX
64*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
65*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
66*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
67*49cdfc7eSAndroid Build Coastguard Worker #endif
68*49cdfc7eSAndroid Build Coastguard Worker 
69*49cdfc7eSAndroid Build Coastguard Worker #define MAXCHILD	25
70*49cdfc7eSAndroid Build Coastguard Worker int allchild[MAXCHILD + 1];
71*49cdfc7eSAndroid Build Coastguard Worker 
72*49cdfc7eSAndroid Build Coastguard Worker char name[NAME_LENGTH + 1];
73*49cdfc7eSAndroid Build Coastguard Worker char path_string[PATH_STRING_LENGTH + 1];
74*49cdfc7eSAndroid Build Coastguard Worker char read_string[PATH_STRING_LENGTH + 1];
75*49cdfc7eSAndroid Build Coastguard Worker char write_string[PATH_STRING_LENGTH + 1];
76*49cdfc7eSAndroid Build Coastguard Worker char remove_string[PATH_STRING_LENGTH + 10];
77*49cdfc7eSAndroid Build Coastguard Worker int parent_pid;
78*49cdfc7eSAndroid Build Coastguard Worker int nchild;
79*49cdfc7eSAndroid Build Coastguard Worker 
80*49cdfc7eSAndroid Build Coastguard Worker FILE *list_stream = NULL;
81*49cdfc7eSAndroid Build Coastguard Worker int list_id;
82*49cdfc7eSAndroid Build Coastguard Worker int file_id;
83*49cdfc7eSAndroid Build Coastguard Worker 
84*49cdfc7eSAndroid Build Coastguard Worker int increment_name(), get_next_name(), mode(), escrivez(), massmurder();
85*49cdfc7eSAndroid Build Coastguard Worker int max_depth, max_breadth, file_length;
86*49cdfc7eSAndroid Build Coastguard Worker int bd_arg(char *);
87*49cdfc7eSAndroid Build Coastguard Worker 
88*49cdfc7eSAndroid Build Coastguard Worker #ifdef LINUX
89*49cdfc7eSAndroid Build Coastguard Worker void (*sigset(int, void (*)(int))) (int);
90*49cdfc7eSAndroid Build Coastguard Worker #endif
91*49cdfc7eSAndroid Build Coastguard Worker 
92*49cdfc7eSAndroid Build Coastguard Worker /** LTP Port **/
93*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
94*49cdfc7eSAndroid Build Coastguard Worker 
95*49cdfc7eSAndroid Build Coastguard Worker void setup(void);
96*49cdfc7eSAndroid Build Coastguard Worker void fail_exit(void);
97*49cdfc7eSAndroid Build Coastguard Worker void anyfail(void);
98*49cdfc7eSAndroid Build Coastguard Worker void ok_exit(void);
99*49cdfc7eSAndroid Build Coastguard Worker void forkfail(void);
100*49cdfc7eSAndroid Build Coastguard Worker void terror(char *);
101*49cdfc7eSAndroid Build Coastguard Worker int instress(void);
102*49cdfc7eSAndroid Build Coastguard Worker 
103*49cdfc7eSAndroid Build Coastguard Worker #define FAILED 0
104*49cdfc7eSAndroid Build Coastguard Worker #define PASSED 1
105*49cdfc7eSAndroid Build Coastguard Worker 
106*49cdfc7eSAndroid Build Coastguard Worker int local_flag = PASSED;
107*49cdfc7eSAndroid Build Coastguard Worker FILE *temp;
108*49cdfc7eSAndroid Build Coastguard Worker 
109*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "inode02";		/* Test program identifier.    */
110*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1;		/* Total number of test cases. */
111*49cdfc7eSAndroid Build Coastguard Worker /**************/
112*49cdfc7eSAndroid Build Coastguard Worker 
main(int argc,char * argv[])113*49cdfc7eSAndroid Build Coastguard Worker int main(int argc, char *argv[])
114*49cdfc7eSAndroid Build Coastguard Worker {
115*49cdfc7eSAndroid Build Coastguard Worker 	int pid, tree(), p, status;
116*49cdfc7eSAndroid Build Coastguard Worker 	int count, child;
117*49cdfc7eSAndroid Build Coastguard Worker 	register int i;
118*49cdfc7eSAndroid Build Coastguard Worker 	int term();
119*49cdfc7eSAndroid Build Coastguard Worker 
120*49cdfc7eSAndroid Build Coastguard Worker 	setup();
121*49cdfc7eSAndroid Build Coastguard Worker 
122*49cdfc7eSAndroid Build Coastguard Worker 	parent_pid = getpid();
123*49cdfc7eSAndroid Build Coastguard Worker 
124*49cdfc7eSAndroid Build Coastguard Worker 	if (sigset(SIGTERM, (void (*)())term) == SIG_ERR) {
125*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TBROK, "\tSIGTERM sigset set failed, errno=%d",
126*49cdfc7eSAndroid Build Coastguard Worker 			 errno);
127*49cdfc7eSAndroid Build Coastguard Worker 		exit(1);
128*49cdfc7eSAndroid Build Coastguard Worker 	}
129*49cdfc7eSAndroid Build Coastguard Worker 
130*49cdfc7eSAndroid Build Coastguard Worker 	/************************************************/
131*49cdfc7eSAndroid Build Coastguard Worker 	/*                                              */
132*49cdfc7eSAndroid Build Coastguard Worker 	/*  Input the parameters for the directory---   */
133*49cdfc7eSAndroid Build Coastguard Worker 	/*  file trees which are to be generated        */
134*49cdfc7eSAndroid Build Coastguard Worker 	/*                                              */
135*49cdfc7eSAndroid Build Coastguard Worker 	/************************************************/
136*49cdfc7eSAndroid Build Coastguard Worker 
137*49cdfc7eSAndroid Build Coastguard Worker 	if (argc < 2) {
138*49cdfc7eSAndroid Build Coastguard Worker 		max_depth = 6;
139*49cdfc7eSAndroid Build Coastguard Worker 		max_breadth = 5;
140*49cdfc7eSAndroid Build Coastguard Worker 		file_length = 8;
141*49cdfc7eSAndroid Build Coastguard Worker 		nchild = 5;
142*49cdfc7eSAndroid Build Coastguard Worker 	} else if (argc < 5) {
143*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TCONF, "Bad argument count.");
144*49cdfc7eSAndroid Build Coastguard Worker 		printf
145*49cdfc7eSAndroid Build Coastguard Worker 		    ("\tinode02 max_depth max_breadth file_length #children\n\tdefault: inode02 6 5 8 5\n");
146*49cdfc7eSAndroid Build Coastguard Worker 		exit(1);
147*49cdfc7eSAndroid Build Coastguard Worker 	} else {
148*49cdfc7eSAndroid Build Coastguard Worker 		i = 1;
149*49cdfc7eSAndroid Build Coastguard Worker 		if (sscanf(argv[i++], "%d", &max_depth) != 1)
150*49cdfc7eSAndroid Build Coastguard Worker 			bd_arg(argv[i - 1]);
151*49cdfc7eSAndroid Build Coastguard Worker 		if (sscanf(argv[i++], "%d", &max_breadth) != 1)
152*49cdfc7eSAndroid Build Coastguard Worker 			bd_arg(argv[i - 1]);
153*49cdfc7eSAndroid Build Coastguard Worker 		if (sscanf(argv[i++], "%d", &file_length) != 1)
154*49cdfc7eSAndroid Build Coastguard Worker 			bd_arg(argv[i - 1]);
155*49cdfc7eSAndroid Build Coastguard Worker 		if (sscanf(argv[i++], "%d", &nchild) != 1)
156*49cdfc7eSAndroid Build Coastguard Worker 			bd_arg(argv[i - 1]);
157*49cdfc7eSAndroid Build Coastguard Worker 		if (nchild > MAXCHILD) {
158*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp, "too many children - max is %d\n",
159*49cdfc7eSAndroid Build Coastguard Worker 				MAXCHILD);
160*49cdfc7eSAndroid Build Coastguard Worker 			exit(1);
161*49cdfc7eSAndroid Build Coastguard Worker 		}
162*49cdfc7eSAndroid Build Coastguard Worker 	}
163*49cdfc7eSAndroid Build Coastguard Worker 
164*49cdfc7eSAndroid Build Coastguard Worker 	/************************************************/
165*49cdfc7eSAndroid Build Coastguard Worker 	/*                                              */
166*49cdfc7eSAndroid Build Coastguard Worker 	/*  Generate and check nchild trees             */
167*49cdfc7eSAndroid Build Coastguard Worker 	/*                                              */
168*49cdfc7eSAndroid Build Coastguard Worker 	/************************************************/
169*49cdfc7eSAndroid Build Coastguard Worker 
170*49cdfc7eSAndroid Build Coastguard Worker 	for (p = 0; p < nchild; p++) {
171*49cdfc7eSAndroid Build Coastguard Worker 		pid = fork();
172*49cdfc7eSAndroid Build Coastguard Worker 		if (pid == 0) {
173*49cdfc7eSAndroid Build Coastguard Worker 			tree();
174*49cdfc7eSAndroid Build Coastguard Worker 		} else {
175*49cdfc7eSAndroid Build Coastguard Worker 			if (pid < 1) {
176*49cdfc7eSAndroid Build Coastguard Worker 				terror
177*49cdfc7eSAndroid Build Coastguard Worker 				    ("Fork failed (may be OK if under stress)");
178*49cdfc7eSAndroid Build Coastguard Worker 				massmurder();
179*49cdfc7eSAndroid Build Coastguard Worker 				if (instress()) {
180*49cdfc7eSAndroid Build Coastguard Worker 					ok_exit();
181*49cdfc7eSAndroid Build Coastguard Worker 				}
182*49cdfc7eSAndroid Build Coastguard Worker 				forkfail();
183*49cdfc7eSAndroid Build Coastguard Worker 			}
184*49cdfc7eSAndroid Build Coastguard Worker 		}
185*49cdfc7eSAndroid Build Coastguard Worker 	}
186*49cdfc7eSAndroid Build Coastguard Worker 
187*49cdfc7eSAndroid Build Coastguard Worker 	count = 0;
188*49cdfc7eSAndroid Build Coastguard Worker 	while ((child = wait(&status)) > 0) {
189*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
190*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Test %d exited status = %d\n", child, status);
191*49cdfc7eSAndroid Build Coastguard Worker #endif
192*49cdfc7eSAndroid Build Coastguard Worker 		if (status) {
193*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp, "Test %d failed - expected 0 exit.\n",
194*49cdfc7eSAndroid Build Coastguard Worker 				child);
195*49cdfc7eSAndroid Build Coastguard Worker 			local_flag = FAILED;
196*49cdfc7eSAndroid Build Coastguard Worker 		}
197*49cdfc7eSAndroid Build Coastguard Worker 		count++;
198*49cdfc7eSAndroid Build Coastguard Worker 	}
199*49cdfc7eSAndroid Build Coastguard Worker 
200*49cdfc7eSAndroid Build Coastguard Worker 	if (count != nchild) {
201*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TFAIL, "Wrong number of children waited on!");
202*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TFAIL, "Saw %d, expected %d", count, nchild);
203*49cdfc7eSAndroid Build Coastguard Worker 		local_flag = FAILED;
204*49cdfc7eSAndroid Build Coastguard Worker 	}
205*49cdfc7eSAndroid Build Coastguard Worker 
206*49cdfc7eSAndroid Build Coastguard Worker 	/************************************************/
207*49cdfc7eSAndroid Build Coastguard Worker 	/*                                              */
208*49cdfc7eSAndroid Build Coastguard Worker 	/*  And report the results..........            */
209*49cdfc7eSAndroid Build Coastguard Worker 	/*                                              */
210*49cdfc7eSAndroid Build Coastguard Worker 	/************************************************/
211*49cdfc7eSAndroid Build Coastguard Worker 
212*49cdfc7eSAndroid Build Coastguard Worker 	anyfail();
213*49cdfc7eSAndroid Build Coastguard Worker 	/** NOT REACHED **/
214*49cdfc7eSAndroid Build Coastguard Worker 	tst_exit();
215*49cdfc7eSAndroid Build Coastguard Worker }
216*49cdfc7eSAndroid Build Coastguard Worker 
bd_arg(char * str)217*49cdfc7eSAndroid Build Coastguard Worker int bd_arg(char *str)
218*49cdfc7eSAndroid Build Coastguard Worker {
219*49cdfc7eSAndroid Build Coastguard Worker 	fprintf(temp,
220*49cdfc7eSAndroid Build Coastguard Worker 		"Bad argument - %s - could not parse as number.\n\tinode02 [max_depth] [max_breadth] [file_length] [#children]\n\tdefault: inode02 6 5 8 5\n",
221*49cdfc7eSAndroid Build Coastguard Worker 		str);
222*49cdfc7eSAndroid Build Coastguard Worker 	exit(1);
223*49cdfc7eSAndroid Build Coastguard Worker }
224*49cdfc7eSAndroid Build Coastguard Worker 
tree(void)225*49cdfc7eSAndroid Build Coastguard Worker int tree(void)
226*49cdfc7eSAndroid Build Coastguard Worker 
227*49cdfc7eSAndroid Build Coastguard Worker /************************************************/
228*49cdfc7eSAndroid Build Coastguard Worker /*						*/
229*49cdfc7eSAndroid Build Coastguard Worker /*  		      TREE			*/
230*49cdfc7eSAndroid Build Coastguard Worker /*						*/
231*49cdfc7eSAndroid Build Coastguard Worker /*   generate a tree of directories and files   */
232*49cdfc7eSAndroid Build Coastguard Worker /*   and save the path names in the path_list	*/
233*49cdfc7eSAndroid Build Coastguard Worker /*   file 					*/
234*49cdfc7eSAndroid Build Coastguard Worker /*						*/
235*49cdfc7eSAndroid Build Coastguard Worker /*   then, read the path names and attempt to   */
236*49cdfc7eSAndroid Build Coastguard Worker /*   access the corresponding directories and	*/
237*49cdfc7eSAndroid Build Coastguard Worker /*   files					*/
238*49cdfc7eSAndroid Build Coastguard Worker /*						*/
239*49cdfc7eSAndroid Build Coastguard Worker /************************************************/
240*49cdfc7eSAndroid Build Coastguard Worker {
241*49cdfc7eSAndroid Build Coastguard Worker 	int gen_ret_val, ch_ret_val, exit_val, level;
242*49cdfc7eSAndroid Build Coastguard Worker 	int ret_val;
243*49cdfc7eSAndroid Build Coastguard Worker 	int generate(), check();
244*49cdfc7eSAndroid Build Coastguard Worker 	char path_list_string[PATH_STRING_LENGTH + 10];
245*49cdfc7eSAndroid Build Coastguard Worker 	int len;
246*49cdfc7eSAndroid Build Coastguard Worker 	int status;
247*49cdfc7eSAndroid Build Coastguard Worker 	int snp_ret;
248*49cdfc7eSAndroid Build Coastguard Worker 
249*49cdfc7eSAndroid Build Coastguard Worker 	/********************************/
250*49cdfc7eSAndroid Build Coastguard Worker 	/*                              */
251*49cdfc7eSAndroid Build Coastguard Worker 	/*  make the root directory for */
252*49cdfc7eSAndroid Build Coastguard Worker 	/*  the tree                    */
253*49cdfc7eSAndroid Build Coastguard Worker 	/*                              */
254*49cdfc7eSAndroid Build Coastguard Worker 	/********************************/
255*49cdfc7eSAndroid Build Coastguard Worker 
256*49cdfc7eSAndroid Build Coastguard Worker 	sprintf(path_string, "inode02.%d", getpid());
257*49cdfc7eSAndroid Build Coastguard Worker 
258*49cdfc7eSAndroid Build Coastguard Worker 	ret_val = mkdir(path_string, DIRECTORY_MODE);
259*49cdfc7eSAndroid Build Coastguard Worker 
260*49cdfc7eSAndroid Build Coastguard Worker 	if (ret_val == -1) {
261*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TBROK,
262*49cdfc7eSAndroid Build Coastguard Worker 			 "Reason: Impossible to create directory %s, errno=%d\n",
263*49cdfc7eSAndroid Build Coastguard Worker 			 path_string, errno);
264*49cdfc7eSAndroid Build Coastguard Worker 		exit(-5);
265*49cdfc7eSAndroid Build Coastguard Worker 	}
266*49cdfc7eSAndroid Build Coastguard Worker 
267*49cdfc7eSAndroid Build Coastguard Worker 	strcpy(remove_string, "rm -rf ");
268*49cdfc7eSAndroid Build Coastguard Worker 	strcat(remove_string, path_string);
269*49cdfc7eSAndroid Build Coastguard Worker 
270*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
271*49cdfc7eSAndroid Build Coastguard Worker 	tst_resm(TINFO, "\n%s\n", path_string);
272*49cdfc7eSAndroid Build Coastguard Worker #endif
273*49cdfc7eSAndroid Build Coastguard Worker 
274*49cdfc7eSAndroid Build Coastguard Worker 	/****************************************/
275*49cdfc7eSAndroid Build Coastguard Worker 	/*                                      */
276*49cdfc7eSAndroid Build Coastguard Worker 	/*  create the "path_list" file, in     */
277*49cdfc7eSAndroid Build Coastguard Worker 	/*  which the list of generated paths   */
278*49cdfc7eSAndroid Build Coastguard Worker 	/*  will be stored so that they later   */
279*49cdfc7eSAndroid Build Coastguard Worker 	/*  may be checked                      */
280*49cdfc7eSAndroid Build Coastguard Worker 	/*                                      */
281*49cdfc7eSAndroid Build Coastguard Worker 	/****************************************/
282*49cdfc7eSAndroid Build Coastguard Worker 
283*49cdfc7eSAndroid Build Coastguard Worker 	snp_ret = snprintf(path_list_string, sizeof(path_list_string),
284*49cdfc7eSAndroid Build Coastguard Worker 		"%s/path_list",	path_string);
285*49cdfc7eSAndroid Build Coastguard Worker 	if (snp_ret < 0 || snp_ret >= sizeof(path_list_string)) {
286*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TBROK, "snprintf(path_list_string,..) returned %d",
287*49cdfc7eSAndroid Build Coastguard Worker 			snp_ret);
288*49cdfc7eSAndroid Build Coastguard Worker 		exit(-1);
289*49cdfc7eSAndroid Build Coastguard Worker 	}
290*49cdfc7eSAndroid Build Coastguard Worker 	list_id = creat(path_list_string, FILE_MODE);
291*49cdfc7eSAndroid Build Coastguard Worker 	if (list_id == -1) {
292*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp,
293*49cdfc7eSAndroid Build Coastguard Worker 			"\nThe path_list file '%s' cannot be created, errno=%d\n",
294*49cdfc7eSAndroid Build Coastguard Worker 			path_list_string, errno);
295*49cdfc7eSAndroid Build Coastguard Worker 		exit(-7);
296*49cdfc7eSAndroid Build Coastguard Worker 	}
297*49cdfc7eSAndroid Build Coastguard Worker 
298*49cdfc7eSAndroid Build Coastguard Worker 	/****************************************/
299*49cdfc7eSAndroid Build Coastguard Worker 	/*                                      */
300*49cdfc7eSAndroid Build Coastguard Worker 	/*   and store its name in path_list    */
301*49cdfc7eSAndroid Build Coastguard Worker 	/*                                      */
302*49cdfc7eSAndroid Build Coastguard Worker 	/****************************************/
303*49cdfc7eSAndroid Build Coastguard Worker 
304*49cdfc7eSAndroid Build Coastguard Worker 	strcpy(write_string, path_string);
305*49cdfc7eSAndroid Build Coastguard Worker 	len = strlen(write_string);
306*49cdfc7eSAndroid Build Coastguard Worker 	write_string[len++] = 'D';
307*49cdfc7eSAndroid Build Coastguard Worker 	write_string[len] = '\0';
308*49cdfc7eSAndroid Build Coastguard Worker 	escrivez(write_string);
309*49cdfc7eSAndroid Build Coastguard Worker 
310*49cdfc7eSAndroid Build Coastguard Worker 	/****************************************/
311*49cdfc7eSAndroid Build Coastguard Worker 	/*                                      */
312*49cdfc7eSAndroid Build Coastguard Worker 	/*   generate the directory-file tree   */
313*49cdfc7eSAndroid Build Coastguard Worker 	/*                                      */
314*49cdfc7eSAndroid Build Coastguard Worker 	/****************************************/
315*49cdfc7eSAndroid Build Coastguard Worker 
316*49cdfc7eSAndroid Build Coastguard Worker 	level = 0;
317*49cdfc7eSAndroid Build Coastguard Worker 
318*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
319*49cdfc7eSAndroid Build Coastguard Worker 	tst_resm(TINFO, "\n\t%s\n\n", "GENERATING:");
320*49cdfc7eSAndroid Build Coastguard Worker #endif
321*49cdfc7eSAndroid Build Coastguard Worker 
322*49cdfc7eSAndroid Build Coastguard Worker 	gen_ret_val = generate(path_string, level);
323*49cdfc7eSAndroid Build Coastguard Worker 	close(list_id);
324*49cdfc7eSAndroid Build Coastguard Worker 	list_id = open(path_list_string, READ);
325*49cdfc7eSAndroid Build Coastguard Worker 	if (list_id == -1) {
326*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp,
327*49cdfc7eSAndroid Build Coastguard Worker 			"\nThe path_list file cannot be opened for reading, errno=%d\n",
328*49cdfc7eSAndroid Build Coastguard Worker 			errno);
329*49cdfc7eSAndroid Build Coastguard Worker 		exit(-8);
330*49cdfc7eSAndroid Build Coastguard Worker 	}
331*49cdfc7eSAndroid Build Coastguard Worker 	list_stream = fdopen(list_id, "r");
332*49cdfc7eSAndroid Build Coastguard Worker 
333*49cdfc7eSAndroid Build Coastguard Worker 	/****************************************/
334*49cdfc7eSAndroid Build Coastguard Worker 	/*                                      */
335*49cdfc7eSAndroid Build Coastguard Worker 	/*   check the directory-file tree      */
336*49cdfc7eSAndroid Build Coastguard Worker 	/*      for correctness                 */
337*49cdfc7eSAndroid Build Coastguard Worker 	/*                                      */
338*49cdfc7eSAndroid Build Coastguard Worker 	/****************************************/
339*49cdfc7eSAndroid Build Coastguard Worker 
340*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
341*49cdfc7eSAndroid Build Coastguard Worker 	tst_resm(TINFO, "\n\t%s\n\n", "CHECKING:");
342*49cdfc7eSAndroid Build Coastguard Worker #endif
343*49cdfc7eSAndroid Build Coastguard Worker 
344*49cdfc7eSAndroid Build Coastguard Worker 	ch_ret_val = check();
345*49cdfc7eSAndroid Build Coastguard Worker 
346*49cdfc7eSAndroid Build Coastguard Worker 	exit_val = MIN(ch_ret_val, gen_ret_val);
347*49cdfc7eSAndroid Build Coastguard Worker 
348*49cdfc7eSAndroid Build Coastguard Worker 	status = fclose(list_stream);
349*49cdfc7eSAndroid Build Coastguard Worker 	if (status != 0) {
350*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp,
351*49cdfc7eSAndroid Build Coastguard Worker 			"Failed to close list_stream: ret=%d errno=%d (%s)\n",
352*49cdfc7eSAndroid Build Coastguard Worker 			status, errno, strerror(errno));
353*49cdfc7eSAndroid Build Coastguard Worker 		exit(-8);
354*49cdfc7eSAndroid Build Coastguard Worker 	}
355*49cdfc7eSAndroid Build Coastguard Worker 
356*49cdfc7eSAndroid Build Coastguard Worker 	/*
357*49cdfc7eSAndroid Build Coastguard Worker 	 * Remove file.
358*49cdfc7eSAndroid Build Coastguard Worker 	 */
359*49cdfc7eSAndroid Build Coastguard Worker 
360*49cdfc7eSAndroid Build Coastguard Worker 	status = system(remove_string);
361*49cdfc7eSAndroid Build Coastguard Worker 	if (status) {
362*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "Caution - `%s' failed.\n", remove_string);
363*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "Status returned %d.\n", status);
364*49cdfc7eSAndroid Build Coastguard Worker 	}
365*49cdfc7eSAndroid Build Coastguard Worker 
366*49cdfc7eSAndroid Build Coastguard Worker 	/****************************************/
367*49cdfc7eSAndroid Build Coastguard Worker 	/*                                      */
368*49cdfc7eSAndroid Build Coastguard Worker 	/*         .....and exit main           */
369*49cdfc7eSAndroid Build Coastguard Worker 	/*                                      */
370*49cdfc7eSAndroid Build Coastguard Worker 	/****************************************/
371*49cdfc7eSAndroid Build Coastguard Worker 
372*49cdfc7eSAndroid Build Coastguard Worker 	exit(exit_val);
373*49cdfc7eSAndroid Build Coastguard Worker }
374*49cdfc7eSAndroid Build Coastguard Worker 
generate(char * string,int level)375*49cdfc7eSAndroid Build Coastguard Worker int generate(char *string, int level)
376*49cdfc7eSAndroid Build Coastguard Worker 
377*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
378*49cdfc7eSAndroid Build Coastguard Worker /*					*/
379*49cdfc7eSAndroid Build Coastguard Worker /*   generate recursively a tree of	*/
380*49cdfc7eSAndroid Build Coastguard Worker /*   directories and files:  within   	*/
381*49cdfc7eSAndroid Build Coastguard Worker /*   created directory, an alternating	*/
382*49cdfc7eSAndroid Build Coastguard Worker /*   series of files and directories 	*/
383*49cdfc7eSAndroid Build Coastguard Worker /*   are constructed---until tree	*/
384*49cdfc7eSAndroid Build Coastguard Worker /*   breadth and depth limits are	*/
385*49cdfc7eSAndroid Build Coastguard Worker /*   reached or an error occurs		*/
386*49cdfc7eSAndroid Build Coastguard Worker /*					*/
387*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
388*49cdfc7eSAndroid Build Coastguard Worker /***************************/
389*49cdfc7eSAndroid Build Coastguard Worker /*  string:                */
390*49cdfc7eSAndroid Build Coastguard Worker /*  the directory path     */
391*49cdfc7eSAndroid Build Coastguard Worker /*  string below which a   */
392*49cdfc7eSAndroid Build Coastguard Worker /*  tree is generated      */
393*49cdfc7eSAndroid Build Coastguard Worker /*                         */
394*49cdfc7eSAndroid Build Coastguard Worker /***************************/
395*49cdfc7eSAndroid Build Coastguard Worker 
396*49cdfc7eSAndroid Build Coastguard Worker /***************************/
397*49cdfc7eSAndroid Build Coastguard Worker /* level:                  */
398*49cdfc7eSAndroid Build Coastguard Worker /* the tree depth variable */
399*49cdfc7eSAndroid Build Coastguard Worker /*                         */
400*49cdfc7eSAndroid Build Coastguard Worker /***************************/
401*49cdfc7eSAndroid Build Coastguard Worker {
402*49cdfc7eSAndroid Build Coastguard Worker 	int switch_flag;
403*49cdfc7eSAndroid Build Coastguard Worker 	int ret_val = 0;
404*49cdfc7eSAndroid Build Coastguard Worker 	int new_ret_val, len, ret_len;
405*49cdfc7eSAndroid Build Coastguard Worker 	char new_string[PATH_STRING_LENGTH + 1];
406*49cdfc7eSAndroid Build Coastguard Worker 	int new_level;
407*49cdfc7eSAndroid Build Coastguard Worker 	int i, j;		/* iteration counters */
408*49cdfc7eSAndroid Build Coastguard Worker 	int snp_ret;
409*49cdfc7eSAndroid Build Coastguard Worker 
410*49cdfc7eSAndroid Build Coastguard Worker 	switch_flag = level & TRUE;
411*49cdfc7eSAndroid Build Coastguard Worker 	if (strlen(string) >= MAX_PATH_STRING_LENGTH) {
412*49cdfc7eSAndroid Build Coastguard Worker 
413*49cdfc7eSAndroid Build Coastguard Worker 		/********************************/
414*49cdfc7eSAndroid Build Coastguard Worker 		/*                              */
415*49cdfc7eSAndroid Build Coastguard Worker 		/*   Maximum path name length   */
416*49cdfc7eSAndroid Build Coastguard Worker 		/*          reached             */
417*49cdfc7eSAndroid Build Coastguard Worker 		/*                              */
418*49cdfc7eSAndroid Build Coastguard Worker 		/********************************/
419*49cdfc7eSAndroid Build Coastguard Worker 
420*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "\nMaximum path_name length reached\n");
421*49cdfc7eSAndroid Build Coastguard Worker 		return (-1);
422*49cdfc7eSAndroid Build Coastguard Worker 	} else if (level < max_depth) {
423*49cdfc7eSAndroid Build Coastguard Worker 		for (i = 0; i <= max_breadth; i++) {
424*49cdfc7eSAndroid Build Coastguard Worker 			get_next_name();
425*49cdfc7eSAndroid Build Coastguard Worker 			snp_ret = snprintf(new_string, sizeof(new_string),
426*49cdfc7eSAndroid Build Coastguard Worker 				"%s/%s", string, name);
427*49cdfc7eSAndroid Build Coastguard Worker 			if (snp_ret < 0 || snp_ret >= sizeof(new_string)) {
428*49cdfc7eSAndroid Build Coastguard Worker 				tst_resm(TBROK, "snprintf(new_string,..) "
429*49cdfc7eSAndroid Build Coastguard Worker 					"returned %d", snp_ret);
430*49cdfc7eSAndroid Build Coastguard Worker 				exit(-1);
431*49cdfc7eSAndroid Build Coastguard Worker 			}
432*49cdfc7eSAndroid Build Coastguard Worker 
433*49cdfc7eSAndroid Build Coastguard Worker 			/****************************************/
434*49cdfc7eSAndroid Build Coastguard Worker 			/*                                      */
435*49cdfc7eSAndroid Build Coastguard Worker 			/*    switch between creating files     */
436*49cdfc7eSAndroid Build Coastguard Worker 			/*    and making directories            */
437*49cdfc7eSAndroid Build Coastguard Worker 			/*                                      */
438*49cdfc7eSAndroid Build Coastguard Worker 			/****************************************/
439*49cdfc7eSAndroid Build Coastguard Worker 
440*49cdfc7eSAndroid Build Coastguard Worker 			if (switch_flag) {
441*49cdfc7eSAndroid Build Coastguard Worker 				switch_flag = FALSE;
442*49cdfc7eSAndroid Build Coastguard Worker 
443*49cdfc7eSAndroid Build Coastguard Worker 				/****************************************/
444*49cdfc7eSAndroid Build Coastguard Worker 				/*                                      */
445*49cdfc7eSAndroid Build Coastguard Worker 				/*        create a new file             */
446*49cdfc7eSAndroid Build Coastguard Worker 				/*                                      */
447*49cdfc7eSAndroid Build Coastguard Worker 				/****************************************/
448*49cdfc7eSAndroid Build Coastguard Worker 
449*49cdfc7eSAndroid Build Coastguard Worker 				file_id = creat(new_string, FILE_MODE);
450*49cdfc7eSAndroid Build Coastguard Worker 				if (file_id == -1) {
451*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(temp,
452*49cdfc7eSAndroid Build Coastguard Worker 						"\nImpossible to create file %s, errno=%d\n",
453*49cdfc7eSAndroid Build Coastguard Worker 						new_string, errno);
454*49cdfc7eSAndroid Build Coastguard Worker 					return (-2);
455*49cdfc7eSAndroid Build Coastguard Worker 				}
456*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
457*49cdfc7eSAndroid Build Coastguard Worker 				tst_resm(TINFO, "%d  %s F\n", level,
458*49cdfc7eSAndroid Build Coastguard Worker 					 new_string);
459*49cdfc7eSAndroid Build Coastguard Worker #endif
460*49cdfc7eSAndroid Build Coastguard Worker 
461*49cdfc7eSAndroid Build Coastguard Worker 				/****************************************/
462*49cdfc7eSAndroid Build Coastguard Worker 				/*                                      */
463*49cdfc7eSAndroid Build Coastguard Worker 				/*            write to it               */
464*49cdfc7eSAndroid Build Coastguard Worker 				/*                                      */
465*49cdfc7eSAndroid Build Coastguard Worker 				/****************************************/
466*49cdfc7eSAndroid Build Coastguard Worker 
467*49cdfc7eSAndroid Build Coastguard Worker 				len = strlen(new_string);
468*49cdfc7eSAndroid Build Coastguard Worker 				for (j = 1; j <= file_length; j++) {
469*49cdfc7eSAndroid Build Coastguard Worker 					ret_len =
470*49cdfc7eSAndroid Build Coastguard Worker 					    write(file_id, new_string, len);
471*49cdfc7eSAndroid Build Coastguard Worker 					if (ret_len != len) {
472*49cdfc7eSAndroid Build Coastguard Worker 						fprintf(temp,
473*49cdfc7eSAndroid Build Coastguard Worker 							"\nUnsuccessful write to file %s, errno=%d\n",
474*49cdfc7eSAndroid Build Coastguard Worker 							new_string, errno);
475*49cdfc7eSAndroid Build Coastguard Worker 						return (-3);
476*49cdfc7eSAndroid Build Coastguard Worker 					}
477*49cdfc7eSAndroid Build Coastguard Worker 				}
478*49cdfc7eSAndroid Build Coastguard Worker 				close(file_id);
479*49cdfc7eSAndroid Build Coastguard Worker 
480*49cdfc7eSAndroid Build Coastguard Worker 				/****************************************/
481*49cdfc7eSAndroid Build Coastguard Worker 				/*                                      */
482*49cdfc7eSAndroid Build Coastguard Worker 				/*   and store its name in path_list    */
483*49cdfc7eSAndroid Build Coastguard Worker 				/*                                      */
484*49cdfc7eSAndroid Build Coastguard Worker 				/****************************************/
485*49cdfc7eSAndroid Build Coastguard Worker 
486*49cdfc7eSAndroid Build Coastguard Worker 				strcpy(write_string, new_string);
487*49cdfc7eSAndroid Build Coastguard Worker 				len = strlen(write_string);
488*49cdfc7eSAndroid Build Coastguard Worker 				write_string[len++] = 'F';
489*49cdfc7eSAndroid Build Coastguard Worker 				write_string[len] = '\0';
490*49cdfc7eSAndroid Build Coastguard Worker 				escrivez(write_string);
491*49cdfc7eSAndroid Build Coastguard Worker 			} else {
492*49cdfc7eSAndroid Build Coastguard Worker 				switch_flag = TRUE;
493*49cdfc7eSAndroid Build Coastguard Worker 
494*49cdfc7eSAndroid Build Coastguard Worker 				/****************************************/
495*49cdfc7eSAndroid Build Coastguard Worker 				/*                                      */
496*49cdfc7eSAndroid Build Coastguard Worker 				/*       or make a directory            */
497*49cdfc7eSAndroid Build Coastguard Worker 				/*                                      */
498*49cdfc7eSAndroid Build Coastguard Worker 				/*  (mknod can only be called when in   */
499*49cdfc7eSAndroid Build Coastguard Worker 				/*   super user mode)                   */
500*49cdfc7eSAndroid Build Coastguard Worker 				/*                                      */
501*49cdfc7eSAndroid Build Coastguard Worker 				/****************************************/
502*49cdfc7eSAndroid Build Coastguard Worker 
503*49cdfc7eSAndroid Build Coastguard Worker 				ret_val = mkdir(new_string, DIRECTORY_MODE);
504*49cdfc7eSAndroid Build Coastguard Worker 
505*49cdfc7eSAndroid Build Coastguard Worker 				if (ret_val != 0) {
506*49cdfc7eSAndroid Build Coastguard Worker 					fprintf(temp,
507*49cdfc7eSAndroid Build Coastguard Worker 						"\nImpossible to create directory %s, errno=%d\n",
508*49cdfc7eSAndroid Build Coastguard Worker 						new_string, errno);
509*49cdfc7eSAndroid Build Coastguard Worker 					return (-5);
510*49cdfc7eSAndroid Build Coastguard Worker 				}
511*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
512*49cdfc7eSAndroid Build Coastguard Worker 				tst_resm(TINFO, "%d  %s D\n", level,
513*49cdfc7eSAndroid Build Coastguard Worker 					 new_string);
514*49cdfc7eSAndroid Build Coastguard Worker #endif
515*49cdfc7eSAndroid Build Coastguard Worker 
516*49cdfc7eSAndroid Build Coastguard Worker 				/****************************************/
517*49cdfc7eSAndroid Build Coastguard Worker 				/*                                      */
518*49cdfc7eSAndroid Build Coastguard Worker 				/*     store its name in path_list      */
519*49cdfc7eSAndroid Build Coastguard Worker 				/*                                      */
520*49cdfc7eSAndroid Build Coastguard Worker 				/****************************************/
521*49cdfc7eSAndroid Build Coastguard Worker 
522*49cdfc7eSAndroid Build Coastguard Worker 				strcpy(write_string, new_string);
523*49cdfc7eSAndroid Build Coastguard Worker 				len = strlen(write_string);
524*49cdfc7eSAndroid Build Coastguard Worker 				write_string[len++] = 'D';
525*49cdfc7eSAndroid Build Coastguard Worker 				write_string[len] = '\0';
526*49cdfc7eSAndroid Build Coastguard Worker 				escrivez(write_string);
527*49cdfc7eSAndroid Build Coastguard Worker 
528*49cdfc7eSAndroid Build Coastguard Worker 				/****************************************/
529*49cdfc7eSAndroid Build Coastguard Worker 				/*                                      */
530*49cdfc7eSAndroid Build Coastguard Worker 				/*      and generate a new level        */
531*49cdfc7eSAndroid Build Coastguard Worker 				/*                                      */
532*49cdfc7eSAndroid Build Coastguard Worker 				/****************************************/
533*49cdfc7eSAndroid Build Coastguard Worker 
534*49cdfc7eSAndroid Build Coastguard Worker 				new_level = level + 1;
535*49cdfc7eSAndroid Build Coastguard Worker 				new_ret_val = generate(new_string, new_level);
536*49cdfc7eSAndroid Build Coastguard Worker 				if (new_ret_val < ret_val)
537*49cdfc7eSAndroid Build Coastguard Worker 					ret_val = new_ret_val;
538*49cdfc7eSAndroid Build Coastguard Worker 			}
539*49cdfc7eSAndroid Build Coastguard Worker 		}
540*49cdfc7eSAndroid Build Coastguard Worker 
541*49cdfc7eSAndroid Build Coastguard Worker 		/********************************/
542*49cdfc7eSAndroid Build Coastguard Worker 		/*                              */
543*49cdfc7eSAndroid Build Coastguard Worker 		/*    Maximum breadth reached   */
544*49cdfc7eSAndroid Build Coastguard Worker 		/*                              */
545*49cdfc7eSAndroid Build Coastguard Worker 		/********************************/
546*49cdfc7eSAndroid Build Coastguard Worker 
547*49cdfc7eSAndroid Build Coastguard Worker 		return (ret_val);
548*49cdfc7eSAndroid Build Coastguard Worker 	} else
549*49cdfc7eSAndroid Build Coastguard Worker 		    /********************************/
550*49cdfc7eSAndroid Build Coastguard Worker 		/*                             */
551*49cdfc7eSAndroid Build Coastguard Worker 		/*    Maximum depth reached    */
552*49cdfc7eSAndroid Build Coastguard Worker 		/*                             */
553*49cdfc7eSAndroid Build Coastguard Worker  /********************************/
554*49cdfc7eSAndroid Build Coastguard Worker 		return 0;
555*49cdfc7eSAndroid Build Coastguard Worker }
556*49cdfc7eSAndroid Build Coastguard Worker 
check(void)557*49cdfc7eSAndroid Build Coastguard Worker int check(void)
558*49cdfc7eSAndroid Build Coastguard Worker 
559*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
560*49cdfc7eSAndroid Build Coastguard Worker /*					*/
561*49cdfc7eSAndroid Build Coastguard Worker /*   check for file and directory	*/
562*49cdfc7eSAndroid Build Coastguard Worker /*   correctness by reading records	*/
563*49cdfc7eSAndroid Build Coastguard Worker /*   from the path_list and attempting	*/
564*49cdfc7eSAndroid Build Coastguard Worker /*   to determine if the corresponding	*/
565*49cdfc7eSAndroid Build Coastguard Worker /*   files or directories are as 	*/
566*49cdfc7eSAndroid Build Coastguard Worker /*   created 				*/
567*49cdfc7eSAndroid Build Coastguard Worker /*					*/
568*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
569*49cdfc7eSAndroid Build Coastguard Worker {
570*49cdfc7eSAndroid Build Coastguard Worker 	int len, path_mode, val, ret_len, j;
571*49cdfc7eSAndroid Build Coastguard Worker 
572*49cdfc7eSAndroid Build Coastguard Worker 	for (;;) {
573*49cdfc7eSAndroid Build Coastguard Worker 
574*49cdfc7eSAndroid Build Coastguard Worker 		/****************************************/
575*49cdfc7eSAndroid Build Coastguard Worker 		/*                                      */
576*49cdfc7eSAndroid Build Coastguard Worker 		/*  read a path string from path_list   */
577*49cdfc7eSAndroid Build Coastguard Worker 		/*                                      */
578*49cdfc7eSAndroid Build Coastguard Worker 		/****************************************/
579*49cdfc7eSAndroid Build Coastguard Worker 
580*49cdfc7eSAndroid Build Coastguard Worker 		if (fscanf(list_stream, "%s", path_string) == EOF) {
581*49cdfc7eSAndroid Build Coastguard Worker 
582*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
583*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TINFO, "\nEnd of path_list file reached \n");
584*49cdfc7eSAndroid Build Coastguard Worker #endif
585*49cdfc7eSAndroid Build Coastguard Worker 
586*49cdfc7eSAndroid Build Coastguard Worker 			return 0;
587*49cdfc7eSAndroid Build Coastguard Worker 		}
588*49cdfc7eSAndroid Build Coastguard Worker #ifdef DEBUG
589*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "%s\n", path_string);
590*49cdfc7eSAndroid Build Coastguard Worker #endif
591*49cdfc7eSAndroid Build Coastguard Worker 
592*49cdfc7eSAndroid Build Coastguard Worker 		len = strlen(path_string);
593*49cdfc7eSAndroid Build Coastguard Worker 		len--;
594*49cdfc7eSAndroid Build Coastguard Worker 		if (path_string[len] == 'F') {
595*49cdfc7eSAndroid Build Coastguard Worker 
596*49cdfc7eSAndroid Build Coastguard Worker 		/********************************/
597*49cdfc7eSAndroid Build Coastguard Worker 			/*                              */
598*49cdfc7eSAndroid Build Coastguard Worker 			/*    this should be a file     */
599*49cdfc7eSAndroid Build Coastguard Worker 			/*                              */
600*49cdfc7eSAndroid Build Coastguard Worker 		/********************************/
601*49cdfc7eSAndroid Build Coastguard Worker 
602*49cdfc7eSAndroid Build Coastguard Worker 			path_string[len] = '\0';
603*49cdfc7eSAndroid Build Coastguard Worker 			file_id = open(path_string, READ);
604*49cdfc7eSAndroid Build Coastguard Worker 			if (file_id <= 0) {
605*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(temp,
606*49cdfc7eSAndroid Build Coastguard Worker 					"\nImpossible to open file %s, errno=%d\n",
607*49cdfc7eSAndroid Build Coastguard Worker 					path_string, errno);
608*49cdfc7eSAndroid Build Coastguard Worker 				return (-1);
609*49cdfc7eSAndroid Build Coastguard Worker 			}
610*49cdfc7eSAndroid Build Coastguard Worker 
611*49cdfc7eSAndroid Build Coastguard Worker 			else {
612*49cdfc7eSAndroid Build Coastguard Worker 				/********************************/
613*49cdfc7eSAndroid Build Coastguard Worker 				/*                              */
614*49cdfc7eSAndroid Build Coastguard Worker 				/*    check its contents        */
615*49cdfc7eSAndroid Build Coastguard Worker 				/*                              */
616*49cdfc7eSAndroid Build Coastguard Worker 				/********************************/
617*49cdfc7eSAndroid Build Coastguard Worker 
618*49cdfc7eSAndroid Build Coastguard Worker 				ret_len = 0;
619*49cdfc7eSAndroid Build Coastguard Worker 				len = strlen(path_string);
620*49cdfc7eSAndroid Build Coastguard Worker 				for (j = 1; j <= file_length; j++) {
621*49cdfc7eSAndroid Build Coastguard Worker 					ret_len =
622*49cdfc7eSAndroid Build Coastguard Worker 					    read(file_id, read_string, len);
623*49cdfc7eSAndroid Build Coastguard Worker 					if (len != ret_len) {
624*49cdfc7eSAndroid Build Coastguard Worker 						fprintf(temp,
625*49cdfc7eSAndroid Build Coastguard Worker 							"\nFile read error for file %s, errno=%d\n",
626*49cdfc7eSAndroid Build Coastguard Worker 							path_string, errno);
627*49cdfc7eSAndroid Build Coastguard Worker 						return (-3);
628*49cdfc7eSAndroid Build Coastguard Worker 					}
629*49cdfc7eSAndroid Build Coastguard Worker 					read_string[len] = '\0';
630*49cdfc7eSAndroid Build Coastguard Worker 					val = strcmp(read_string, path_string);
631*49cdfc7eSAndroid Build Coastguard Worker 					if (val != 0) {
632*49cdfc7eSAndroid Build Coastguard Worker 						fprintf(temp,
633*49cdfc7eSAndroid Build Coastguard Worker 							"\nContents of file %s are different than expected: %s\n",
634*49cdfc7eSAndroid Build Coastguard Worker 							path_string,
635*49cdfc7eSAndroid Build Coastguard Worker 							read_string);
636*49cdfc7eSAndroid Build Coastguard Worker 						return (-4);
637*49cdfc7eSAndroid Build Coastguard Worker 					}
638*49cdfc7eSAndroid Build Coastguard Worker 				}
639*49cdfc7eSAndroid Build Coastguard Worker 				close(file_id);
640*49cdfc7eSAndroid Build Coastguard Worker 			}	/* else for */
641*49cdfc7eSAndroid Build Coastguard Worker 			if (ret_len <= 0) {
642*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(temp,
643*49cdfc7eSAndroid Build Coastguard Worker 					"\nImpossible to read file %s, errno=%d\n",
644*49cdfc7eSAndroid Build Coastguard Worker 					path_string, errno);
645*49cdfc7eSAndroid Build Coastguard Worker 				return (-2);
646*49cdfc7eSAndroid Build Coastguard Worker 			}
647*49cdfc7eSAndroid Build Coastguard Worker 		} else {
648*49cdfc7eSAndroid Build Coastguard Worker 
649*49cdfc7eSAndroid Build Coastguard Worker 		/********************************/
650*49cdfc7eSAndroid Build Coastguard Worker 			/*                              */
651*49cdfc7eSAndroid Build Coastguard Worker 			/*  otherwise..........         */
652*49cdfc7eSAndroid Build Coastguard Worker 			/*  it should be a directory    */
653*49cdfc7eSAndroid Build Coastguard Worker 			/*                              */
654*49cdfc7eSAndroid Build Coastguard Worker 		/********************************/
655*49cdfc7eSAndroid Build Coastguard Worker 
656*49cdfc7eSAndroid Build Coastguard Worker 			path_string[len] = '\0';
657*49cdfc7eSAndroid Build Coastguard Worker 			path_mode = mode(path_string);
658*49cdfc7eSAndroid Build Coastguard Worker 			if (path_mode == -1) {
659*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(temp,
660*49cdfc7eSAndroid Build Coastguard Worker 					"\nPreviously created directory path %s was not open\n",
661*49cdfc7eSAndroid Build Coastguard Worker 					path_string);
662*49cdfc7eSAndroid Build Coastguard Worker 				return (-4);
663*49cdfc7eSAndroid Build Coastguard Worker 			}
664*49cdfc7eSAndroid Build Coastguard Worker 			if ((040000 & path_mode) != 040000) {
665*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(temp,
666*49cdfc7eSAndroid Build Coastguard Worker 					"\nPath %s was not recognized to be a directory\n",
667*49cdfc7eSAndroid Build Coastguard Worker 					path_string);
668*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(temp, "Its mode is %o\n", path_mode);
669*49cdfc7eSAndroid Build Coastguard Worker 				return (-5);
670*49cdfc7eSAndroid Build Coastguard Worker 			}
671*49cdfc7eSAndroid Build Coastguard Worker 		}
672*49cdfc7eSAndroid Build Coastguard Worker 	}			/* while */
673*49cdfc7eSAndroid Build Coastguard Worker }
674*49cdfc7eSAndroid Build Coastguard Worker 
get_next_name(void)675*49cdfc7eSAndroid Build Coastguard Worker int get_next_name(void)
676*49cdfc7eSAndroid Build Coastguard Worker 
677*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
678*49cdfc7eSAndroid Build Coastguard Worker /*					*/
679*49cdfc7eSAndroid Build Coastguard Worker /*   get the next---in a dictionary	*/
680*49cdfc7eSAndroid Build Coastguard Worker /*   sense---file or directory name	*/
681*49cdfc7eSAndroid Build Coastguard Worker /*					*/
682*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
683*49cdfc7eSAndroid Build Coastguard Worker {
684*49cdfc7eSAndroid Build Coastguard Worker 	static int k;
685*49cdfc7eSAndroid Build Coastguard Worker 	int i;
686*49cdfc7eSAndroid Build Coastguard Worker 	int last_position;
687*49cdfc7eSAndroid Build Coastguard Worker 
688*49cdfc7eSAndroid Build Coastguard Worker 	last_position = NAME_LENGTH - 1;
689*49cdfc7eSAndroid Build Coastguard Worker 	if (k == 0) {
690*49cdfc7eSAndroid Build Coastguard Worker 
691*49cdfc7eSAndroid Build Coastguard Worker 		/************************/
692*49cdfc7eSAndroid Build Coastguard Worker 		/*                      */
693*49cdfc7eSAndroid Build Coastguard Worker 		/*   initialize name    */
694*49cdfc7eSAndroid Build Coastguard Worker 		/*                      */
695*49cdfc7eSAndroid Build Coastguard Worker 		/************************/
696*49cdfc7eSAndroid Build Coastguard Worker 
697*49cdfc7eSAndroid Build Coastguard Worker 		for (i = 0; i < NAME_LENGTH; i++)
698*49cdfc7eSAndroid Build Coastguard Worker 			name[i] = 'a';
699*49cdfc7eSAndroid Build Coastguard Worker 		name[NAME_LENGTH] = '\0';
700*49cdfc7eSAndroid Build Coastguard Worker 		k++;
701*49cdfc7eSAndroid Build Coastguard Worker 	}
702*49cdfc7eSAndroid Build Coastguard Worker 					    /********************************/
703*49cdfc7eSAndroid Build Coastguard Worker 	/*                              */
704*49cdfc7eSAndroid Build Coastguard Worker 	else
705*49cdfc7eSAndroid Build Coastguard Worker 		increment_name(last_position);	/* i.e., beginning at the last  */
706*49cdfc7eSAndroid Build Coastguard Worker 	/* position                     */
707*49cdfc7eSAndroid Build Coastguard Worker 	/*                              */
708*49cdfc7eSAndroid Build Coastguard Worker 					    /********************************/
709*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
710*49cdfc7eSAndroid Build Coastguard Worker }
711*49cdfc7eSAndroid Build Coastguard Worker 
increment_name(int position)712*49cdfc7eSAndroid Build Coastguard Worker int increment_name(int position)
713*49cdfc7eSAndroid Build Coastguard Worker 
714*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
715*49cdfc7eSAndroid Build Coastguard Worker /*					*/
716*49cdfc7eSAndroid Build Coastguard Worker /*  recursively revise the letters in 	*/
717*49cdfc7eSAndroid Build Coastguard Worker /*  a name to get the lexiographically	*/
718*49cdfc7eSAndroid Build Coastguard Worker /*  next name				*/
719*49cdfc7eSAndroid Build Coastguard Worker /*					*/
720*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
721*49cdfc7eSAndroid Build Coastguard Worker {
722*49cdfc7eSAndroid Build Coastguard Worker 	int next_position;
723*49cdfc7eSAndroid Build Coastguard Worker 
724*49cdfc7eSAndroid Build Coastguard Worker 	if (name[position] == 'z')
725*49cdfc7eSAndroid Build Coastguard Worker 		if (position == 0) {
726*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp,
727*49cdfc7eSAndroid Build Coastguard Worker 				"ERROR: There are no more available names\n");
728*49cdfc7eSAndroid Build Coastguard Worker 			exit(-1);
729*49cdfc7eSAndroid Build Coastguard Worker 		} else {
730*49cdfc7eSAndroid Build Coastguard Worker 			name[position] = 'a';	       /**********************/
731*49cdfc7eSAndroid Build Coastguard Worker 			next_position = --position;	/*                    */
732*49cdfc7eSAndroid Build Coastguard Worker 			increment_name(next_position);	/*  increment the     */
733*49cdfc7eSAndroid Build Coastguard Worker 			/*  previous letter   */
734*49cdfc7eSAndroid Build Coastguard Worker 			/*                    */
735*49cdfc7eSAndroid Build Coastguard Worker 						       /**********************/
736*49cdfc7eSAndroid Build Coastguard Worker 		}
737*49cdfc7eSAndroid Build Coastguard Worker 				  /*********************************/
738*49cdfc7eSAndroid Build Coastguard Worker 	/*                               */
739*49cdfc7eSAndroid Build Coastguard Worker 	else
740*49cdfc7eSAndroid Build Coastguard Worker 		name[position]++;	/* otherwise, increment this one */
741*49cdfc7eSAndroid Build Coastguard Worker 	return 0;		/*                               */
742*49cdfc7eSAndroid Build Coastguard Worker 				  /*********************************/
743*49cdfc7eSAndroid Build Coastguard Worker }
744*49cdfc7eSAndroid Build Coastguard Worker 
mode(char * path_string)745*49cdfc7eSAndroid Build Coastguard Worker int mode(char *path_string)
746*49cdfc7eSAndroid Build Coastguard Worker 
747*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
748*49cdfc7eSAndroid Build Coastguard Worker /*					*/
749*49cdfc7eSAndroid Build Coastguard Worker /*   determine and return the mode of	*/
750*49cdfc7eSAndroid Build Coastguard Worker /*   the file named by path_string 	*/
751*49cdfc7eSAndroid Build Coastguard Worker /*					*/
752*49cdfc7eSAndroid Build Coastguard Worker /****************************************/
753*49cdfc7eSAndroid Build Coastguard Worker {
754*49cdfc7eSAndroid Build Coastguard Worker 	struct stat buf;
755*49cdfc7eSAndroid Build Coastguard Worker 	int ret_val, mod;
756*49cdfc7eSAndroid Build Coastguard Worker 
757*49cdfc7eSAndroid Build Coastguard Worker 	ret_val = stat(path_string, &buf);
758*49cdfc7eSAndroid Build Coastguard Worker 	if (ret_val == -1)
759*49cdfc7eSAndroid Build Coastguard Worker 		return (-1);
760*49cdfc7eSAndroid Build Coastguard Worker 	else {
761*49cdfc7eSAndroid Build Coastguard Worker 		mod = buf.st_mode;
762*49cdfc7eSAndroid Build Coastguard Worker 		return (mod);
763*49cdfc7eSAndroid Build Coastguard Worker 	}
764*49cdfc7eSAndroid Build Coastguard Worker }
765*49cdfc7eSAndroid Build Coastguard Worker 
escrivez(char * string)766*49cdfc7eSAndroid Build Coastguard Worker int escrivez(char *string)
767*49cdfc7eSAndroid Build Coastguard Worker {
768*49cdfc7eSAndroid Build Coastguard Worker 	char write_string[PATH_STRING_LENGTH + 1];
769*49cdfc7eSAndroid Build Coastguard Worker 	int len, ret_len;
770*49cdfc7eSAndroid Build Coastguard Worker 
771*49cdfc7eSAndroid Build Coastguard Worker 	strcpy(write_string, string);
772*49cdfc7eSAndroid Build Coastguard Worker 	len = strlen(write_string);
773*49cdfc7eSAndroid Build Coastguard Worker 	write_string[len] = '\n';
774*49cdfc7eSAndroid Build Coastguard Worker 	len++;
775*49cdfc7eSAndroid Build Coastguard Worker 	ret_len = write(list_id, write_string, len);
776*49cdfc7eSAndroid Build Coastguard Worker 	if (len != ret_len) {
777*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp,
778*49cdfc7eSAndroid Build Coastguard Worker 			"A string of deviant length %d written to path_list, errno=%d\n",
779*49cdfc7eSAndroid Build Coastguard Worker 			ret_len, errno);
780*49cdfc7eSAndroid Build Coastguard Worker 		exit(-2);
781*49cdfc7eSAndroid Build Coastguard Worker 	}
782*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
783*49cdfc7eSAndroid Build Coastguard Worker }
784*49cdfc7eSAndroid Build Coastguard Worker 
term(void)785*49cdfc7eSAndroid Build Coastguard Worker int term(void)
786*49cdfc7eSAndroid Build Coastguard Worker {
787*49cdfc7eSAndroid Build Coastguard Worker 	int status;
788*49cdfc7eSAndroid Build Coastguard Worker 
789*49cdfc7eSAndroid Build Coastguard Worker 	fflush(temp);
790*49cdfc7eSAndroid Build Coastguard Worker 	if (parent_pid == getpid()) {
791*49cdfc7eSAndroid Build Coastguard Worker 		massmurder();	/* kill kids */
792*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "\term1 - SIGTERM received by parent.\n");
793*49cdfc7eSAndroid Build Coastguard Worker 		fflush(temp);
794*49cdfc7eSAndroid Build Coastguard Worker 	} else {
795*49cdfc7eSAndroid Build Coastguard Worker 		fprintf(temp, "\tchild - got SIGTERM signal.\n");
796*49cdfc7eSAndroid Build Coastguard Worker 		if (list_stream != NULL)
797*49cdfc7eSAndroid Build Coastguard Worker 			fclose(list_stream);
798*49cdfc7eSAndroid Build Coastguard Worker 		close(list_id);
799*49cdfc7eSAndroid Build Coastguard Worker 		close(file_id);
800*49cdfc7eSAndroid Build Coastguard Worker 		status = system(remove_string);
801*49cdfc7eSAndroid Build Coastguard Worker 		if (status) {
802*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp, "Caution - ``%s'' returned status %d\n",
803*49cdfc7eSAndroid Build Coastguard Worker 				remove_string, status);
804*49cdfc7eSAndroid Build Coastguard Worker 		}
805*49cdfc7eSAndroid Build Coastguard Worker 		exit(0);
806*49cdfc7eSAndroid Build Coastguard Worker 	}
807*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
808*49cdfc7eSAndroid Build Coastguard Worker }
809*49cdfc7eSAndroid Build Coastguard Worker 
massmurder(void)810*49cdfc7eSAndroid Build Coastguard Worker int massmurder(void)
811*49cdfc7eSAndroid Build Coastguard Worker {
812*49cdfc7eSAndroid Build Coastguard Worker 	int i;
813*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < MAXCHILD; i++) {
814*49cdfc7eSAndroid Build Coastguard Worker 		if (allchild[i]) {
815*49cdfc7eSAndroid Build Coastguard Worker 			kill(allchild[i], SIGTERM);
816*49cdfc7eSAndroid Build Coastguard Worker 		}
817*49cdfc7eSAndroid Build Coastguard Worker 	}
818*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
819*49cdfc7eSAndroid Build Coastguard Worker }
820*49cdfc7eSAndroid Build Coastguard Worker 
821*49cdfc7eSAndroid Build Coastguard Worker /** LTP Port **/
822*49cdfc7eSAndroid Build Coastguard Worker /*
823*49cdfc7eSAndroid Build Coastguard Worker  * setup
824*49cdfc7eSAndroid Build Coastguard Worker  *
825*49cdfc7eSAndroid Build Coastguard Worker  * Do set up - here its a dummy function
826*49cdfc7eSAndroid Build Coastguard Worker  */
setup(void)827*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
828*49cdfc7eSAndroid Build Coastguard Worker {
829*49cdfc7eSAndroid Build Coastguard Worker 	tst_tmpdir();
830*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
831*49cdfc7eSAndroid Build Coastguard Worker }
832*49cdfc7eSAndroid Build Coastguard Worker 
833*49cdfc7eSAndroid Build Coastguard Worker /*
834*49cdfc7eSAndroid Build Coastguard Worker  * fail_exit()
835*49cdfc7eSAndroid Build Coastguard Worker  *
836*49cdfc7eSAndroid Build Coastguard Worker  * Exit on failure
837*49cdfc7eSAndroid Build Coastguard Worker  */
fail_exit(void)838*49cdfc7eSAndroid Build Coastguard Worker void fail_exit(void)
839*49cdfc7eSAndroid Build Coastguard Worker {
840*49cdfc7eSAndroid Build Coastguard Worker 	tst_brkm(TFAIL, tst_rmdir, "Test failed");
841*49cdfc7eSAndroid Build Coastguard Worker }
842*49cdfc7eSAndroid Build Coastguard Worker 
843*49cdfc7eSAndroid Build Coastguard Worker /*
844*49cdfc7eSAndroid Build Coastguard Worker  *
845*49cdfc7eSAndroid Build Coastguard Worker  * Function: anyfail()
846*49cdfc7eSAndroid Build Coastguard Worker  *
847*49cdfc7eSAndroid Build Coastguard Worker  * Description: Exit a test.
848*49cdfc7eSAndroid Build Coastguard Worker  */
anyfail(void)849*49cdfc7eSAndroid Build Coastguard Worker void anyfail(void)
850*49cdfc7eSAndroid Build Coastguard Worker {
851*49cdfc7eSAndroid Build Coastguard Worker 	(local_flag == FAILED) ? tst_resm(TFAIL, "Test failed")
852*49cdfc7eSAndroid Build Coastguard Worker 	    : tst_resm(TPASS, "Test passed");
853*49cdfc7eSAndroid Build Coastguard Worker 	tst_rmdir();
854*49cdfc7eSAndroid Build Coastguard Worker 	tst_exit();
855*49cdfc7eSAndroid Build Coastguard Worker }
856*49cdfc7eSAndroid Build Coastguard Worker 
857*49cdfc7eSAndroid Build Coastguard Worker /*
858*49cdfc7eSAndroid Build Coastguard Worker  * ok_exit
859*49cdfc7eSAndroid Build Coastguard Worker  *
860*49cdfc7eSAndroid Build Coastguard Worker  * Calling block passed the test
861*49cdfc7eSAndroid Build Coastguard Worker  */
ok_exit(void)862*49cdfc7eSAndroid Build Coastguard Worker void ok_exit(void)
863*49cdfc7eSAndroid Build Coastguard Worker {
864*49cdfc7eSAndroid Build Coastguard Worker 	local_flag = PASSED;
865*49cdfc7eSAndroid Build Coastguard Worker 	return;
866*49cdfc7eSAndroid Build Coastguard Worker }
867*49cdfc7eSAndroid Build Coastguard Worker 
868*49cdfc7eSAndroid Build Coastguard Worker /*
869*49cdfc7eSAndroid Build Coastguard Worker  * forkfail()
870*49cdfc7eSAndroid Build Coastguard Worker  *
871*49cdfc7eSAndroid Build Coastguard Worker  * exit on failure
872*49cdfc7eSAndroid Build Coastguard Worker  */
forkfail(void)873*49cdfc7eSAndroid Build Coastguard Worker void forkfail(void)
874*49cdfc7eSAndroid Build Coastguard Worker {
875*49cdfc7eSAndroid Build Coastguard Worker 	tst_brkm(TBROK, tst_rmdir, "Reason: %s", strerror(errno));
876*49cdfc7eSAndroid Build Coastguard Worker }
877*49cdfc7eSAndroid Build Coastguard Worker 
878*49cdfc7eSAndroid Build Coastguard Worker /*
879*49cdfc7eSAndroid Build Coastguard Worker  * Function: terror
880*49cdfc7eSAndroid Build Coastguard Worker  *
881*49cdfc7eSAndroid Build Coastguard Worker  * Description: prints error message this may not be because some part of the
882*49cdfc7eSAndroid Build Coastguard Worker  *              test case failed, for example fork() failed. We will log this
883*49cdfc7eSAndroid Build Coastguard Worker  *              failure as TBROK instead of TFAIL.
884*49cdfc7eSAndroid Build Coastguard Worker  */
terror(char * message)885*49cdfc7eSAndroid Build Coastguard Worker void terror(char *message)
886*49cdfc7eSAndroid Build Coastguard Worker {
887*49cdfc7eSAndroid Build Coastguard Worker 	tst_resm(TBROK, "Reason: %s:%s", message, strerror(errno));
888*49cdfc7eSAndroid Build Coastguard Worker 	return;
889*49cdfc7eSAndroid Build Coastguard Worker }
890*49cdfc7eSAndroid Build Coastguard Worker 
891*49cdfc7eSAndroid Build Coastguard Worker /*
892*49cdfc7eSAndroid Build Coastguard Worker  * instress
893*49cdfc7eSAndroid Build Coastguard Worker  *
894*49cdfc7eSAndroid Build Coastguard Worker  * Assume that we are always running under stress, so this function will
895*49cdfc7eSAndroid Build Coastguard Worker  * return > 0 value always.
896*49cdfc7eSAndroid Build Coastguard Worker  */
instress(void)897*49cdfc7eSAndroid Build Coastguard Worker int instress(void)
898*49cdfc7eSAndroid Build Coastguard Worker {
899*49cdfc7eSAndroid Build Coastguard Worker 	tst_resm(TINFO, "System resource may be too low, fork() malloc()"
900*49cdfc7eSAndroid Build Coastguard Worker 		 " etc are likely to fail.\n");
901*49cdfc7eSAndroid Build Coastguard Worker 	return 1;
902*49cdfc7eSAndroid Build Coastguard Worker }
903