1 /* $NetBSD: t_rmdirrace.c,v 1.9 2012/02/16 02:47:56 perseant Exp $ */
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
40 #include <rump/rump_syscalls.h>
41 #include <rump/rump.h>
43 #include "../common/h_fsmacros.h"
45 #define DIRNAME "rmdir.test"
47 static void *func1(void *arg
)
50 while (*(int *)arg
!= 1)
51 rump_sys_mkdir(DIRNAME
, 0755);
56 static void *func2(void *arg
)
59 while (*(int *)arg
!= 1)
60 rump_sys_rmdir(DIRNAME
);
66 race(const atf_tc_t
*tc
, const char *path
)
71 if (FSTYPE_SYSVBFS(tc
))
72 atf_tc_skip("directories not supported by file system");
74 fd
= rump_sys_open(".", O_RDONLY
, 0666);
76 atf_tc_fail("open failed");
77 res
= rump_sys_chdir(path
);
79 atf_tc_fail("chdir failed");
83 res
= pthread_create(&th1
, NULL
, func1
, &quit
);
85 atf_tc_fail("pthread_create1 failed");
86 res
= pthread_create(&th2
, NULL
, func2
, &quit
);
88 atf_tc_fail("pthread_create2 failed");
94 res
= pthread_join(th2
, NULL
);
96 atf_tc_fail("pthread_join2 failed");
97 res
= pthread_join(th1
, NULL
);
99 atf_tc_fail("pthread_join1 failed");
101 res
= rump_sys_fchdir(fd
);
103 atf_tc_fail("fchdir failed");
106 ATF_FSAPPLY(race
, "rmdir(2) race");