• 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 		SAFE_EXECL(TEST_APP, TEST_APP, NULL);
42 		exit(1);
43 	}
44 
45 	TST_CHECKPOINT_WAIT(0);
46 
47 	TEST(creat(TEST_APP, O_WRONLY));
48 
49 	if (TST_RET != -1) {
50 		tst_res(TFAIL, "creat() succeeded unexpectedly");
51 		return;
52 	}
53 
54 	if (TST_ERR == ETXTBSY)
55 		tst_res(TPASS, "creat() received EXTBSY");
56 	else
57 		tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
58 
59 	SAFE_KILL(pid, SIGKILL);
60 	SAFE_WAITPID(pid, NULL, 0);
61 }
62 
63 static const char *const resource_files[] = {
64 	TEST_APP,
65 	NULL,
66 };
67 
68 static struct tst_test test = {
69 	.test_all = verify_creat,
70 	.needs_checkpoints = 1,
71 	.forks_child = 1,
72 	.resource_files = resource_files,
73 };
74