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 <chrubis@suse.cz>
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
50 static const char *const resource_files[] = {
51 TEST_APP,
52 NULL,
53 };
54
55 static struct tst_test test = {
56 .test_all = verify_creat,
57 .needs_checkpoints = 1,
58 .forks_child = 1,
59 .resource_files = resource_files,
60 };
61