blob: 079ca608ecb8dda1abf541b5ac4ffe32953a24d3 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
Cyril Hrubis88629d42014-06-02 16:41:40 +02003 * AUTHOR : William Roske
4 * CO-PILOT : Dave Fenner
plars865695b2001-08-27 22:15:12 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it would be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 * Further, this software is distributed without any warranty that it is
15 * free of the rightful claim of any third person regarding infringement
16 * or the like. Any license provided herein, whether implied or
17 * otherwise, applies only to this software file. Patent licenses, if
18 * any, provided herein do not apply to combinations of this program with
19 * other software, or any other product whatsoever.
20 *
21 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080022 * with this program; if not, write the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
plars865695b2001-08-27 22:15:12 +000024 *
25 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
26 * Mountain View, CA 94043, or:
27 *
28 * http://www.sgi.com
29 *
30 * For further information regarding this notice, see:
31 *
32 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
33 *
34 */
plars865695b2001-08-27 22:15:12 +000035
36#include <errno.h>
37#include <signal.h>
38#include <sys/wait.h>
39#include <string.h>
40#include <stdlib.h>
41#include "test.h"
plars865695b2001-08-27 22:15:12 +000042
43void setup();
44void cleanup();
45
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020046char *TCID = "setpgrp01";
47int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000048
subrata_modak56207ce2009-03-23 13:35:39 +000049int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000050{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020051 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020052 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +000053
Cyril Hrubis88629d42014-06-02 16:41:40 +020054 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
subrata_modak56207ce2009-03-23 13:35:39 +000055 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080056
subrata_modak56207ce2009-03-23 13:35:39 +000057 setup();
plars865695b2001-08-27 22:15:12 +000058
subrata_modak56207ce2009-03-23 13:35:39 +000059 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +000060
Caspar Zhangd59a6592013-03-07 14:59:12 +080061 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000062
subrata_modak56207ce2009-03-23 13:35:39 +000063 /*
64 * TEST CASE:
65 * Call the setpgrp system call
66 */
subrata_modak56207ce2009-03-23 13:35:39 +000067 TEST(setpgrp());
subrata_modakbdbaec52009-02-26 12:14:51 +000068
subrata_modak56207ce2009-03-23 13:35:39 +000069 if (TEST_RETURN != 0) {
subrata_modak56207ce2009-03-23 13:35:39 +000070 tst_resm(TFAIL,
71 "setpgrp - Call the setpgrp system call failed, errno=%d : %s",
72 TEST_ERRNO, strerror(TEST_ERRNO));
73 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +020074 tst_resm(TPASS,
75 "setpgrp - Call the setpgrp system call returned %ld",
76 TEST_RETURN);
subrata_modak56207ce2009-03-23 13:35:39 +000077 }
subrata_modakbdbaec52009-02-26 12:14:51 +000078
Garrett Cooper2c282152010-12-16 00:55:50 -080079 }
plars865695b2001-08-27 22:15:12 +000080
subrata_modak56207ce2009-03-23 13:35:39 +000081 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -080082 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080083}
plars865695b2001-08-27 22:15:12 +000084
Mike Frysingerc57fba52014-04-09 18:56:30 -040085void setup(void)
plars865695b2001-08-27 22:15:12 +000086{
subrata_modak56207ce2009-03-23 13:35:39 +000087 int pid, status;
plars865695b2001-08-27 22:15:12 +000088
subrata_modak56207ce2009-03-23 13:35:39 +000089 tst_sig(FORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +000090
subrata_modak56207ce2009-03-23 13:35:39 +000091 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +000092
subrata_modak56207ce2009-03-23 13:35:39 +000093 /*
94 * Make sure current process is NOT a session or pgrp leader
95 */
subrata_modak56207ce2009-03-23 13:35:39 +000096 if (getpgrp() == getpid()) {
97 if ((pid = FORK_OR_VFORK()) == -1) {
98 tst_brkm(TBROK, cleanup,
99 "fork() in setup() failed - errno %d", errno);
100 }
101
102 if (pid != 0) { /* parent - sits and waits */
103 wait(&status);
104 exit(WEXITSTATUS(status));
105 }
106
plars865695b2001-08-27 22:15:12 +0000107 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800108}
plars865695b2001-08-27 22:15:12 +0000109
Mike Frysingerc57fba52014-04-09 18:56:30 -0400110void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000111{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700112}