1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) International Business Machines Corp., 2001
4 * Copyright (c) 2012-2016 Cyril Hrubis <[email protected]>
5 */
6
7 /*
8 * Testcase to check creat(2) sets ETXTBSY correctly.
9 */
10
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <sys/wait.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <errno.h>
17 #include <fcntl.h>
18 #include "tst_test.h"
19
20 #define TEST_APP "creat07_child"
21
verify_creat(void)22 static void verify_creat(void)
23 {
24 pid_t pid;
25
26 pid = SAFE_FORK();
27 if (pid == 0) {
28 SAFE_EXECL(TEST_APP, TEST_APP, NULL);
29 exit(1);
30 }
31
32 TST_CHECKPOINT_WAIT(0);
33
34 TEST(creat(TEST_APP, O_WRONLY));
35
36 if (TST_RET != -1) {
37 tst_res(TFAIL, "creat() succeeded unexpectedly");
38 return;
39 }
40
41 if (TST_ERR == ETXTBSY)
42 tst_res(TPASS, "creat() received EXTBSY");
43 else
44 tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
45
46 SAFE_KILL(pid, SIGKILL);
47 SAFE_WAITPID(pid, NULL, 0);
48 }
49
setup(void)50 static void setup(void)
51 {
52 if ((tst_kvercmp(6, 11, 0)) >= 0) {
53 tst_brk(TCONF, "Skipping test, write to executed file is "
54 "allowed since 6.11-rc1.\n"
55 "2a010c412853 (\"fs: don't block i_writecount during exec\")");
56 }
57 }
58
59 static struct tst_test test = {
60 .setup = setup,
61 .test_all = verify_creat,
62 .needs_checkpoints = 1,
63 .forks_child = 1,
64 .resource_files = (const char *const []) {
65 TEST_APP,
66 NULL
67 }
68 };
69