xref: /freebsd/tools/test/stress2/misc/beneath2.sh (revision d7d962ead0b6e5e8a39202d0590022082bf5bfb6)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5#
6# Copyright (c) 2018 Dell EMC Isilon
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27# SUCH DAMAGE.
28#
29
30# O_RESOLVE_BENEATH test with a relative path, which is a symbolic link pointing
31# to an absolute path.
32
33# "panic: Assertion (ndp->ni_lcf & NI_LCF_LATCH) != 0 failed at
34# ../../../kern/vfs_lookup.c:182" seen. Fixed by r340343.
35
36# Based on scenario by Vladimir Kondratyev <vladimir kondratyev su>
37
38. ../default.cfg
39[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1
40
41dir=/tmp
42odir=`pwd`
43cd $dir
44sed '1,/^EOF/d' < $odir/$0 > $dir/beneath2.c
45mycc -o beneath2 -Wall -Wextra -O0 -g beneath2.c || exit 1
46rm -f beneath2.c
47cd $odir
48
49set -e
50mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint
51[ -c /dev/md$mdstart ] &&  mdconfig -d -u $mdstart
52mdconfig -a -t swap -s 1g -u $mdstart
53bsdlabel -w md$mdstart auto
54newfs $newfs_flags md${mdstart}$part > /dev/null
55mount /dev/md${mdstart}$part $mntpoint
56set +e
57
58cd $mntpoint
59ln -s /tmp/justalongname symlink
60$dir/beneath2 symlink
61s=$?
62[ -f beneath2.core -a $s -eq 0 ] &&
63    { ls -l beneath2.core; mv beneath2.core $dir; s=1; }
64cd $odir
65
66for i in `jot 6`; do
67	mount | grep -q "on $mntpoint " || break
68	umount $mntpoint && break || sleep 10
69	[ $i -eq 6 ] &&
70	    { echo FATAL; fstat -mf $mntpoint; exit 1; }
71done
72mdconfig -d -u $mdstart
73rm -rf $dir/beneath2
74exit $s
75
76EOF
77#include <sys/types.h>
78
79#include <err.h>
80#include <errno.h>
81#include <fcntl.h>
82#include <stdio.h>
83#include <stdlib.h>
84
85int
86main(int argc, char *argv[])
87{
88	int fd;
89	char *file;
90
91	if (argc != 2) {
92		fprintf(stderr, "Usage: %s <file>", argv[0]);
93		exit(1);
94	}
95	file = argv[1];
96	if ((fd = open(file, O_RDONLY | O_RESOLVE_BENEATH)) != 0 &&
97	    errno != ENOTCAPABLE)
98		err(1, "open(%s)", file);
99
100	return (0);
101}
102