plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 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 Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 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> |
robbiew | 2c94524 | 2002-11-11 19:01:25 +0000 | [diff] [blame] | 50 | #include <fcntl.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 51 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 52 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 53 | char *TCID = "creat03"; |
| 54 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 55 | |
| 56 | char pfilname[40] = ""; |
| 57 | #define FMODE 0444 |
| 58 | |
| 59 | void setup(void); |
| 60 | void cleanup(void); |
| 61 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 62 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 63 | { |
| 64 | struct stat statbuf; |
| 65 | unsigned short filmode; |
Garrett Cooper | 87bc45c | 2010-12-17 01:56:08 -0800 | [diff] [blame] | 66 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 67 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 68 | |
Garrett Cooper | 87bc45c | 2010-12-17 01:56:08 -0800 | [diff] [blame] | 69 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 70 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 71 | |
| 72 | setup(); |
| 73 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 74 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 75 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 76 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 77 | |
| 78 | TEST(creat(pfilname, FMODE)); |
| 79 | |
| 80 | if (TEST_RETURN == -1) { |
| 81 | tst_resm(TFAIL, "Cannot creat %s", pfilname); |
| 82 | continue; |
Garrett Cooper | 87bc45c | 2010-12-17 01:56:08 -0800 | [diff] [blame] | 83 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 84 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 85 | 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"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 92 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 93 | tst_resm(TPASS, "save text bit cleared"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 94 | } |
| 95 | |
subrata_modak | dad6e1a | 2007-10-30 10:46:58 +0000 | [diff] [blame] | 96 | close(TEST_RETURN); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | /* clean up things in case we are looping */ |
| 98 | if (unlink(pfilname) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 99 | tst_brkm(TBROK | TERRNO, cleanup, |
| 100 | "couldn't remove file"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 103 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 104 | cleanup(); |
Garrett Cooper | 87bc45c | 2010-12-17 01:56:08 -0800 | [diff] [blame] | 105 | tst_exit(); |
Garrett Cooper | 87bc45c | 2010-12-17 01:56:08 -0800 | [diff] [blame] | 106 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 107 | |
| 108 | /* |
| 109 | * setup() - performs all ONE TIME setup for this test |
| 110 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 111 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 112 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 113 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 114 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 115 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 116 | 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_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 128 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 129 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 130 | tst_rmdir(); |
| 131 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 132 | } |