xref: /freebsd/contrib/netbsd-tests/fs/nfs/t_mountd.c (revision 63d1fd59)
1*63d1fd59SEnji Cooper /*	$NetBSD: t_mountd.c,v 1.6 2017/01/13 21:30:40 christos Exp $	*/
257718be8SEnji Cooper 
357718be8SEnji Cooper /*-
457718be8SEnji Cooper  * Copyright (c) 2010 The NetBSD Foundation, Inc.
557718be8SEnji Cooper  *
657718be8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
757718be8SEnji Cooper  * modification, are permitted provided that the following conditions
857718be8SEnji Cooper  * are met:
957718be8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
1057718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
1157718be8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
1257718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
1357718be8SEnji Cooper  *    documentation and/or other materials provided with the distribution.
1457718be8SEnji Cooper  *
1557718be8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
1657718be8SEnji Cooper  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1757718be8SEnji Cooper  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1857718be8SEnji Cooper  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1957718be8SEnji Cooper  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2057718be8SEnji Cooper  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2157718be8SEnji Cooper  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2257718be8SEnji Cooper  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2357718be8SEnji Cooper  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2457718be8SEnji Cooper  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2557718be8SEnji Cooper  * SUCH DAMAGE.
2657718be8SEnji Cooper  */
2757718be8SEnji Cooper 
2857718be8SEnji Cooper #include <sys/types.h>
2957718be8SEnji Cooper #include <sys/mount.h>
3057718be8SEnji Cooper 
3157718be8SEnji Cooper #include <atf-c.h>
3257718be8SEnji Cooper #include <errno.h>
3357718be8SEnji Cooper #include <fcntl.h>
3457718be8SEnji Cooper #include <pthread.h>
3557718be8SEnji Cooper #include <stdio.h>
3657718be8SEnji Cooper #include <stdlib.h>
3757718be8SEnji Cooper #include <unistd.h>
3857718be8SEnji Cooper #include <string.h>
3957718be8SEnji Cooper #include <signal.h>
4057718be8SEnji Cooper 
4157718be8SEnji Cooper #include <rump/rump.h>
4257718be8SEnji Cooper #include <rump/rump_syscalls.h>
4357718be8SEnji Cooper 
44*63d1fd59SEnji Cooper #include "h_macros.h"
4557718be8SEnji Cooper #include "../common/h_fsmacros.h"
4657718be8SEnji Cooper 
4757718be8SEnji Cooper ATF_TC(mountdhup);
ATF_TC_HEAD(mountdhup,tc)4857718be8SEnji Cooper ATF_TC_HEAD(mountdhup, tc)
4957718be8SEnji Cooper {
5057718be8SEnji Cooper 
5157718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "test for service interrupt while "
5257718be8SEnji Cooper 	    "mountd handles SIGHUP");
5357718be8SEnji Cooper }
5457718be8SEnji Cooper 
5557718be8SEnji Cooper static volatile int quit;
5657718be8SEnji Cooper 
5757718be8SEnji Cooper static void *
wrkwrkwrk(void * unused)5857718be8SEnji Cooper wrkwrkwrk(void *unused)
5957718be8SEnji Cooper {
6057718be8SEnji Cooper 	int fd, fail;
6157718be8SEnji Cooper 
6257718be8SEnji Cooper 	fail = 0;
6357718be8SEnji Cooper 
6457718be8SEnji Cooper 	rump_sys_chdir(FSTEST_MNTNAME);
6557718be8SEnji Cooper 	while (!quit) {
6657718be8SEnji Cooper 		fd = rump_sys_open("file", O_RDWR | O_CREAT);
6757718be8SEnji Cooper 		if (fd == -1) {
6857718be8SEnji Cooper 			if (errno == EACCES) {
6957718be8SEnji Cooper 				fail++;
7057718be8SEnji Cooper 				break;
7157718be8SEnji Cooper 			}
7257718be8SEnji Cooper 		}
7357718be8SEnji Cooper 		rump_sys_close(fd);
7457718be8SEnji Cooper 		if (rump_sys_unlink("file") == -1) {
7557718be8SEnji Cooper 			if (errno == EACCES) {
7657718be8SEnji Cooper 				fail++;
7757718be8SEnji Cooper 				break;
7857718be8SEnji Cooper 			}
7957718be8SEnji Cooper 		}
8057718be8SEnji Cooper 	}
8157718be8SEnji Cooper 	rump_sys_chdir("/");
8257718be8SEnji Cooper 	quit = 1;
8357718be8SEnji Cooper 
8457718be8SEnji Cooper 	return fail ? wrkwrkwrk : NULL;
8557718be8SEnji Cooper }
8657718be8SEnji Cooper 
ATF_TC_BODY(mountdhup,tc)8757718be8SEnji Cooper ATF_TC_BODY(mountdhup, tc)
8857718be8SEnji Cooper {
8957718be8SEnji Cooper 	pthread_t pt;
9057718be8SEnji Cooper 	struct nfstestargs *nfsargs;
9157718be8SEnji Cooper 	void *voidargs;
9257718be8SEnji Cooper 	int attempts;
9357718be8SEnji Cooper 	void *fail;
9457718be8SEnji Cooper 
9557718be8SEnji Cooper 	FSTEST_CONSTRUCTOR(tc, nfs, voidargs);
9657718be8SEnji Cooper 	nfsargs = voidargs;
9757718be8SEnji Cooper 
9857718be8SEnji Cooper 	pthread_create(&pt, NULL, wrkwrkwrk, NULL);
9957718be8SEnji Cooper 	for (attempts = 100; attempts && !quit; attempts--) {
10057718be8SEnji Cooper 		usleep(100000);
10157718be8SEnji Cooper 		kill(nfsargs->ta_childpid, SIGHUP);
10257718be8SEnji Cooper 	}
10357718be8SEnji Cooper 	quit = 1;
10457718be8SEnji Cooper 	pthread_join(pt, &fail);
10557718be8SEnji Cooper 
10657718be8SEnji Cooper 	FSTEST_DESTRUCTOR(tc, nfs, voidargs);
10757718be8SEnji Cooper 
10857718be8SEnji Cooper 	atf_tc_expect_fail("PR kern/5844");
10957718be8SEnji Cooper 	if (fail)
11057718be8SEnji Cooper 		atf_tc_fail("op failed with EACCES");
11157718be8SEnji Cooper 	else
11257718be8SEnji Cooper 		atf_tc_fail("race did not trigger this time");
11357718be8SEnji Cooper }
11457718be8SEnji Cooper 
ATF_TP_ADD_TCS(tp)11557718be8SEnji Cooper ATF_TP_ADD_TCS(tp)
11657718be8SEnji Cooper {
11757718be8SEnji Cooper 
11857718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, mountdhup);
11957718be8SEnji Cooper 
12057718be8SEnji Cooper 	return atf_no_error();
12157718be8SEnji Cooper }
122