blob: f1f6ce72a33ba57c6939ad25a95b7ae052d74a03 [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>
Steven Jackson249f4052016-12-13 16:16:00 +000048#include <sys/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;
plars865695b2001-08-27 22:15:12 +000060
robbiewf1ca2382003-03-27 20:28:50 +000061 int pid, oldpgrp;
subrata_modak56207ce2009-03-23 13:35:39 +000062 int e_code, status, retval = 0;
plars865695b2001-08-27 22:15:12 +000063
Cyril Hrubisd6d11d02015-03-09 17:35:43 +010064 tst_parse_opts(ac, av, NULL, NULL);
plars865695b2001-08-27 22:15:12 +000065
66 setup();
67
plars865695b2001-08-27 22:15:12 +000068 for (lc = 0; TEST_LOOPING(lc); lc++) {
69
Caspar Zhangd59a6592013-03-07 14:59:12 +080070 /* reset tst_count in case we are looping */
71 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000072
robbiewd34d5812005-07-11 22:28:09 +000073 if ((pid = FORK_OR_VFORK()) == -1) {
plars865695b2001-08-27 22:15:12 +000074 tst_brkm(TBROK, cleanup, "fork() failed");
75 }
76
subrata_modak56207ce2009-03-23 13:35:39 +000077 if (pid == 0) { /* child */
plars865695b2001-08-27 22:15:12 +000078 oldpgrp = getpgrp();
79
80 TEST(setpgrp());
81
82 if (TEST_RETURN != 0) {
subrata_modak56207ce2009-03-23 13:35:39 +000083 retval = 1;
plars865695b2001-08-27 22:15:12 +000084 tst_resm(TFAIL, "setpgrp() FAILED, errno:%d",
85 errno);
86 continue;
87 }
88
plars865695b2001-08-27 22:15:12 +000089 if (getpgrp() == oldpgrp) {
subrata_modak56207ce2009-03-23 13:35:39 +000090 retval = 1;
plars865695b2001-08-27 22:15:12 +000091 tst_resm(TFAIL, "setpgrp() FAILED to set "
92 "new group id");
93 continue;
94 } else {
95 tst_resm(TPASS, "functionality is correct");
96 }
robbiewa3b949c2001-09-17 18:04:26 +000097 exit(retval);
subrata_modak56207ce2009-03-23 13:35:39 +000098 } else { /* parent */
robbiewa3b949c2001-09-17 18:04:26 +000099 /* wait for the child to finish */
subrata_modak56207ce2009-03-23 13:35:39 +0000100 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 }
robbiewa3b949c2001-09-17 18:04:26 +0000106 cleanup();
plars865695b2001-08-27 22:15:12 +0000107 }
108 }
Garrett Cooper49f76222010-12-19 10:22:13 -0800109 tst_exit();
plars865695b2001-08-27 22:15:12 +0000110}
111
112/*
113 * setup() - performs all ONE TIME setup for this test.
114 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400115void setup(void)
plars865695b2001-08-27 22:15:12 +0000116{
Garrett Cooper2c282152010-12-16 00:55:50 -0800117
plars865695b2001-08-27 22:15:12 +0000118 tst_sig(FORK, DEF_HANDLER, cleanup);
119
plars865695b2001-08-27 22:15:12 +0000120 TEST_PAUSE;
121}
122
123/*
124 * cleanup() - performs all ONE TIME cleanup for this test at
125 * completion or premature exit.
126 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400127void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000128{
plars865695b2001-08-27 22:15:12 +0000129
Garrett Cooper49f76222010-12-19 10:22:13 -0800130}