blob: a02fc6e68980895809824697771d70dbf46319c3 [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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * NAME
22 * creat03.c
23 *
24 * DESCRIPTION
25 * Testcase to check whether the sticky bit cleared.
26 *
27 * ALGORITHM
28 * Creat a new file, fstat.st_mode should have the 01000 bit off
29 *
30 * USAGE: <for command-line>
31 * creat03 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
32 * where, -c n : Run n copies concurrently.
33 * -f : Turn off functionality Testing.
34 * -i n : Execute test n times.
35 * -I x : Execute test for x seconds.
36 * -P x : Pause for x seconds between iterations.
37 * -t : Turn on syscall timing.
38 *
39 * HISTORY
40 * 07/2001 Ported by Wayne Boyer
41 *
42 * RESTRICTIONS
43 * None
44 */
45
46#include <errno.h>
47#include <stdio.h>
48#include <sys/types.h>
49#include <sys/stat.h>
robbiew2c945242002-11-11 19:01:25 +000050#include <fcntl.h>
plars865695b2001-08-27 22:15:12 +000051#include "test.h"
plars865695b2001-08-27 22:15:12 +000052
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020053char *TCID = "creat03";
54int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000055
56char pfilname[40] = "";
57#define FMODE 0444
58
59void setup(void);
60void cleanup(void);
61
subrata_modak56207ce2009-03-23 13:35:39 +000062int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000063{
64 struct stat statbuf;
65 unsigned short filmode;
Garrett Cooper87bc45c2010-12-17 01:56:08 -080066 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020067 const char *msg;
plars865695b2001-08-27 22:15:12 +000068
Garrett Cooper87bc45c2010-12-17 01:56:08 -080069 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080070 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000071
72 setup();
73
plars865695b2001-08-27 22:15:12 +000074 for (lc = 0; TEST_LOOPING(lc); lc++) {
75
Caspar Zhangd59a6592013-03-07 14:59:12 +080076 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000077
78 TEST(creat(pfilname, FMODE));
79
80 if (TEST_RETURN == -1) {
81 tst_resm(TFAIL, "Cannot creat %s", pfilname);
82 continue;
Garrett Cooper87bc45c2010-12-17 01:56:08 -080083 }
plars865695b2001-08-27 22:15:12 +000084
Cyril Hrubise38b9612014-06-02 17:20:57 +020085 if (fstat(TEST_RETURN, &statbuf) == -1) {
86 tst_brkm(TBROK, cleanup, "fstat() failed");
87 }
88 filmode = statbuf.st_mode;
89 tst_resm(TINFO, "Created file has mode = 0%o", filmode);
90 if ((filmode & S_ISVTX) != 0) {
91 tst_resm(TFAIL, "save text bit not cleared");
plars865695b2001-08-27 22:15:12 +000092 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +020093 tst_resm(TPASS, "save text bit cleared");
plars865695b2001-08-27 22:15:12 +000094 }
95
subrata_modakdad6e1a2007-10-30 10:46:58 +000096 close(TEST_RETURN);
plars865695b2001-08-27 22:15:12 +000097 /* clean up things in case we are looping */
98 if (unlink(pfilname) == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080099 tst_brkm(TBROK | TERRNO, cleanup,
100 "couldn't remove file");
plars865695b2001-08-27 22:15:12 +0000101 }
102 }
Cyril Hrubise38b9612014-06-02 17:20:57 +0200103
plars865695b2001-08-27 22:15:12 +0000104 cleanup();
Garrett Cooper87bc45c2010-12-17 01:56:08 -0800105 tst_exit();
Garrett Cooper87bc45c2010-12-17 01:56:08 -0800106}
plars865695b2001-08-27 22:15:12 +0000107
108/*
109 * setup() - performs all ONE TIME setup for this test
110 */
subrata_modak56207ce2009-03-23 13:35:39 +0000111void setup(void)
plars865695b2001-08-27 22:15:12 +0000112{
Garrett Cooper2c282152010-12-16 00:55:50 -0800113
plars865695b2001-08-27 22:15:12 +0000114 tst_sig(NOFORK, DEF_HANDLER, cleanup);
115
plars865695b2001-08-27 22:15:12 +0000116 TEST_PAUSE;
117
118 /* make a temp dir and cd to it */
119 tst_tmpdir();
120
121 sprintf(pfilname, "./creat4.%d", getpid());
122}
123
124/*
125 * cleanup() - performs all ONE TIME cleanup for this test at completion or
126 * premature exit
127 */
subrata_modak56207ce2009-03-23 13:35:39 +0000128void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000129{
plars865695b2001-08-27 22:15:12 +0000130 tst_rmdir();
131
Chris Dearmanec6edca2012-10-17 19:54:01 -0700132}