Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/tools/test/stress2/misc/beneath2.sh
39536 views
1
#!/bin/sh
2
3
#
4
# SPDX-License-Identifier: BSD-2-Clause
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
41
dir=/tmp
42
odir=`pwd`
43
cd $dir
44
sed '1,/^EOF/d' < $odir/$0 > $dir/beneath2.c
45
mycc -o beneath2 -Wall -Wextra -O0 -g beneath2.c || exit 1
46
rm -f beneath2.c
47
cd $odir
48
49
set -e
50
mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint
51
[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart
52
mdconfig -a -t swap -s 1g -u $mdstart
53
newfs $newfs_flags md$mdstart > /dev/null
54
mount /dev/md$mdstart $mntpoint
55
set +e
56
57
cd $mntpoint
58
ln -s /tmp/justalongname symlink
59
$dir/beneath2 symlink
60
s=$?
61
[ -f beneath2.core -a $s -eq 0 ] &&
62
{ ls -l beneath2.core; mv beneath2.core $dir; s=1; }
63
cd $odir
64
65
for 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; }
70
done
71
mdconfig -d -u $mdstart
72
rm -rf $dir/beneath2
73
exit $s
74
75
EOF
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
84
int
85
main(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
102