blob: e6b2c3a190ba1f50630c0b020c1cc41d0c4efb52 [file] [log] [blame]
plarsd758be32002-11-01 15:59:31 +00001/*
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
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
plarsd758be32002-11-01 15:59:31 +000015 *
16 */
17/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
19 * TEST IDENTIFIER : setdomainname01
20 *
plarsd758be32002-11-01 15:59:31 +000021 * EXECUTED BY : root / superuser
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
plarsd758be32002-11-01 15:59:31 +000023 * TEST TITLE : Basic test for setdomainame(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
plarsd758be32002-11-01 15:59:31 +000025 * TEST CASE TOTAL : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
plarsd758be32002-11-01 15:59:31 +000027 * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
plarsd758be32002-11-01 15:59:31 +000029 * 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.
subrata_modak4bb656a2009-02-26 12:02:09 +000036 *
plarsd758be32002-11-01 15:59:31 +000037 * Setup:
38 * Setup signal handling.
39 * Pause for SIGUSR1 if option specified.
40 * Save the current domainname.
subrata_modak4bb656a2009-02-26 12:02:09 +000041 *
plarsd758be32002-11-01 15:59:31 +000042 * 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.
subrata_modak4bb656a2009-02-26 12:02:09 +000048 *
plarsd758be32002-11-01 15:59:31 +000049 * Cleanup:
50 * Restore old domain name.
51 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000052 *
plarsd758be32002-11-01 15:59:31 +000053 * 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>
mridge3a6b4742004-09-13 21:55:16 +000068#include <string.h>
69#include <sys/utsname.h>
plarsd758be32002-11-01 15:59:31 +000070#include "test.h"
plarsd758be32002-11-01 15:59:31 +000071
mridge3a6b4742004-09-13 21:55:16 +000072#define MAX_NAME_LEN _UTSNAME_DOMAIN_LENGTH
plarsd758be32002-11-01 15:59:31 +000073
74static void setup();
75static void cleanup();
76
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020077char *TCID = "setdomainname01";
78int TST_TOTAL = 1;
plarsd758be32002-11-01 15:59:31 +000079
subrata_modak56207ce2009-03-23 13:35:39 +000080static char *test_domain_name = "test_dom";
81static char old_domain_name[MAX_NAME_LEN];
plarsd758be32002-11-01 15:59:31 +000082
subrata_modak56207ce2009-03-23 13:35:39 +000083int main(int ac, char **av)
plarsd758be32002-11-01 15:59:31 +000084{
85
Cyril Hrubis89af32a2012-10-24 16:39:11 +020086 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020087 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +000088
Garrett Cooper45e285d2010-11-22 12:19:25 -080089 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
plarsd758be32002-11-01 15:59:31 +000090 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080091
plarsd758be32002-11-01 15:59:31 +000092 }
93
plarsd758be32002-11-01 15:59:31 +000094 setup();
95
subrata_modak56207ce2009-03-23 13:35:39 +000096 for (lc = 0; TEST_LOOPING(lc); lc++) {
plarsd758be32002-11-01 15:59:31 +000097
Caspar Zhangd59a6592013-03-07 14:59:12 +080098 tst_count = 0;
plarsd758be32002-11-01 15:59:31 +000099
subrata_modak4bb656a2009-02-26 12:02:09 +0000100 /*
plarsd758be32002-11-01 15:59:31 +0000101 * Call setdomainname(2)
102 */
subrata_modak56207ce2009-03-23 13:35:39 +0000103 TEST(setdomainname(test_domain_name, sizeof(test_domain_name)));
subrata_modakbdbaec52009-02-26 12:14:51 +0000104
plarsd758be32002-11-01 15:59:31 +0000105 /* check return code */
subrata_modak56207ce2009-03-23 13:35:39 +0000106 if (TEST_RETURN == -1) {
plarsd758be32002-11-01 15:59:31 +0000107 tst_resm(TFAIL, "setdomainname() Failed, errno = %d :"
subrata_modak56207ce2009-03-23 13:35:39 +0000108 " %s", TEST_ERRNO, strerror(TEST_ERRNO));
plarsd758be32002-11-01 15:59:31 +0000109 } else {
subrata_modak923b23f2009-11-02 13:57:16 +0000110 tst_resm(TPASS, "setdomainname() returned %ld, "
plarsd758be32002-11-01 15:59:31 +0000111 "Domain name set to \"%s\"", TEST_RETURN,
112 test_domain_name);
subrata_modak4bb656a2009-02-26 12:02:09 +0000113 }
plarsd758be32002-11-01 15:59:31 +0000114
Garrett Cooper2c282152010-12-16 00:55:50 -0800115 }
plarsd758be32002-11-01 15:59:31 +0000116
117 /* cleanup and exit */
118 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800119 tst_exit();
plarsd758be32002-11-01 15:59:31 +0000120
Garrett Cooper2c282152010-12-16 00:55:50 -0800121}
plarsd758be32002-11-01 15:59:31 +0000122
123/* setup() - performs all ONE TIME setup for this test */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400124void setup(void)
plarsd758be32002-11-01 15:59:31 +0000125{
Nicolas Jolyd4ceb372014-06-22 17:03:57 +0200126 tst_require_root(NULL);
subrata_modakbdbaec52009-02-26 12:14:51 +0000127
plarsd758be32002-11-01 15:59:31 +0000128 tst_sig(NOFORK, DEF_HANDLER, cleanup);
129
subrata_modak4bb656a2009-02-26 12:02:09 +0000130 /* Save current domain name */
subrata_modak56207ce2009-03-23 13:35:39 +0000131 if ((getdomainname(old_domain_name, sizeof(old_domain_name))) < 0) {
Garrett Cooper53740502010-12-16 00:04:01 -0800132 tst_brkm(TBROK, NULL, "getdomainname() failed while"
subrata_modakbdbaec52009-02-26 12:14:51 +0000133 " getting current domain name");
plarsd758be32002-11-01 15:59:31 +0000134 }
135
plarsd758be32002-11-01 15:59:31 +0000136 TEST_PAUSE;
137
Garrett Cooper2c282152010-12-16 00:55:50 -0800138}
plarsd758be32002-11-01 15:59:31 +0000139
subrata_modak4bb656a2009-02-26 12:02:09 +0000140/*
plarsd758be32002-11-01 15:59:31 +0000141 *cleanup() - performs all ONE TIME cleanup for this test at
142 * completion or premature exit.
143 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400144void cleanup(void)
plarsd758be32002-11-01 15:59:31 +0000145{
146
plarsd758be32002-11-01 15:59:31 +0000147 /* Restore domain name */
subrata_modak56207ce2009-03-23 13:35:39 +0000148 if ((setdomainname(old_domain_name, strlen(old_domain_name))) < 0) {
plarsd758be32002-11-01 15:59:31 +0000149 tst_resm(TWARN, "setdomainname() failed while restoring"
subrata_modak56207ce2009-03-23 13:35:39 +0000150 " domainname to \"%s\"", old_domain_name);
plarsd758be32002-11-01 15:59:31 +0000151 }
152
Chris Dearmanec6edca2012-10-17 19:54:01 -0700153}