• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) International Business Machines  Corp., 2001
3  * Copyright (c) 2012-2016 Cyril Hrubis <chrubis@suse.cz>
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
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /*
21  * Testcase to check creat(2) sets ETXTBSY correctly.
22  */
23 
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <sys/wait.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <errno.h>
30 #include <fcntl.h>
31 #include "tst_test.h"
32 
33 #define TEST_APP "creat07_child"
34 
verify_creat(void)35 static void verify_creat(void)
36 {
37 	pid_t pid;
38 
39 	pid = SAFE_FORK();
40 	if (pid == 0) {
41 		char *av[] = {TEST_APP, NULL};
42 		(void)execve(TEST_APP, av, tst_ipc_envp);
43 		perror("execve failed");
44 		exit(1);
45 	}
46 
47 	TST_CHECKPOINT_WAIT(0);
48 
49 	TEST(creat(TEST_APP, O_WRONLY));
50 
51 	if (TEST_RETURN != -1) {
52 		tst_res(TFAIL, "creat() succeeded unexpectedly");
53 		return;
54 	}
55 
56 	if (TEST_ERRNO == ETXTBSY)
57 		tst_res(TPASS, "creat() received EXTBSY");
58 	else
59 		tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
60 
61 	SAFE_KILL(pid, SIGKILL);
62 	SAFE_WAITPID(pid, NULL, 0);
63 }
64 
65 static const char *const resource_files[] = {
66 	TEST_APP,
67 	NULL,
68 };
69 
70 static struct tst_test test = {
71 	.tid = "creat07",
72 	.test_all = verify_creat,
73 	.needs_checkpoints = 1,
74 	.forks_child = 1,
75 	.resource_files = resource_files,
76 };
77