Home | History | Annotate | Download | only in setdomainname
      1 /*
      2  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
      3  *
      4  * This program is free software; you can redistribute it and/or modify it
      5  * under the terms of version 2 of the GNU General Public License as
      6  * published by the Free Software Foundation.
      7  *
      8  * This program is distributed in the hope that it would be useful, but
      9  * WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     11  *
     12  * You should have received a copy of the GNU General Public License along
     13  * with this program; if not, write the Free Software Foundation, Inc.,
     14  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     15  *
     16  */
     17 /**********************************************************
     18  *
     19  *    TEST IDENTIFIER	: setdomainname01
     20  *
     21  *    EXECUTED BY	: root / superuser
     22  *
     23  *    TEST TITLE	: Basic test for setdomainame(2)
     24  *
     25  *    TEST CASE TOTAL	: 1
     26  *
     27  *    AUTHOR		: Saji Kumar.V.R <saji.kumar (at) wipro.com>
     28  *
     29  *    SIGNALS
     30  * 	Uses SIGUSR1 to pause before test if option set.
     31  * 	(See the parse_opts(3) man page).
     32  *
     33  *    DESCRIPTION
     34  *	This is a Phase I test for the setdomainname(2) system call.
     35  *	It is intended to provide a limited exposure of the system call.
     36  *
     37  * 	Setup:
     38  * 	  Setup signal handling.
     39  *	  Pause for SIGUSR1 if option specified.
     40  *	  Save the current domainname.
     41  *
     42  * 	Test:
     43  *	 Loop if the proper options are given.
     44  * 	  Execute system call
     45  *	  Check return code, if system call failed (return=-1)
     46  *		Log the errno and Issue a FAIL message.
     47  *	  Otherwise, Issue a PASS message.
     48  *
     49  * 	Cleanup:
     50  *	  Restore old domain name.
     51  * 	  Print errno log and/or timing stats if options given
     52  *
     53  * USAGE:  <for command-line>
     54  *  setdomainname01  [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
     55  *			where,  -c n : Run n copies concurrently.
     56  *				-e   : Turn on errno logging.
     57  *				-h   : Show help screen
     58  *				-f   : Turn off functional testing
     59  *				-i n : Execute test n times.
     60  *				-I x : Execute test for x seconds.
     61  *				-p   : Pause for SIGUSR1 before starting
     62  *				-P x : Pause for x seconds between iterations.
     63  *				-t   : Turn on syscall timing.
     64  *
     65  ****************************************************************/
     66 
     67 #include <errno.h>
     68 #include <string.h>
     69 #include <sys/utsname.h>
     70 #include "test.h"
     71 
     72 #define MAX_NAME_LEN _UTSNAME_DOMAIN_LENGTH
     73 
     74 static void setup();
     75 static void cleanup();
     76 
     77 char *TCID = "setdomainname01";
     78 int TST_TOTAL = 1;
     79 
     80 static char *test_domain_name = "test_dom";
     81 static char old_domain_name[MAX_NAME_LEN];
     82 
     83 int main(int ac, char **av)
     84 {
     85 
     86 	int lc;
     87 
     88 	tst_parse_opts(ac, av, NULL, NULL);
     89 
     90 	setup();
     91 
     92 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     93 
     94 		tst_count = 0;
     95 
     96 		/*
     97 		 * Call setdomainname(2)
     98 		 */
     99 		TEST(setdomainname(test_domain_name, sizeof(test_domain_name)));
    100 
    101 		/* check return code */
    102 		if (TEST_RETURN == -1) {
    103 			tst_resm(TFAIL, "setdomainname() Failed, errno = %d :"
    104 				 " %s", TEST_ERRNO, strerror(TEST_ERRNO));
    105 		} else {
    106 			tst_resm(TPASS, "setdomainname() returned %ld, "
    107 				 "Domain name set to \"%s\"", TEST_RETURN,
    108 				 test_domain_name);
    109 		}
    110 
    111 	}
    112 
    113 	/* cleanup and exit */
    114 	cleanup();
    115 	tst_exit();
    116 
    117 }
    118 
    119 /* setup() - performs all ONE TIME setup for this test */
    120 void setup(void)
    121 {
    122 	tst_require_root();
    123 
    124 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
    125 
    126 	/* Save current domain name */
    127 	if ((getdomainname(old_domain_name, sizeof(old_domain_name))) < 0) {
    128 		tst_brkm(TBROK, NULL, "getdomainname() failed while"
    129 			 " getting current domain name");
    130 	}
    131 
    132 	TEST_PAUSE;
    133 
    134 }
    135 
    136 /*
    137  *cleanup() -  performs all ONE TIME cleanup for this test at
    138  *		completion or premature exit.
    139  */
    140 void cleanup(void)
    141 {
    142 
    143 	/* Restore domain name */
    144 	if ((setdomainname(old_domain_name, strlen(old_domain_name))) < 0) {
    145 		tst_resm(TWARN, "setdomainname() failed while restoring"
    146 			 " domainname to \"%s\"", old_domain_name);
    147 	}
    148 
    149 }
    150