Drop main() prototype. Syncs with NetBSD-8
[minix.git] / tests / fs / nfs / t_mountd.c
blobb6c15287791c78ab1c262fe814bc5754e5cfbb16
1 /* $NetBSD: t_mountd.c,v 1.5 2012/02/24 13:53:46 joerg Exp $ */
3 /*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
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.
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.
28 #include <sys/types.h>
29 #include <sys/mount.h>
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>
41 #include <rump/rump.h>
42 #include <rump/rump_syscalls.h>
44 #include "../../h_macros.h"
45 #include "../common/h_fsmacros.h"
47 ATF_TC(mountdhup);
48 ATF_TC_HEAD(mountdhup, tc)
51 atf_tc_set_md_var(tc, "descr", "test for service interrupt while "
52 "mountd handles SIGHUP");
55 static volatile int quit;
57 static void *
58 wrkwrkwrk(void *unused)
60 int fd, fail;
62 fail = 0;
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;
73 rump_sys_close(fd);
74 if (rump_sys_unlink("file") == -1) {
75 if (errno == EACCES) {
76 fail++;
77 break;
81 rump_sys_chdir("/");
82 quit = 1;
84 return fail ? wrkwrkwrk : NULL;
87 ATF_TC_BODY(mountdhup, tc)
89 pthread_t pt;
90 struct nfstestargs *nfsargs;
91 void *voidargs;
92 int attempts;
93 void *fail;
95 FSTEST_CONSTRUCTOR(tc, nfs, voidargs);
96 nfsargs = voidargs;
98 pthread_create(&pt, NULL, wrkwrkwrk, NULL);
99 for (attempts = 100; attempts && !quit; attempts--) {
100 usleep(100000);
101 kill(nfsargs->ta_childpid, SIGHUP);
103 quit = 1;
104 pthread_join(pt, &fail);
106 FSTEST_DESTRUCTOR(tc, nfs, voidargs);
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");
115 ATF_TP_ADD_TCS(tp)
118 ATF_TP_ADD_TC(tp, mountdhup);
120 return atf_no_error();