blob: 9348b1ab111955c097e3d64c04d3b26a44d83f20 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * NAME
subrata_modak56207ce2009-03-23 13:35:39 +000022 * setpgrp02.c
plars865695b2001-08-27 22:15:12 +000023 *
24 * DESCRIPTION
25 * Testcase to check the basic functionality of the setpgrp(2) syscall.
26 *
27 * ALGORITHM
subrata_modak56207ce2009-03-23 13:35:39 +000028 * Check the values that setpgrp() and getpgrp() return. The setpgrp()
plars865695b2001-08-27 22:15:12 +000029 * returns 0 on success in Linux, but, in DYNIX/ptx this call returns
30 * the new pgid.
31 *
32 * USAGE: <for command-line>
robbiewa3b949c2001-09-17 18:04:26 +000033 * setpgrp02 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
plars865695b2001-08-27 22:15:12 +000034 * 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
subrata_modak56207ce2009-03-23 13:35:39 +000045 * None
plars865695b2001-08-27 22:15:12 +000046 */
47#include <errno.h>
robbiewf1ca2382003-03-27 20:28:50 +000048#include <wait.h>
plars865695b2001-08-27 22:15:12 +000049#include "test.h"
plars865695b2001-08-27 22:15:12 +000050
robbiewa3b949c2001-09-17 18:04:26 +000051char *TCID = "setpgrp02";
plars865695b2001-08-27 22:15:12 +000052int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000053
54void setup(void);
55void cleanup(void);
56
robbiewf1ca2382003-03-27 20:28:50 +000057int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000058{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020059 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020060 const char *msg; /* message returned by parse_opts */
plars865695b2001-08-27 22:15:12 +000061
robbiewf1ca2382003-03-27 20:28:50 +000062 int pid, oldpgrp;
subrata_modak56207ce2009-03-23 13:35:39 +000063 int e_code, status, retval = 0;
plars865695b2001-08-27 22:15:12 +000064
Garrett Cooper45e285d2010-11-22 12:19:25 -080065 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080066 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000067 }
68
69 setup();
70
plars865695b2001-08-27 22:15:12 +000071 for (lc = 0; TEST_LOOPING(lc); lc++) {
72
Caspar Zhangd59a6592013-03-07 14:59:12 +080073 /* reset tst_count in case we are looping */
74 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000075
robbiewd34d5812005-07-11 22:28:09 +000076 if ((pid = FORK_OR_VFORK()) == -1) {
plars865695b2001-08-27 22:15:12 +000077 tst_brkm(TBROK, cleanup, "fork() failed");
78 }
79
subrata_modak56207ce2009-03-23 13:35:39 +000080 if (pid == 0) { /* child */
plars865695b2001-08-27 22:15:12 +000081 oldpgrp = getpgrp();
82
83 TEST(setpgrp());
84
85 if (TEST_RETURN != 0) {
subrata_modak56207ce2009-03-23 13:35:39 +000086 retval = 1;
plars865695b2001-08-27 22:15:12 +000087 tst_resm(TFAIL, "setpgrp() FAILED, errno:%d",
88 errno);
89 continue;
90 }
91
plars865695b2001-08-27 22:15:12 +000092 if (getpgrp() == oldpgrp) {
subrata_modak56207ce2009-03-23 13:35:39 +000093 retval = 1;
plars865695b2001-08-27 22:15:12 +000094 tst_resm(TFAIL, "setpgrp() FAILED to set "
95 "new group id");
96 continue;
97 } else {
98 tst_resm(TPASS, "functionality is correct");
99 }
robbiewa3b949c2001-09-17 18:04:26 +0000100 exit(retval);
subrata_modak56207ce2009-03-23 13:35:39 +0000101 } else { /* parent */
robbiewa3b949c2001-09-17 18:04:26 +0000102 /* wait for the child to finish */
subrata_modak56207ce2009-03-23 13:35:39 +0000103 wait(&status);
104 /* make sure the child returned a good exit status */
105 e_code = status >> 8;
106 if ((e_code != 0) || (retval != 0)) {
107 tst_resm(TFAIL, "Failures reported above");
108 }
robbiewa3b949c2001-09-17 18:04:26 +0000109 cleanup();
plars865695b2001-08-27 22:15:12 +0000110 }
111 }
Garrett Cooper49f76222010-12-19 10:22:13 -0800112 tst_exit();
plars865695b2001-08-27 22:15:12 +0000113}
114
115/*
116 * setup() - performs all ONE TIME setup for this test.
117 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400118void setup(void)
plars865695b2001-08-27 22:15:12 +0000119{
Garrett Cooper2c282152010-12-16 00:55:50 -0800120
plars865695b2001-08-27 22:15:12 +0000121 tst_sig(FORK, DEF_HANDLER, cleanup);
122
plars865695b2001-08-27 22:15:12 +0000123 TEST_PAUSE;
124}
125
126/*
127 * cleanup() - performs all ONE TIME cleanup for this test at
128 * completion or premature exit.
129 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400130void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000131{
plars865695b2001-08-27 22:15:12 +0000132
Garrett Cooper49f76222010-12-19 10:22:13 -0800133}