xref: /freebsd/tools/test/stress2/misc/beneath2.sh (revision 271171e0d97b88ba2a7c3bf750c9672b484c1c13)
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
53newfs $newfs_flags md$mdstart > /dev/null
54mount /dev/md$mdstart $mntpoint
55set +e
56
57cd $mntpoint
58ln -s /tmp/justalongname symlink
59$dir/beneath2 symlink
60s=$?
61[ -f beneath2.core -a $s -eq 0 ] &&
62    { ls -l beneath2.core; mv beneath2.core $dir; s=1; }
63cd $odir
64
65for i in `jot 6`; do
66	mount | grep -q "on $mntpoint " || break
67	umount $mntpoint && break || sleep 10
68	[ $i -eq 6 ] &&
69	    { echo FATAL; fstat -mf $mntpoint; exit 1; }
70done
71mdconfig -d -u $mdstart
72rm -rf $dir/beneath2
73exit $s
74
75EOF
76#include <sys/types.h>
77
78#include <err.h>
79#include <errno.h>
80#include <fcntl.h>
81#include <stdio.h>
82#include <stdlib.h>
83
84int
85main(int argc, char *argv[])
86{
87	int fd;
88	char *file;
89
90	if (argc != 2) {
91		fprintf(stderr, "Usage: %s <file>", argv[0]);
92		exit(1);
93	}
94	file = argv[1];
95	if ((fd = open(file, O_RDONLY | O_RESOLVE_BENEATH)) != 0 &&
96	    errno != ENOTCAPABLE)
97		err(1, "open(%s)", file);
98
99	return (0);
100}
101