Home | History | Annotate | Download | only in vhangup
      1 /*
      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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 <sys/wait.h>
     48 #include "test.h"
     49 
     50 void setup(void);
     51 void cleanup(void);
     52 
     53 char *TCID = "vhangup02";
     54 int TST_TOTAL = 1;
     55 
     56 int fail;
     57 
     58 int main(int argc, char **argv)
     59 {
     60 	int lc;
     61 
     62 	pid_t pid, pid1;
     63 	int status;
     64 
     65 	tst_parse_opts(argc, argv, NULL, NULL);
     66 
     67 	setup();
     68 
     69 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     70 		/* reset tst_count in case we are looping */
     71 		tst_count = 0;
     72 
     73 		fail = 0;
     74 
     75 		if ((pid = FORK_OR_VFORK()) < 0) {
     76 			tst_brkm(TFAIL, cleanup, "fork failed");
     77 		} else if (pid > 0) {	/* parent */
     78 			waitpid(pid, &status, 0);
     79 			_exit(0);
     80 		} else {	/* child */
     81 			pid1 = setsid();
     82 			if (pid1 < 0) {
     83 				tst_brkm(TFAIL, cleanup, "setsid failed");
     84 			}
     85 			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();
     95 	tst_exit();
     96 
     97 }
     98 
     99 /*
    100  * setup()
    101  *	performs all ONE TIME setup for this test
    102  */
    103 void setup(void)
    104 {
    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  */
    116 void cleanup(void)
    117 {
    118 
    119 }
    120