blob: a7101bb046f8663b947f48428a903c35bf741f66 [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"
71#include "usctest.h"
72
mridge3a6b4742004-09-13 21:55:16 +000073#define MAX_NAME_LEN _UTSNAME_DOMAIN_LENGTH
plarsd758be32002-11-01 15:59:31 +000074
75static void setup();
76static void cleanup();
77
subrata_modak56207ce2009-03-23 13:35:39 +000078char *TCID = "setdomainname01"; /* Test program identifier. */
79int TST_TOTAL = 1; /* Total number of test cases. */
plarsd758be32002-11-01 15:59:31 +000080
subrata_modak56207ce2009-03-23 13:35:39 +000081static char *test_domain_name = "test_dom";
82static char old_domain_name[MAX_NAME_LEN];
plarsd758be32002-11-01 15:59:31 +000083
subrata_modak56207ce2009-03-23 13:35:39 +000084int main(int ac, char **av)
plarsd758be32002-11-01 15:59:31 +000085{
86
subrata_modak56207ce2009-03-23 13:35:39 +000087 int lc; /* loop counter */
88 char *msg; /* message returned from parse_opts */
89
plarsd758be32002-11-01 15:59:31 +000090 /* parse standard options */
Garrett Cooper45e285d2010-11-22 12:19:25 -080091 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
plarsd758be32002-11-01 15:59:31 +000092 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080093
plarsd758be32002-11-01 15:59:31 +000094 }
95
plarsd758be32002-11-01 15:59:31 +000096 setup();
97
subrata_modak56207ce2009-03-23 13:35:39 +000098 for (lc = 0; TEST_LOOPING(lc); lc++) {
plarsd758be32002-11-01 15:59:31 +000099
subrata_modak56207ce2009-03-23 13:35:39 +0000100 Tst_count = 0;
plarsd758be32002-11-01 15:59:31 +0000101
subrata_modak4bb656a2009-02-26 12:02:09 +0000102 /*
plarsd758be32002-11-01 15:59:31 +0000103 * Call setdomainname(2)
104 */
subrata_modak56207ce2009-03-23 13:35:39 +0000105 TEST(setdomainname(test_domain_name, sizeof(test_domain_name)));
subrata_modakbdbaec52009-02-26 12:14:51 +0000106
plarsd758be32002-11-01 15:59:31 +0000107 /* check return code */
subrata_modak56207ce2009-03-23 13:35:39 +0000108 if (TEST_RETURN == -1) {
plarsd758be32002-11-01 15:59:31 +0000109 tst_resm(TFAIL, "setdomainname() Failed, errno = %d :"
subrata_modak56207ce2009-03-23 13:35:39 +0000110 " %s", TEST_ERRNO, strerror(TEST_ERRNO));
plarsd758be32002-11-01 15:59:31 +0000111 } else {
subrata_modak923b23f2009-11-02 13:57:16 +0000112 tst_resm(TPASS, "setdomainname() returned %ld, "
plarsd758be32002-11-01 15:59:31 +0000113 "Domain name set to \"%s\"", TEST_RETURN,
114 test_domain_name);
subrata_modak4bb656a2009-02-26 12:02:09 +0000115 }
plarsd758be32002-11-01 15:59:31 +0000116
Garrett Cooper2c282152010-12-16 00:55:50 -0800117 }
plarsd758be32002-11-01 15:59:31 +0000118
119 /* cleanup and exit */
120 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800121 tst_exit();
plarsd758be32002-11-01 15:59:31 +0000122
Garrett Cooper2c282152010-12-16 00:55:50 -0800123}
plarsd758be32002-11-01 15:59:31 +0000124
125/* setup() - performs all ONE TIME setup for this test */
subrata_modak56207ce2009-03-23 13:35:39 +0000126void setup()
plarsd758be32002-11-01 15:59:31 +0000127{
subrata_modakbdbaec52009-02-26 12:14:51 +0000128
plarsd758be32002-11-01 15:59:31 +0000129 tst_sig(NOFORK, DEF_HANDLER, cleanup);
130
subrata_modak56207ce2009-03-23 13:35:39 +0000131 /* Check whether we are root */
plarsd758be32002-11-01 15:59:31 +0000132 if (geteuid() != 0) {
Garrett Cooper53740502010-12-16 00:04:01 -0800133 tst_brkm(TBROK, NULL, "Test must be run as root");
plarsd758be32002-11-01 15:59:31 +0000134 }
135
subrata_modak4bb656a2009-02-26 12:02:09 +0000136 /* Save current domain name */
subrata_modak56207ce2009-03-23 13:35:39 +0000137 if ((getdomainname(old_domain_name, sizeof(old_domain_name))) < 0) {
Garrett Cooper53740502010-12-16 00:04:01 -0800138 tst_brkm(TBROK, NULL, "getdomainname() failed while"
subrata_modakbdbaec52009-02-26 12:14:51 +0000139 " getting current domain name");
plarsd758be32002-11-01 15:59:31 +0000140 }
141
plarsd758be32002-11-01 15:59:31 +0000142 TEST_PAUSE;
143
Garrett Cooper2c282152010-12-16 00:55:50 -0800144}
plarsd758be32002-11-01 15:59:31 +0000145
subrata_modak4bb656a2009-02-26 12:02:09 +0000146/*
plarsd758be32002-11-01 15:59:31 +0000147 *cleanup() - performs all ONE TIME cleanup for this test at
148 * completion or premature exit.
149 */
subrata_modak56207ce2009-03-23 13:35:39 +0000150void cleanup()
plarsd758be32002-11-01 15:59:31 +0000151{
152
153 /*
154 * print timing stats if that option was specified.
155 * print errno log if that option was specified.
156 */
157 TEST_CLEANUP;
158
159 /* Restore domain name */
subrata_modak56207ce2009-03-23 13:35:39 +0000160 if ((setdomainname(old_domain_name, strlen(old_domain_name))) < 0) {
plarsd758be32002-11-01 15:59:31 +0000161 tst_resm(TWARN, "setdomainname() failed while restoring"
subrata_modak56207ce2009-03-23 13:35:39 +0000162 " domainname to \"%s\"", old_domain_name);
plarsd758be32002-11-01 15:59:31 +0000163 }
164
Chris Dearmanec6edca2012-10-17 19:54:01 -0700165}