blob: b18feab4968f21265f22604d9c1b08dbb71cae7b [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
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20/*
21 * NAME
22 * vhangup02.c
23 *
24 * DESCRIPTION
25 * To test the basic functionality of vhangup(2)
26 *
27 *
28 * USAGE: <for command-line>
29 * vhangup02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
30 * where, -c n : Run n copies concurrently.
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 * History
36 * 07/2001 John George
37 * -Ported
38 *
39 * Restrictions
40 * None
41 */
42
43#include <unistd.h>
44#include <sys/types.h>
45#include <errno.h>
46#include <pwd.h>
47#include <wait.h>
48#include <test.h>
49#include <usctest.h>
50
51void setup(void);
52void cleanup(void);
53
54char *TCID = "vhangup02";
55int TST_TOTAL = 1;
56extern int Tst_count;
57
58int fail;
59
plars74948ad2002-11-14 16:16:14 +000060int main(int argc, char **argv)
plars865695b2001-08-27 22:15:12 +000061{
62 int lc;
63 char *msg;
64
65 pid_t pid, pid1;
plars74948ad2002-11-14 16:16:14 +000066 int status;
plars865695b2001-08-27 22:15:12 +000067
68 /* parse standard options */
69 if ((msg = parse_opts(argc, argv, (option_t *)NULL, NULL)) !=
70 (char *) NULL) {
71 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
72 }
73
74 setup();
75
76 /* check looping state if -i option is given */
77 for (lc = 0; TEST_LOOPING(lc); lc++) {
78 /* reset Tst_count in case we are looping */
79 Tst_count = 0;
80
81 fail = 0;
82
robbiewd34d5812005-07-11 22:28:09 +000083 if ((pid = FORK_OR_VFORK()) < 0) {
plars865695b2001-08-27 22:15:12 +000084 tst_brkm(TFAIL, cleanup, "fork failed");
85 /*NOTREACHED*/
86 } else if (pid > 0) { /* parent */
87 waitpid(pid, &status, 0);
88 _exit(0);
89 } else { /* child */
90 pid1 = setsid();
91 if (pid1 < 0) {
92 tst_brkm(TFAIL, cleanup, "setsid failed");
93 /*NOTREACHED*/
94 }
95 TEST(vhangup());
96 if (TEST_RETURN == -1) {
97 tst_resm(TFAIL, "vhangup() failed, errno:%d",
98 errno);
99 } else {
100 tst_resm(TPASS, "vhangup() succeeded");
101 }
102 }
103 }
104 cleanup();
105 /*NOTREACHED*/
robbiew10d86462003-03-27 22:37:45 +0000106
subrata_modak43337a32009-02-26 11:43:51 +0000107 return 0;
robbiew10d86462003-03-27 22:37:45 +0000108
plars865695b2001-08-27 22:15:12 +0000109}
110
111/*
112 * setup()
113 * performs all ONE TIME setup for this test
114 */
115void
116setup(void)
117{
118 /* Pause if that option was specified
119 * TEST_PAUSE contains the code to fork the test with the -c option.
120 */
121 TEST_PAUSE;
122}
123
124/*
125 * cleanup()
126 * performs all ONE TIME cleanup for this test at
127 * completion or premature exit
128 */
129void
130cleanup(void)
131{
132 /*
133 * print timing stats if that option was specified.
134 * print errno log if that option was specified.
135 */
136 TEST_CLEANUP;
137
138 /* exit with return code appropriate for results */
139 tst_exit();
140 /*NOTREACHED*/
141}