xref: /minix3/tests/fs/nfs/t_mountd.c (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc /*	$NetBSD: t_mountd.c,v 1.5 2012/02/24 13:53:46 joerg Exp $	*/
2*11be35a1SLionel Sambuc 
3*11be35a1SLionel Sambuc /*-
4*11be35a1SLionel Sambuc  * Copyright (c) 2010 The NetBSD Foundation, Inc.
5*11be35a1SLionel Sambuc  *
6*11be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
7*11be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
8*11be35a1SLionel Sambuc  * are met:
9*11be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
10*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
11*11be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
12*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
13*11be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
14*11be35a1SLionel Sambuc  *
15*11be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16*11be35a1SLionel Sambuc  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17*11be35a1SLionel Sambuc  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18*11be35a1SLionel Sambuc  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*11be35a1SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*11be35a1SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21*11be35a1SLionel Sambuc  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*11be35a1SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*11be35a1SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*11be35a1SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*11be35a1SLionel Sambuc  * SUCH DAMAGE.
26*11be35a1SLionel Sambuc  */
27*11be35a1SLionel Sambuc 
28*11be35a1SLionel Sambuc #include <sys/types.h>
29*11be35a1SLionel Sambuc #include <sys/mount.h>
30*11be35a1SLionel Sambuc 
31*11be35a1SLionel Sambuc #include <atf-c.h>
32*11be35a1SLionel Sambuc #include <errno.h>
33*11be35a1SLionel Sambuc #include <fcntl.h>
34*11be35a1SLionel Sambuc #include <pthread.h>
35*11be35a1SLionel Sambuc #include <stdio.h>
36*11be35a1SLionel Sambuc #include <stdlib.h>
37*11be35a1SLionel Sambuc #include <unistd.h>
38*11be35a1SLionel Sambuc #include <string.h>
39*11be35a1SLionel Sambuc #include <signal.h>
40*11be35a1SLionel Sambuc 
41*11be35a1SLionel Sambuc #include <rump/rump.h>
42*11be35a1SLionel Sambuc #include <rump/rump_syscalls.h>
43*11be35a1SLionel Sambuc 
44*11be35a1SLionel Sambuc #include "../../h_macros.h"
45*11be35a1SLionel Sambuc #include "../common/h_fsmacros.h"
46*11be35a1SLionel Sambuc 
47*11be35a1SLionel Sambuc ATF_TC(mountdhup);
ATF_TC_HEAD(mountdhup,tc)48*11be35a1SLionel Sambuc ATF_TC_HEAD(mountdhup, tc)
49*11be35a1SLionel Sambuc {
50*11be35a1SLionel Sambuc 
51*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "test for service interrupt while "
52*11be35a1SLionel Sambuc 	    "mountd handles SIGHUP");
53*11be35a1SLionel Sambuc }
54*11be35a1SLionel Sambuc 
55*11be35a1SLionel Sambuc static volatile int quit;
56*11be35a1SLionel Sambuc 
57*11be35a1SLionel Sambuc static void *
wrkwrkwrk(void * unused)58*11be35a1SLionel Sambuc wrkwrkwrk(void *unused)
59*11be35a1SLionel Sambuc {
60*11be35a1SLionel Sambuc 	int fd, fail;
61*11be35a1SLionel Sambuc 
62*11be35a1SLionel Sambuc 	fail = 0;
63*11be35a1SLionel Sambuc 
64*11be35a1SLionel Sambuc 	rump_sys_chdir(FSTEST_MNTNAME);
65*11be35a1SLionel Sambuc 	while (!quit) {
66*11be35a1SLionel Sambuc 		fd = rump_sys_open("file", O_RDWR | O_CREAT);
67*11be35a1SLionel Sambuc 		if (fd == -1) {
68*11be35a1SLionel Sambuc 			if (errno == EACCES) {
69*11be35a1SLionel Sambuc 				fail++;
70*11be35a1SLionel Sambuc 				break;
71*11be35a1SLionel Sambuc 			}
72*11be35a1SLionel Sambuc 		}
73*11be35a1SLionel Sambuc 		rump_sys_close(fd);
74*11be35a1SLionel Sambuc 		if (rump_sys_unlink("file") == -1) {
75*11be35a1SLionel Sambuc 			if (errno == EACCES) {
76*11be35a1SLionel Sambuc 				fail++;
77*11be35a1SLionel Sambuc 				break;
78*11be35a1SLionel Sambuc 			}
79*11be35a1SLionel Sambuc 		}
80*11be35a1SLionel Sambuc 	}
81*11be35a1SLionel Sambuc 	rump_sys_chdir("/");
82*11be35a1SLionel Sambuc 	quit = 1;
83*11be35a1SLionel Sambuc 
84*11be35a1SLionel Sambuc 	return fail ? wrkwrkwrk : NULL;
85*11be35a1SLionel Sambuc }
86*11be35a1SLionel Sambuc 
ATF_TC_BODY(mountdhup,tc)87*11be35a1SLionel Sambuc ATF_TC_BODY(mountdhup, tc)
88*11be35a1SLionel Sambuc {
89*11be35a1SLionel Sambuc 	pthread_t pt;
90*11be35a1SLionel Sambuc 	struct nfstestargs *nfsargs;
91*11be35a1SLionel Sambuc 	void *voidargs;
92*11be35a1SLionel Sambuc 	int attempts;
93*11be35a1SLionel Sambuc 	void *fail;
94*11be35a1SLionel Sambuc 
95*11be35a1SLionel Sambuc 	FSTEST_CONSTRUCTOR(tc, nfs, voidargs);
96*11be35a1SLionel Sambuc 	nfsargs = voidargs;
97*11be35a1SLionel Sambuc 
98*11be35a1SLionel Sambuc 	pthread_create(&pt, NULL, wrkwrkwrk, NULL);
99*11be35a1SLionel Sambuc 	for (attempts = 100; attempts && !quit; attempts--) {
100*11be35a1SLionel Sambuc 		usleep(100000);
101*11be35a1SLionel Sambuc 		kill(nfsargs->ta_childpid, SIGHUP);
102*11be35a1SLionel Sambuc 	}
103*11be35a1SLionel Sambuc 	quit = 1;
104*11be35a1SLionel Sambuc 	pthread_join(pt, &fail);
105*11be35a1SLionel Sambuc 
106*11be35a1SLionel Sambuc 	FSTEST_DESTRUCTOR(tc, nfs, voidargs);
107*11be35a1SLionel Sambuc 
108*11be35a1SLionel Sambuc 	atf_tc_expect_fail("PR kern/5844");
109*11be35a1SLionel Sambuc 	if (fail)
110*11be35a1SLionel Sambuc 		atf_tc_fail("op failed with EACCES");
111*11be35a1SLionel Sambuc 	else
112*11be35a1SLionel Sambuc 		atf_tc_fail("race did not trigger this time");
113*11be35a1SLionel Sambuc }
114*11be35a1SLionel Sambuc 
ATF_TP_ADD_TCS(tp)115*11be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
116*11be35a1SLionel Sambuc {
117*11be35a1SLionel Sambuc 
118*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, mountdhup);
119*11be35a1SLionel Sambuc 
120*11be35a1SLionel Sambuc 	return atf_no_error();
121*11be35a1SLionel Sambuc }
122