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