Path: blob/main/tools/test/stress2/misc/beneath.sh
39537 views
#!/bin/sh12#3# SPDX-License-Identifier: BSD-2-Clause4#5# Copyright (c) 2021 Konstantin Belousov <[email protected]>6#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# Test of open(2) with the O_RESOLVE_BENEATH flag.3031# userret: returning with the following locks held:32# shared lockmgr ufs (ufs) r = 0 (0xfffff804ec0d2a48) locked @33# kern/vfs_subr.c:2590 seen in WiP code:34# https://people.freebsd.org/~pho/stress/log/kostik1126.txt3536top=/tmp/beneath.d37mkdir -p $top38cat > $top/beneath.c <<EOF39/* $Id: beneath.c,v 1.1 2018/10/13 16:53:02 kostik Exp kostik $ */4041#include <sys/stat.h>42#include <errno.h>43#include <fcntl.h>44#include <stdio.h>45#include <string.h>46#include <unistd.h>4748int49main(int argc, char *argv[])50{51struct stat st;52char *name;53int error, fd, i;5455for (i = 1; i < argc; i++) {56name = argv[i];57alarm(120);58fd = open(name, O_RDONLY | O_RESOLVE_BENEATH);59if (fd == -1) {60fprintf(stderr, "open(\"%s\") failed, error %d %s\n",61name, errno, strerror(errno));62} else {63fprintf(stderr, "open(\"%s\") succeeded\n", name);64close(fd);65}66error = fstatat(AT_FDCWD, name, &st, AT_RESOLVE_BENEATH);67if (error == -1){68fprintf(stderr, "stat(\"%s\") failed, error %d %s\n",69name, errno, strerror(errno));70} else {71fprintf(stderr, "stat(\"%s\") succeeded\n", name);72}73}74}75EOF76cc -o $top/beneath -Wall -Wextra $top/beneath.c || exit 177rm $top/beneath.c7879# Test with two directories as arguments:80cd $top81mkdir -p a/b82./beneath a/b83./beneath $top/a/b84touch $top/a/c85./beneath a/c86./beneath $top/a/c87./beneath a/d88./beneath $top/a/d8990# CWD is still $top for this test91top2=/var/tmp/beneath.d92mkdir -p $top293mkdir -p $top2/a/b94./beneath $top2/a/b > /dev/null 2>&19596touch $top2/a/c97./beneath $top2/a/c > /dev/null 2>&19899# Other CWDs100(cd /etc; find . | head -1000 | xargs $top/beneath) > /dev/null 2>&1101(cd /var; find . | head -1000 | xargs $top/beneath) > /dev/null 2>&1102103rm -rf $top $top2104exit 0105106107