1 /*
2  *
3  *   Copyright (c) International Business Machines  Corp., 2001
4  *
5  *   This program is free software;  you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  *   the GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program;  if not, write to the Free Software
17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /*
21  * NAME
22  * 	getppid02.c
23  *
24  * DESCRIPTION
25  * 	Testcase to check the basic functionality of the getppid() syscall.
26  *
27  * USAGE:  <for command-line>
28  *  getppid02 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
29  *     where,  -c n : Run n copies concurrently.
30  *             -f   : Turn off functionality Testing.
31  *             -i n : Execute test n times.
32  *             -I x : Execute test for x seconds.
33  *             -P x : Pause for x seconds between iterations.
34  *             -t   : Turn on syscall timing.
35  *
36  * HISTORY
37  *	07/2001 Ported by Wayne Boyer
38  *
39  * RESTRICTIONS
40  * 	None
41  */
42 #include <sys/types.h>
43 #include <sys/wait.h>
44 #include <err.h>
45 #include <errno.h>
46 #include "test.h"
47 #include "safe_macros.h"
48 
49 char *TCID = "getppid02";
50 int TST_TOTAL = 1;
51 
52 void setup(void);
53 void cleanup(void);
54 
55 int main(int ac, char **av)
56 {
57 
58 	int lc;
59 	int status;
60 	pid_t pid, ppid;
61 
62 	tst_parse_opts(ac, av, NULL, NULL);
63 
64 	setup();
65 
66 	for (lc = 0; TEST_LOOPING(lc); lc++) {
67 		tst_count = 0;
68 
69 		ppid = getpid();
70 		pid = FORK_OR_VFORK();
71 		if (pid == -1)
72 			tst_brkm(TBROK, cleanup, "fork failed");
73 
74 		if (pid == 0) {
75 			TEST(getppid());
76 
77 			if (TEST_RETURN != ppid)
78 				errx(1, "getppid failed (%ld != %d)",
79 				     TEST_RETURN, ppid);
80 			else
81 				printf("return value and parent's pid "
82 				       "value match\n");
83 			exit(0);
84 		} else {
85 			SAFE_WAIT(cleanup, &status);
86 			if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
87 				tst_resm(TFAIL,
88 					 "getppid functionality incorrect");
89 		}
90 	}
91 	cleanup();
92 
93 	tst_exit();
94 }
95 
96 void setup(void)
97 {
98 
99 	tst_sig(FORK, DEF_HANDLER, cleanup);
100 
101 	TEST_PAUSE;
102 }
103 
104 void cleanup(void)
105 {
106 }
107