1 /* $NetBSD: t_mountd.c,v 1.2 2010/08/01 15:38:27 pooka 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 40 #include <rump/rump.h> 41 #include <rump/rump_syscalls.h> 42 43 #include "../../h_macros.h" 44 #include "../common/h_fsmacros.h" 45 46 ATF_TC(mountdhup); 47 ATF_TC_HEAD(mountdhup, tc) 48 { 49 50 atf_tc_set_md_var(tc, "descr", "test for service interrupt while " 51 "mountd handles SIGHUP"); 52 atf_tc_set_md_var(tc, "use.fs", "true"); 53 } 54 55 static volatile int quit; 56 57 static void * 58 wrkwrkwrk(void *unused) 59 { 60 int fd, fail; 61 62 rump_sys_chdir(FSTEST_MNTNAME); 63 while (!quit) { 64 fd = rump_sys_open("file", O_RDWR | O_CREAT); 65 if (fd == -1) { 66 if (errno == EACCES) { 67 fail++; 68 break; 69 } 70 } 71 rump_sys_close(fd); 72 if (rump_sys_unlink("file") == -1) { 73 if (errno == EACCES) { 74 fail++; 75 break; 76 } 77 } 78 } 79 rump_sys_chdir("/"); 80 quit = 1; 81 82 return fail ? &fail : NULL; 83 } 84 85 ATF_TC_BODY(mountdhup, tc) 86 { 87 pthread_t pt; 88 struct nfstestargs *nfsargs; 89 void *voidargs; 90 int attempts; 91 void *fail; 92 93 FSTEST_CONSTRUCTOR(tc, nfs, voidargs); 94 nfsargs = voidargs; 95 96 pthread_create(&pt, NULL, wrkwrkwrk, NULL); 97 for (attempts = 100; attempts && !quit; attempts--) { 98 usleep(100000); 99 kill(nfsargs->ta_childpid, SIGHUP); 100 } 101 quit = 1; 102 pthread_join(pt, &fail); 103 104 FSTEST_DESTRUCTOR(tc, nfs, voidargs); 105 106 atf_tc_expect_fail("PR kern/5844"); 107 if (fail) 108 atf_tc_fail("op failed with EACCES"); 109 else 110 atf_tc_fail("race did not trigger this time"); 111 } 112 113 ATF_TP_ADD_TCS(tp) 114 { 115 116 ATF_TP_ADD_TC(tp, mountdhup); 117 118 return atf_no_error(); 119 } 120