blob: b6bca5df94dfdaf6c8ce54045f72d270ad25180e [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
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>
Steven Jackson249f4052016-12-13 16:16:00 +000047#include <sys/wait.h>
Garrett Coopere8530df2010-12-21 11:37:57 -080048#include "test.h"
plars865695b2001-08-27 22:15:12 +000049
50void setup(void);
51void cleanup(void);
52
53char *TCID = "vhangup02";
54int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000055
56int fail;
57
plars74948ad2002-11-14 16:16:14 +000058int main(int argc, char **argv)
plars865695b2001-08-27 22:15:12 +000059{
60 int lc;
plars865695b2001-08-27 22:15:12 +000061
62 pid_t pid, pid1;
plars74948ad2002-11-14 16:16:14 +000063 int status;
plars865695b2001-08-27 22:15:12 +000064
Cyril Hrubisd6d11d02015-03-09 17:35:43 +010065 tst_parse_opts(argc, argv, NULL, NULL);
plars865695b2001-08-27 22:15:12 +000066
67 setup();
68
plars865695b2001-08-27 22:15:12 +000069 for (lc = 0; TEST_LOOPING(lc); lc++) {
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
73 fail = 0;
74
robbiewd34d5812005-07-11 22:28:09 +000075 if ((pid = FORK_OR_VFORK()) < 0) {
plars865695b2001-08-27 22:15:12 +000076 tst_brkm(TFAIL, cleanup, "fork failed");
Wanlong Gao354ebb42012-12-07 10:10:04 +080077 } else if (pid > 0) { /* parent */
plars865695b2001-08-27 22:15:12 +000078 waitpid(pid, &status, 0);
79 _exit(0);
subrata_modak56207ce2009-03-23 13:35:39 +000080 } else { /* child */
plars865695b2001-08-27 22:15:12 +000081 pid1 = setsid();
82 if (pid1 < 0) {
83 tst_brkm(TFAIL, cleanup, "setsid failed");
Wanlong Gao354ebb42012-12-07 10:10:04 +080084 }
plars865695b2001-08-27 22:15:12 +000085 TEST(vhangup());
86 if (TEST_RETURN == -1) {
87 tst_resm(TFAIL, "vhangup() failed, errno:%d",
88 errno);
89 } else {
90 tst_resm(TPASS, "vhangup() succeeded");
91 }
92 }
93 }
94 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080095 tst_exit();
robbiew10d86462003-03-27 22:37:45 +000096
plars865695b2001-08-27 22:15:12 +000097}
98
99/*
100 * setup()
101 * performs all ONE TIME setup for this test
102 */
subrata_modak56207ce2009-03-23 13:35:39 +0000103void setup(void)
plars865695b2001-08-27 22:15:12 +0000104{
105 /* Pause if that option was specified
106 * TEST_PAUSE contains the code to fork the test with the -c option.
107 */
108 TEST_PAUSE;
109}
110
111/*
112 * cleanup()
113 * performs all ONE TIME cleanup for this test at
114 * completion or premature exit
115 */
subrata_modak56207ce2009-03-23 13:35:39 +0000116void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000117{
plars865695b2001-08-27 22:15:12 +0000118
Wanlong Gao354ebb42012-12-07 10:10:04 +0800119}