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 | * umask02.c |
| 23 | * |
| 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> |
| 33 | * umask02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] |
| 34 | * where, -c n : Run n copies concurrently. |
| 35 | * -e : Turn on errno logging. |
| 36 | * -i n : Execute test n times. |
| 37 | * -I x : Execute test for x seconds. |
| 38 | * -P x : Pause for x seconds between iterations. |
| 39 | * -t : Turn on syscall timing. |
| 40 | * |
| 41 | * History |
| 42 | * 07/2001 John George |
| 43 | * -Ported |
| 44 | * |
| 45 | * Restrictions |
| 46 | * None |
| 47 | */ |
| 48 | |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 49 | #include <sys/types.h> |
| 50 | #include <sys/stat.h> |
| 51 | #include <fcntl.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 52 | #include <stdio.h> |
| 53 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 54 | |
| 55 | char *TCID = "umask02"; |
| 56 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 57 | |
| 58 | void setup(void); |
| 59 | void cleanup(void); |
| 60 | |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 61 | int main(int argc, char **argv) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 62 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 63 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 64 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | |
| 66 | int uret = 0, i, mskval = 0000; |
plars | c11fb73 | 2003-07-08 18:51:04 +0000 | [diff] [blame] | 67 | int failcnt = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 68 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 69 | if ((msg = parse_opts(argc, argv, 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); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 71 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 72 | |
| 73 | setup(); |
| 74 | |
| 75 | /* Check for looping state if -i option is given */ |
| 76 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 77 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 78 | /* reset tst_count in case we are looping */ |
| 79 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 80 | |
| 81 | for (umask(++mskval), i = 1; mskval < 01000; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 82 | uret = umask(++mskval), i++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 83 | if ((uret != mskval - 1) && (mskval != 0000)) { |
plars | c11fb73 | 2003-07-08 18:51:04 +0000 | [diff] [blame] | 84 | failcnt = 1; |
| 85 | tst_resm(TFAIL, "umask(%d) returned bad mask " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 86 | "value %d.", mskval, uret); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | } |
| 88 | } |
plars | c11fb73 | 2003-07-08 18:51:04 +0000 | [diff] [blame] | 89 | if (!failcnt) |
| 90 | tst_resm(TPASS, "All umask values return correct " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 91 | "values"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 92 | } |
| 93 | cleanup(); |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 94 | tst_exit(); |
robbiew | 9a66de1 | 2003-03-27 22:16:14 +0000 | [diff] [blame] | 95 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /* |
| 99 | * setup() |
| 100 | * performs all ONE TIME setup for this test |
| 101 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 102 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 103 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 104 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 105 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 106 | |
| 107 | /* Pause if that option was specified |
| 108 | * TEST_PAUSE contains the code to fork the test with the -c option. |
| 109 | */ |
| 110 | TEST_PAUSE; |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * cleanup() |
| 115 | * performs all ONE TIME cleanup for this test at |
| 116 | * completion or premature exit |
| 117 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 118 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 119 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 120 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 121 | } |