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