Path: blob/main/tools/test/stress2/misc/beneath2.sh
39536 views
#!/bin/sh12#3# SPDX-License-Identifier: BSD-2-Clause4#5# Copyright (c) 2018 Dell EMC Isilon6#7# Redistribution and use in source and binary forms, with or without8# modification, are permitted provided that the following conditions9# are met:10# 1. Redistributions of source code must retain the above copyright11# notice, this list of conditions and the following disclaimer.12# 2. Redistributions in binary form must reproduce the above copyright13# notice, this list of conditions and the following disclaimer in the14# documentation and/or other materials provided with the distribution.15#16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26# SUCH DAMAGE.27#2829# O_RESOLVE_BENEATH test with a relative path, which is a symbolic link pointing30# to an absolute path.3132# "panic: Assertion (ndp->ni_lcf & NI_LCF_LATCH) != 0 failed at33# ../../../kern/vfs_lookup.c:182" seen. Fixed by r340343.3435# Based on scenario by Vladimir Kondratyev <vladimir kondratyev su>3637. ../default.cfg38[ `id -u` -ne 0 ] && echo "Must be root!" && exit 13940dir=/tmp41odir=`pwd`42cd $dir43sed '1,/^EOF/d' < $odir/$0 > $dir/beneath2.c44mycc -o beneath2 -Wall -Wextra -O0 -g beneath2.c || exit 145rm -f beneath2.c46cd $odir4748set -e49mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint50[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart51mdconfig -a -t swap -s 1g -u $mdstart52newfs $newfs_flags md$mdstart > /dev/null53mount /dev/md$mdstart $mntpoint54set +e5556cd $mntpoint57ln -s /tmp/justalongname symlink58$dir/beneath2 symlink59s=$?60[ -f beneath2.core -a $s -eq 0 ] &&61{ ls -l beneath2.core; mv beneath2.core $dir; s=1; }62cd $odir6364for i in `jot 6`; do65mount | grep -q "on $mntpoint " || break66umount $mntpoint && break || sleep 1067[ $i -eq 6 ] &&68{ echo FATAL; fstat -mf $mntpoint; exit 1; }69done70mdconfig -d -u $mdstart71rm -rf $dir/beneath272exit $s7374EOF75#include <sys/types.h>7677#include <err.h>78#include <errno.h>79#include <fcntl.h>80#include <stdio.h>81#include <stdlib.h>8283int84main(int argc, char *argv[])85{86int fd;87char *file;8889if (argc != 2) {90fprintf(stderr, "Usage: %s <file>", argv[0]);91exit(1);92}93file = argv[1];94if ((fd = open(file, O_RDONLY | O_RESOLVE_BENEATH)) != 0 &&95errno != ENOTCAPABLE)96err(1, "open(%s)", file);9798return (0);99}100101102