blob: d477c8f2f62377b06dfeceedc7432cf12f2f5708 [file] [log] [blame]
nstraze3219812003-07-14 17:06:37 +00001/*
2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +08003 * Copyright (c) 2012 Wanlong Gao <gaowanlong@cn.fujitsu.com>
nstraze3219812003-07-14 17:06:37 +00004 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 *
13 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080014 * with this program; if not, write the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
nstraze3219812003-07-14 17:06:37 +000016 *
17 */
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080018/*
nstraze3219812003-07-14 17:06:37 +000019 * TEST1
20 * -----
21 * Call clone() with all resources shared.
22 *
23 * CHILD:
24 * modify the shared resources
25 * return 1 on success
26 * PARENT:
27 * wait for child to finish
28 * verify that the shared resourses are modified
29 * return 1 on success
30 * If parent & child returns successfully
31 * test passed
32 * else
33 * test failed
subrata_modak4bb656a2009-02-26 12:02:09 +000034 *
nstraze3219812003-07-14 17:06:37 +000035 * TEST2
36 * -----
37 * Call clone() with no resources shared.
38 *
39 * CHILD:
40 * modify the resources in child's address space
41 * return 1 on success
42 * PARENT:
43 * wait for child to finish
44 * verify that the parent's resourses are not modified
45 * return 1 on success
46 * If parent & child returns successfully
47 * test passed
48 * else
49 * test failed
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080050 */
nstraze3219812003-07-14 17:06:37 +000051
robbiewd34d5812005-07-11 22:28:09 +000052#if defined UCLINUX && !__THROW
53/* workaround for libc bug */
54#define __THROW
55#endif
56
Cyril Hrubis019ed6c2011-08-26 12:59:32 +020057#define _GNU_SOURCE
58
nstraze3219812003-07-14 17:06:37 +000059#include <errno.h>
nstraze3219812003-07-14 17:06:37 +000060#include <fcntl.h>
61#include <sys/wait.h>
mridgefc9dd8c2004-05-11 21:37:01 +000062#include <sys/types.h>
63#include <sys/syscall.h>
Cyril Hrubis019ed6c2011-08-26 12:59:32 +020064#include <sched.h>
nstraze3219812003-07-14 17:06:37 +000065#include "test.h"
nstraze3219812003-07-14 17:06:37 +000066
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080067#define FLAG_ALL (CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGCHLD)
nstraze3219812003-07-14 17:06:37 +000068#define FLAG_NONE SIGCHLD
69#define PARENT_VALUE 1
70#define CHILD_VALUE 2
71#define TRUE 1
72#define FALSE 0
73
nstraz882ee2d2003-07-16 17:40:32 +000074#include "clone_platform.h"
nstraze3219812003-07-14 17:06:37 +000075
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080076static void setup(void);
77static int test_setup(void);
78static void cleanup(void);
79static void test_cleanup(void);
nstraze3219812003-07-14 17:06:37 +000080static int child_fn();
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080081static int parent_test1(void);
82static int parent_test2(void);
83static int test_VM(void);
84static int test_FS(void);
85static int test_FILES(void);
86static int test_SIG(void);
87static int modified_VM(void);
88static int modified_FS(void);
89static int modified_FILES(void);
90static int modified_SIG(void);
91static void sig_child_defined_handler(int);
nstraze3219812003-07-14 17:06:37 +000092static void sig_default_handler();
93
nstraze3219812003-07-14 17:06:37 +000094static int fd_parent;
95static char file_name[25];
96static int parent_variable;
97static char cwd_parent[FILENAME_MAX];
98static int parent_got_signal, child_pid;
99
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800100char *TCID = "clone02";
nstraze3219812003-07-14 17:06:37 +0000101
102struct test_case_t {
103 int flags;
subrata_modak56207ce2009-03-23 13:35:39 +0000104 int (*parent_fn) ();
nstraze3219812003-07-14 17:06:37 +0000105} test_cases[] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800106 {
107 FLAG_ALL, parent_test1}, {
108 FLAG_NONE, parent_test2}
nstraze3219812003-07-14 17:06:37 +0000109};
110
111int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
subrata_modakbdbaec52009-02-26 12:14:51 +0000112
subrata_modak56207ce2009-03-23 13:35:39 +0000113int main(int ac, char **av)
nstraze3219812003-07-14 17:06:37 +0000114{
115
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200116 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200117 const char *msg;
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800118 void *child_stack;
nstraze3219812003-07-14 17:06:37 +0000119 int status, i;
subrata_modak56207ce2009-03-23 13:35:39 +0000120
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800121 msg = parse_opts(ac, av, NULL, NULL);
122 if (msg != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -0800123 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
nstraze3219812003-07-14 17:06:37 +0000124
nstraze3219812003-07-14 17:06:37 +0000125 setup();
126
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800127 child_stack = malloc(CHILD_STACK_SIZE);
128 if (child_stack == NULL)
nstraze3219812003-07-14 17:06:37 +0000129 tst_brkm(TBROK, cleanup, "Cannot allocate stack for child");
nstraze3219812003-07-14 17:06:37 +0000130
subrata_modak56207ce2009-03-23 13:35:39 +0000131 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +0800132 tst_count = 0;
nstraze3219812003-07-14 17:06:37 +0000133
subrata_modak56207ce2009-03-23 13:35:39 +0000134 for (i = 0; i < TST_TOTAL; ++i) {
Garrett Cooper7e20b262010-12-17 02:23:12 -0800135 if (test_setup() != 0) {
nstraze3219812003-07-14 17:06:37 +0000136 tst_resm(TWARN, "test_setup() failed,"
137 "skipping this test case");
138 continue;
139 }
subrata_modak56207ce2009-03-23 13:35:39 +0000140
nstraze3219812003-07-14 17:06:37 +0000141 /* Test the system call */
vapierf6d7f092009-11-03 20:07:35 +0000142 TEST(ltp_clone(test_cases[i].flags, child_fn, NULL,
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800143 CHILD_STACK_SIZE, child_stack));
nstraze3219812003-07-14 17:06:37 +0000144
145 /* check return code */
146 if (TEST_RETURN == -1) {
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800147 tst_resm(TFAIL | TTERRNO, "clone() failed");
nstraze3219812003-07-14 17:06:37 +0000148 /* Cleanup & continue with next test case */
149 test_cleanup();
150 continue;
151 }
152
153 /* Wait for child to finish */
Garrett Cooper7e20b262010-12-17 02:23:12 -0800154 if ((wait(&status)) == -1) {
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800155 tst_resm(TWARN | TERRNO,
156 "wait failed; skipping testcase");
nstraze3219812003-07-14 17:06:37 +0000157 /* Cleanup & continue with next test case */
158 test_cleanup();
159 continue;
160 }
subrata_modak56207ce2009-03-23 13:35:39 +0000161
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800162 if (WTERMSIG(status))
subrata_modak56207ce2009-03-23 13:35:39 +0000163 tst_resm(TWARN, "child exitied with signal %d",
164 WTERMSIG(status));
nstraze3219812003-07-14 17:06:37 +0000165
166 /*
Garrett Cooper7e20b262010-12-17 02:23:12 -0800167 * Check the return value from child function and
nstraze3219812003-07-14 17:06:37 +0000168 * parent function. If both functions returned
169 * successfully, test passed, else failed
subrata_modakbdbaec52009-02-26 12:14:51 +0000170 */
Garrett Cooper7e20b262010-12-17 02:23:12 -0800171 if (WIFEXITED(status) && WEXITSTATUS(status) == 0 &&
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800172 test_cases[i].parent_fn())
nstraze3219812003-07-14 17:06:37 +0000173 tst_resm(TPASS, "Test Passed");
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800174 else
subrata_modak56207ce2009-03-23 13:35:39 +0000175 tst_resm(TFAIL, "Test Failed");
nstraze3219812003-07-14 17:06:37 +0000176
177 /* Do test specific cleanup */
178 test_cleanup();
179 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800180 }
nstraze3219812003-07-14 17:06:37 +0000181
182 free(child_stack);
subrata_modakbdbaec52009-02-26 12:14:51 +0000183
nstraze3219812003-07-14 17:06:37 +0000184 cleanup();
Garrett Cooper53740502010-12-16 00:04:01 -0800185 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800186}
nstraze3219812003-07-14 17:06:37 +0000187
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800188static void setup(void)
nstraze3219812003-07-14 17:06:37 +0000189{
nstraze3219812003-07-14 17:06:37 +0000190 tst_sig(FORK, DEF_HANDLER, cleanup);
nstraze3219812003-07-14 17:06:37 +0000191 TEST_PAUSE;
nstraze3219812003-07-14 17:06:37 +0000192 tst_tmpdir();
subrata_modakbdbaec52009-02-26 12:14:51 +0000193
nstraze3219812003-07-14 17:06:37 +0000194 /* Get unique file name for each child process */
Garrett Cooper7e20b262010-12-17 02:23:12 -0800195 if ((sprintf(file_name, "parent_file_%ld", syscall(__NR_gettid))) <= 0)
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800196 tst_brkm(TBROK | TERRNO, cleanup, "sprintf() failed");
Garrett Cooper2c282152010-12-16 00:55:50 -0800197}
nstraze3219812003-07-14 17:06:37 +0000198
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800199static void cleanup(void)
nstraze3219812003-07-14 17:06:37 +0000200{
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800201 if (unlink(file_name) == -1)
202 tst_resm(TWARN | TERRNO, "unlink(%s) failed", file_name);
Garrett Cooper7e20b262010-12-17 02:23:12 -0800203 tst_rmdir();
Garrett Cooper2c282152010-12-16 00:55:50 -0800204}
nstraze3219812003-07-14 17:06:37 +0000205
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800206static int test_setup(void)
nstraze3219812003-07-14 17:06:37 +0000207{
208
209 struct sigaction def_act;
210
211 /* Save current working directory of parent */
Garrett Cooper7e20b262010-12-17 02:23:12 -0800212 if (getcwd(cwd_parent, sizeof(cwd_parent)) == NULL) {
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800213 tst_resm(TWARN | TERRNO, "getcwd() failed in test_setup()");
Garrett Cooper7e20b262010-12-17 02:23:12 -0800214 return -1;
nstraze3219812003-07-14 17:06:37 +0000215 }
216
217 /*
218 * Set value for parent_variable in parent, which will be
219 * changed by child in test_VM(), for testing CLONE_VM flag
220 */
221 parent_variable = PARENT_VALUE;
222
223 /*
224 * Open file from parent, which will be closed by
225 * child in test_FILES(), used for testing CLONE_FILES flag
226 */
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800227 fd_parent = open(file_name, O_CREAT | O_RDWR, 0777);
228 if (fd_parent == -1) {
229 tst_resm(TWARN | TERRNO, "open() failed in test_setup()");
Garrett Cooper7e20b262010-12-17 02:23:12 -0800230 return -1;
nstraze3219812003-07-14 17:06:37 +0000231 }
232
233 /*
234 * set parent_got_signal to FALSE, used for testing
235 * CLONE_SIGHAND flag
236 */
237 parent_got_signal = FALSE;
238
239 /* Setup signal handler for SIGUSR2 */
240 def_act.sa_handler = sig_default_handler;
241 def_act.sa_flags = SA_RESTART;
Jan Stancekcbec02d2013-04-02 12:16:58 +0200242 sigemptyset(&def_act.sa_mask);
nstraze3219812003-07-14 17:06:37 +0000243
Garrett Cooper7e20b262010-12-17 02:23:12 -0800244 if (sigaction(SIGUSR2, &def_act, NULL) == -1) {
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800245 tst_resm(TWARN | TERRNO, "sigaction() failed in test_setup()");
Garrett Cooper7e20b262010-12-17 02:23:12 -0800246 return -1;
nstraze3219812003-07-14 17:06:37 +0000247 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000248
Garrett Cooper7e20b262010-12-17 02:23:12 -0800249 return 0;
nstraze3219812003-07-14 17:06:37 +0000250}
251
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800252static void test_cleanup(void)
nstraze3219812003-07-14 17:06:37 +0000253{
254
255 /* Restore parent's working directory */
Garrett Cooper7e20b262010-12-17 02:23:12 -0800256 if (chdir(cwd_parent) == -1) {
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800257 /*
Garrett Cooper7e20b262010-12-17 02:23:12 -0800258 * we have to exit here
259 *
260 * XXX (garrcoop): why???
261 */
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800262 tst_brkm(TBROK | TERRNO, cleanup,
263 "chdir() failed in test_cleanup()");
nstraze3219812003-07-14 17:06:37 +0000264 }
265
266}
267
Mike Frysingerc57fba52014-04-09 18:56:30 -0400268static int child_fn(void)
nstraze3219812003-07-14 17:06:37 +0000269{
270
271 /* save child pid */
subrata_modak56207ce2009-03-23 13:35:39 +0000272 child_pid = syscall(__NR_gettid);
mridgefc9dd8c2004-05-11 21:37:01 +0000273
Garrett Cooper7e20b262010-12-17 02:23:12 -0800274 if (test_VM() == 0 && test_FILES() == 0 && test_FS() == 0 &&
275 test_SIG() == 0)
276 exit(0);
277 exit(1);
nstraze3219812003-07-14 17:06:37 +0000278}
279
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800280static int parent_test1(void)
nstraze3219812003-07-14 17:06:37 +0000281{
subrata_modakbdbaec52009-02-26 12:14:51 +0000282
nstraze3219812003-07-14 17:06:37 +0000283 /*
284 * For first test case (with all flags set), all resources are
285 * shared between parent and child. So whatever changes made by
286 * child should get reflected in parent also. modified_*()
287 * functions check this. All of them should return 1 for
288 * parent_test1() to return 1
289 */
subrata_modakbdbaec52009-02-26 12:14:51 +0000290
subrata_modak56207ce2009-03-23 13:35:39 +0000291 if (modified_VM() && modified_FILES() && modified_FS() &&
Garrett Cooper7e20b262010-12-17 02:23:12 -0800292 modified_SIG())
293 return 0;
294 return -1;
nstraze3219812003-07-14 17:06:37 +0000295}
296
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800297static int parent_test2(void)
nstraze3219812003-07-14 17:06:37 +0000298{
299
300 /*
301 * For second test case (with no resouce shared), all of the
302 * modified_*() functions should return 0 for parent_test2()
303 * to return 1
304 */
subrata_modak56207ce2009-03-23 13:35:39 +0000305 if (modified_VM() || modified_FILES() || modified_FS() ||
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800306 modified_SIG())
nstraze3219812003-07-14 17:06:37 +0000307 return 0;
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800308
Garrett Cooper7e20b262010-12-17 02:23:12 -0800309 return -1;
nstraze3219812003-07-14 17:06:37 +0000310}
311
312/*
313 * test_VM() - function to change parent_variable from child's
314 * address space. If CLONE_VM flag is set, child shares
315 * the memory space with parent so this will be visible
316 * to parent also.
317 */
318
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800319static int test_VM(void)
nstraze3219812003-07-14 17:06:37 +0000320{
321 parent_variable = CHILD_VALUE;
Garrett Cooper7e20b262010-12-17 02:23:12 -0800322 return 0;
nstraze3219812003-07-14 17:06:37 +0000323}
324
325/*
326 * test_FILES() - This function closes a file descriptor opened by
327 * parent. If CLONE_FILES flag is set, the parent and
328 * the child process share the same file descriptor
329 * table. so this affects the parent also
330 */
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800331static int test_FILES(void)
nstraze3219812003-07-14 17:06:37 +0000332{
Garrett Cooper7e20b262010-12-17 02:23:12 -0800333 if (close(fd_parent) == -1) {
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800334 tst_resm(TWARN | TERRNO, "close failed in test_FILES");
Garrett Cooper7e20b262010-12-17 02:23:12 -0800335 return -1;
nstraze3219812003-07-14 17:06:37 +0000336 }
Garrett Cooper7e20b262010-12-17 02:23:12 -0800337 return 0;
nstraze3219812003-07-14 17:06:37 +0000338}
339
340/*
341 * test_FS() - This function changes the current working directory
342 * of the child process. If CLONE_FS flag is set, this
343 * will be visible to parent also.
344 */
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800345static int test_FS(void)
nstraze3219812003-07-14 17:06:37 +0000346{
Garrett Cooper7e20b262010-12-17 02:23:12 -0800347 char *test_tmpdir;
348 int rval;
349
Cyril Hrubis9c31ad22014-05-14 17:15:39 +0200350 test_tmpdir = tst_get_tmpdir();
Garrett Cooper7e20b262010-12-17 02:23:12 -0800351 if (test_tmpdir == NULL) {
Cyril Hrubis9c31ad22014-05-14 17:15:39 +0200352 tst_resm(TWARN | TERRNO, "tst_get_tmpdir failed");
Garrett Cooper7e20b262010-12-17 02:23:12 -0800353 rval = -1;
354 } else if (chdir(test_tmpdir) == -1) {
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800355 tst_resm(TWARN | TERRNO, "chdir failed in test_FS");
Garrett Cooper7e20b262010-12-17 02:23:12 -0800356 rval = -1;
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800357 } else {
Garrett Cooper7e20b262010-12-17 02:23:12 -0800358 rval = 0;
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800359 }
360
Garrett Cooper7e20b262010-12-17 02:23:12 -0800361 free(test_tmpdir);
362 return rval;
nstraze3219812003-07-14 17:06:37 +0000363}
364
365/*
366 * test_SIG() - This function changes the signal handler for SIGUSR2
367 * signal for child. If CLONE_SIGHAND flag is set, this
368 * affects parent also.
369 */
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800370static int test_SIG(void)
nstraze3219812003-07-14 17:06:37 +0000371{
372
373 struct sigaction new_act;
subrata_modakbdbaec52009-02-26 12:14:51 +0000374
nstraze3219812003-07-14 17:06:37 +0000375 new_act.sa_handler = sig_child_defined_handler;
376 new_act.sa_flags = SA_RESTART;
Jan Stancekcbec02d2013-04-02 12:16:58 +0200377 sigemptyset(&new_act.sa_mask);
subrata_modakbdbaec52009-02-26 12:14:51 +0000378
nstraze3219812003-07-14 17:06:37 +0000379 /* Set signal handler to sig_child_defined_handler */
Garrett Cooper7e20b262010-12-17 02:23:12 -0800380 if (sigaction(SIGUSR2, &new_act, NULL) == -1) {
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800381 tst_resm(TWARN | TERRNO, "signal failed in test_SIG");
Garrett Cooper7e20b262010-12-17 02:23:12 -0800382 return -1;
nstraze3219812003-07-14 17:06:37 +0000383 }
384
385 /* Send SIGUSR2 signal to parent */
Garrett Cooper7e20b262010-12-17 02:23:12 -0800386 if (kill(getppid(), SIGUSR2) == -1) {
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800387 tst_resm(TWARN | TERRNO, "kill failed in test_SIG");
Garrett Cooper7e20b262010-12-17 02:23:12 -0800388 return -1;
nstraze3219812003-07-14 17:06:37 +0000389 }
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800390
Garrett Cooper7e20b262010-12-17 02:23:12 -0800391 return 0;
nstraze3219812003-07-14 17:06:37 +0000392}
393
394/*
395 * modified_VM() - This function is called by parent process to check
396 * whether child's modification to parent_variable
397 * is visible to parent
398 */
399
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800400static int modified_VM(void)
nstraze3219812003-07-14 17:06:37 +0000401{
402
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800403 if (parent_variable == CHILD_VALUE)
nstraze3219812003-07-14 17:06:37 +0000404 /* child has modified parent_variable */
405 return 1;
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800406
nstraze3219812003-07-14 17:06:37 +0000407 return 0;
408}
409
410/*
411 * modified_FILES() - This function checks for file descriptor table
412 * modifications done by child
413 */
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800414static int modified_FILES(void)
nstraze3219812003-07-14 17:06:37 +0000415{
416 char buff[20];
subrata_modakbdbaec52009-02-26 12:14:51 +0000417
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800418 if (((read(fd_parent, buff, sizeof(buff))) == -1) && (errno == EBADF))
nstraze3219812003-07-14 17:06:37 +0000419 /* Child has closed this file descriptor */
420 return 1;
nstraze3219812003-07-14 17:06:37 +0000421
subrata_modak56207ce2009-03-23 13:35:39 +0000422 /* close fd_parent */
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800423 if ((close(fd_parent)) == -1)
424 tst_resm(TWARN | TERRNO, "close() failed in modified_FILES()");
subrata_modakbdbaec52009-02-26 12:14:51 +0000425
nstraze3219812003-07-14 17:06:37 +0000426 return 0;
427}
428
429/*
430 * modified_FS() - This function checks parent's current working directory
431 * to see whether its modified by child or not.
432 */
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800433static int modified_FS(void)
nstraze3219812003-07-14 17:06:37 +0000434{
435 char cwd[FILENAME_MAX];
subrata_modakbdbaec52009-02-26 12:14:51 +0000436
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800437 if ((getcwd(cwd, sizeof(cwd))) == NULL)
438 tst_resm(TWARN | TERRNO, "getcwd() failed");
subrata_modakbdbaec52009-02-26 12:14:51 +0000439
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800440 if (!(strcmp(cwd, cwd_parent)))
nstraze3219812003-07-14 17:06:37 +0000441 /* cwd hasn't changed */
442 return 0;
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800443
nstraze3219812003-07-14 17:06:37 +0000444 return 1;
445}
446
447/*
448 * modified_SIG() - This function checks whether child has changed
449 * parent's signal handler for signal, SIGUSR2
450 */
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800451static int modified_SIG(void)
nstraze3219812003-07-14 17:06:37 +0000452{
subrata_modakbdbaec52009-02-26 12:14:51 +0000453
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800454 if (parent_got_signal)
nstraze3219812003-07-14 17:06:37 +0000455 /*
456 * parent came through sig_child_defined_handler()
457 * this means child has changed parent's handler
458 */
459 return 1;
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800460
nstraze3219812003-07-14 17:06:37 +0000461 return 0;
462}
463
464/*
465 * sig_child_defined_handler() - Signal handler installed by child
466 */
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800467static void sig_child_defined_handler(int pid)
nstraze3219812003-07-14 17:06:37 +0000468{
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800469 if ((syscall(__NR_gettid)) == child_pid)
nstraze3219812003-07-14 17:06:37 +0000470 /* Child got signal, give warning */
471 tst_resm(TWARN, "Child got SIGUSR2 signal");
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +0800472 else
nstraze3219812003-07-14 17:06:37 +0000473 parent_got_signal = TRUE;
nstraze3219812003-07-14 17:06:37 +0000474}
475
476/* sig_default_handler() - Default handler for parent */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400477static void sig_default_handler(void)
nstraze3219812003-07-14 17:06:37 +0000478{
Cyril Hrubis019ed6c2011-08-26 12:59:32 +0200479}