blob: 3863dce9797ffc035795a4ccc52dbdec4f4db000 [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
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20/*
21 * NAME
nstrazfa31d552002-05-14 16:50:06 +000022 * umask03.c
plars865695b2001-08-27 22:15:12 +000023 *
24 * DESCRIPTION
25 * Check that umask changes the mask, and that the previous
26 * value of the mask is returned correctly for each value.
27 *
28 * ALGORITHM
29 * For each mask value (9 bits) set mask, and check that the return
30 * corresponds to the previous value set.
31 *
32 * USAGE: <for command-line>
nstrazfa31d552002-05-14 16:50:06 +000033 * umask03 [-c n] [-i n] [-I x] [-P x] [-t]
plars865695b2001-08-27 22:15:12 +000034 * where, -c n : Run n copies concurrently.
35 * -i n : Execute test n times.
36 * -I x : Execute test for x seconds.
37 * -P x : Pause for x seconds between iterations.
38 * -t : Turn on syscall timing.
39 *
40 * History
41 * 07/2001 John George
42 * -Ported
43 *
44 * Restrictions
45 * None
46 */
47
48#include <stdio.h>
49#include "test.h"
50#include "usctest.h"
51#include <sys/types.h>
52#include <sys/stat.h>
53
nstrazfa31d552002-05-14 16:50:06 +000054char *TCID = "umask03";
plars865695b2001-08-27 22:15:12 +000055int TST_TOTAL = 1;
56extern int Tst_count;
57
58char filname[40];
59
60void setup(void);
61void cleanup(void);
62
63main(int argc, char **argv)
64{
65 int lc;
66 char *msg;
67
68 struct stat statbuf;
69 int mskval = 0000;
70 int fildes, i;
71 unsigned low9mode;
72
73 /* parse standard options */
74 if ((msg = parse_opts(argc, argv, (option_t *) NULL, NULL))
75 != (char *) NULL) {
76 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
77 /*NOTREACHED*/
78 }
79
80 setup(); /* global setup */
81
82 /* check looping state if -i option is given */
83 for (lc = 0; TEST_LOOPING(lc); lc++) {
84
85 /* reset Tst_count in case we are looping */
86 Tst_count = 0;
87
88 for (umask(mskval = 0077), i = 1; mskval < 01000;
89 i++, umask(++mskval)) {
90 unlink(filname);
91 if ((fildes = creat(filname, 0777)) == -1) {
92 tst_resm(TBROK, "cannot create "
93 "file with mskval 0%o %d",
94 mskval, mskval);
95 } else {
96 if (fstat(fildes, &statbuf) != 0) {
97 tst_resm(TBROK, "cannot fstat file");
98 } else {
99 low9mode = statbuf.st_mode & 0777;
100 if (low9mode != (~mskval & 0777)) {
101 tst_brkm(TBROK, cleanup,
102 "got %0 expected %o"
103 "mask didnot take",
104 low9mode,
105 (~mskval & 0777));
106 /*NOTREACHED*/
107 } else {
108 tst_resm(TPASS, "Test "
109 "condition: %d, umask: "
110 "0%o", i, mskval);
111 }
112 }
113 }
114 close(fildes);
115 }
116 }
117 cleanup();
118 /*NOTREACHED*/
119}
120
121/*
122 * setup
123 * performs all ONE TIME setup for this test
124 */
125void
126setup()
127{
128 /* capture signals */
129 tst_sig(NOFORK, DEF_HANDLER, cleanup);
130
131
132 /* Pause if that option was specified
133 * TEST_PAUSE contains the code to fork the test with the -i option.
134 * You want to make sure you do this before you create your temporary
135 * directory.
136 */
137 TEST_PAUSE;
138
139 /* make temp dir and cd to it */
140 tst_tmpdir();
141
142 sprintf(filname, "umask2.%d", getpid());
143}
144
145/*
146 * cleanup
147 * performs all ONE TIME cleanup for this test at completion or
148 * premature exit
149 */
150void
151cleanup()
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 /*
160 * cleanup the temporary files and the temporary directory
161 */
162 unlink(filname);
163 tst_rmdir();
164
165 /*
166 * exit with return code appropriate for results
167 */
168 tst_exit();
169}