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 * setpgrp02.c
23 *
24 * DESCRIPTION
25 * Testcase to check the basic functionality of the setpgrp(2) syscall.
26 *
27 * ALGORITHM
28 * Check the values that setpgrp() and getpgrp() return. The setpgrp()
29 * returns 0 on success in Linux, but, in DYNIX/ptx this call returns
30 * the new pgid.
31 *
32 * USAGE: <for command-line>
33 * setpgrp02 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
34 * where, -c n : Run n copies concurrently.
35 * -f : Turn off functionality Testing.
36 * -i n : Execute test n times.
37 * -I x : Execute test for x seconds.
38 * -P x : Pause for x seconds between iterations.
39 * -t : Turn on syscall timing.
40 *
41 * HISTORY
42 * 07/2001 Ported by Wayne Boyer
43 *
44 * RESTRICTIONS
45 * None
46 */
47 #include <errno.h>
48 #include <sys/wait.h>
49 #include "test.h"
50
51 char *TCID = "setpgrp02";
52 int TST_TOTAL = 1;
53
54 void setup(void);
55 void cleanup(void);
56
main(int ac,char ** av)57 int main(int ac, char **av)
58 {
59 int lc;
60
61 int pid, oldpgrp;
62 int e_code, status, retval = 0;
63
64 tst_parse_opts(ac, av, NULL, NULL);
65
66 setup();
67
68 for (lc = 0; TEST_LOOPING(lc); lc++) {
69
70 /* reset tst_count in case we are looping */
71 tst_count = 0;
72
73 if ((pid = FORK_OR_VFORK()) == -1) {
74 tst_brkm(TBROK, cleanup, "fork() failed");
75 }
76
77 if (pid == 0) { /* child */
78 oldpgrp = getpgrp();
79
80 TEST(setpgrp());
81
82 if (TEST_RETURN != 0) {
83 retval = 1;
84 tst_resm(TFAIL, "setpgrp() FAILED, errno:%d",
85 errno);
86 continue;
87 }
88
89 if (getpgrp() == oldpgrp) {
90 retval = 1;
91 tst_resm(TFAIL, "setpgrp() FAILED to set "
92 "new group id");
93 continue;
94 } else {
95 tst_resm(TPASS, "functionality is correct");
96 }
97 exit(retval);
98 } else { /* parent */
99 /* wait for the child to finish */
100 wait(&status);
101 /* make sure the child returned a good exit status */
102 e_code = status >> 8;
103 if ((e_code != 0) || (retval != 0)) {
104 tst_resm(TFAIL, "Failures reported above");
105 }
106 cleanup();
107 }
108 }
109 tst_exit();
110 }
111
112 /*
113 * setup() - performs all ONE TIME setup for this test.
114 */
setup(void)115 void setup(void)
116 {
117
118 tst_sig(FORK, DEF_HANDLER, cleanup);
119
120 TEST_PAUSE;
121 }
122
123 /*
124 * cleanup() - performs all ONE TIME cleanup for this test at
125 * completion or premature exit.
126 */
cleanup(void)127 void cleanup(void)
128 {
129
130 }
131