plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 2 | * Copyright (c) International Business Machines Corp., 2001 |
| 3 | * Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 4 | * |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 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. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 9 | * |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 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. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 14 | * |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 21 | * Testcase to check creat(2) sets ETXTBSY correctly. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
Garrett Cooper | c585a27 | 2010-12-20 03:04:07 -0800 | [diff] [blame] | 24 | #ifndef _GNU_SOURCE |
| 25 | #define _GNU_SOURCE |
| 26 | #endif |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 27 | #include <sys/types.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 28 | #include <sys/stat.h> |
plars | 4d1ce60 | 2001-09-12 16:23:42 +0000 | [diff] [blame] | 29 | #include <sys/wait.h> |
Garrett Cooper | c585a27 | 2010-12-20 03:04:07 -0800 | [diff] [blame] | 30 | #include <errno.h> |
| 31 | #include <fcntl.h> |
| 32 | #include <libgen.h> |
| 33 | #include <stdio.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 35 | |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 36 | #define TEST_APP "creat07_child" |
Garrett Cooper | 87bc45c | 2010-12-17 01:56:08 -0800 | [diff] [blame] | 37 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 38 | char *TCID = "creat07"; |
| 39 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 40 | |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 41 | static void setup(char *); |
| 42 | static void cleanup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 43 | |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 44 | static struct tst_checkpoint checkpoint; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 45 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 46 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 47 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 48 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 49 | const char *msg; |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 50 | pid_t pid; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 51 | |
Garrett Cooper | 87bc45c | 2010-12-17 01:56:08 -0800 | [diff] [blame] | 52 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 53 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 54 | |
Garrett Cooper | 87bc45c | 2010-12-17 01:56:08 -0800 | [diff] [blame] | 55 | setup(av[0]); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 56 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 57 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 58 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 59 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 60 | |
Garrett Cooper | 87bc45c | 2010-12-17 01:56:08 -0800 | [diff] [blame] | 61 | if ((pid = FORK_OR_VFORK()) == -1) |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 62 | tst_brkm(TBROK|TERRNO, cleanup, "fork #1 failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 63 | |
Garrett Cooper | 87bc45c | 2010-12-17 01:56:08 -0800 | [diff] [blame] | 64 | if (pid == 0) { |
Salvatore CRO | 76c4c80 | 2012-02-01 15:38:34 +0100 | [diff] [blame] | 65 | char *av[2]; |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 66 | av[0] = TEST_APP; |
Salvatore CRO | 76c4c80 | 2012-02-01 15:38:34 +0100 | [diff] [blame] | 67 | av[1] = NULL; |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 68 | (void)execve(TEST_APP, av, NULL); |
Garrett Cooper | 87bc45c | 2010-12-17 01:56:08 -0800 | [diff] [blame] | 69 | perror("execve failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | exit(1); |
| 71 | } |
| 72 | |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 73 | TST_CHECKPOINT_PARENT_WAIT(NULL, &checkpoint); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 74 | |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 75 | TEST(creat(TEST_APP, O_WRONLY)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 77 | if (TEST_RETURN != -1) { |
| 78 | tst_resm(TFAIL, "creat succeeded"); |
| 79 | } else { |
| 80 | if (TEST_ERRNO == ETXTBSY) |
| 81 | tst_resm(TPASS, "creat received EXTBSY"); |
| 82 | else |
| 83 | tst_resm(TFAIL | TTERRNO, "creat failed with " |
| 84 | "unexpected error"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 85 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 86 | |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 87 | if (kill(pid, SIGKILL) == -1) |
| 88 | tst_resm(TINFO | TERRNO, "kill failed"); |
| 89 | |
| 90 | if (wait(NULL) == -1) |
| 91 | tst_brkm(TBROK|TERRNO, cleanup, "wait failed"); |
| 92 | } |
| 93 | |
| 94 | cleanup(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 95 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 98 | static void setup(char *app) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 99 | { |
Garrett Cooper | fb89b0a | 2010-12-20 01:58:23 -0800 | [diff] [blame] | 100 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 101 | |
subrata_modak | 4ce69a5 | 2008-11-13 11:28:28 +0000 | [diff] [blame] | 102 | tst_tmpdir(); |
| 103 | |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 104 | TST_RESOURCE_COPY(cleanup, TEST_APP, NULL); |
| 105 | |
Jan Stancek | 4caa631 | 2014-10-06 14:57:56 +0200 | [diff] [blame] | 106 | TST_CHECKPOINT_CREATE(&checkpoint); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 107 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 108 | TEST_PAUSE; |
| 109 | } |
| 110 | |
Cyril Hrubis | 3e5f790 | 2012-12-12 17:28:29 +0100 | [diff] [blame] | 111 | static void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 112 | { |
subrata_modak | 4ce69a5 | 2008-11-13 11:28:28 +0000 | [diff] [blame] | 113 | tst_rmdir(); |
Garrett Cooper | fb89b0a | 2010-12-20 01:58:23 -0800 | [diff] [blame] | 114 | } |