4 # Copyright (c) 2016 Dell EMC
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 # Demonstrate that vfs_export() leaks M_CRED when mountd(8) is started:
30 # "M_CRED leaked 160".
32 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
36 pgrep -q mountd || echo "Note: mountd(8) must run for this test to fail"
39 sed '1,/^EOF/d' < $here/$0 > credleak.c
40 mycc -o credleak -Wall -Wextra -O2 -g credleak.c || exit 1
43 mount | grep -q "on $mntpoint " && umount -f $mntpoint
44 mount -t tmpfs tmpfs $mntpoint
47 old=`vmstat -m | grep -w cred | awk '{print $2}'`
48 su $testuser -c "/tmp/credleak $mntpoint" &
50 while kill -0 $! 2>/dev/null; do
51 umount -f $mntpoint &&
52 mount -t tmpfs tmpfs $mntpoint
59 while pkill -9 swap; do
62 while mount | grep $mntpoint | grep -q tmpfs; do
63 umount $mntpoint || sleep 1
65 [ -d "$mntpoint" ] && (cd $mntpoint && find . -delete)
69 leak=$((`vmstat -m | grep -w cred | awk '{print $2}'` - old))
70 [ $leak -gt 10 ] && { echo "M_CRED leaked $leak"; s=1; }
73 #include <sys/param.h>
95 char d[MAXPATHLEN + 1], name[MAXPATHLEN + 1];
97 setproctitle(__func__);
100 snprintf(name, sizeof(name), "%s/d1.%05d", dir, getpid());
101 if (mkdir(name, 0755) == -1) {
102 if (errno != ENAMETOOLONG && errno != ENOENT &&
103 errno != EBUSY && errno != EACCES && errno != EPERM)
104 warn("mkdir(%s)", name);
108 snprintf(d, sizeof(d), "/%d", i++);
109 strncat(name, d, sizeof(name) - 1);
110 if (mkdir(name, 0755) == -1) {
111 if (errno != ENAMETOOLONG && errno != ENOENT &&
112 errno != EBUSY && errno != EACCES && errno != EPERM)
113 warn("mkdir(%s)", name);
121 snprintf(name, sizeof(name), "%s/d1.%05d", dir, getpid());
122 for (j = 0; j < i; j++) {
123 snprintf(d, sizeof(d), "/%d", j);
124 strncat(name, d, sizeof(name) - 1);
126 if (rmdir(name) == -1) {
127 if (errno != ENOTEMPTY && errno != ENOENT && errno !=
129 warn("rmdir(%s)", name);
136 fprintf(stderr, "FAIL nbc = %d, nbd = %d\n", nbc, nbd);
142 main(int argc, char **argv)
147 fprintf(stderr, "Usage: %s <full path to dir>", argv[0]);
152 for (j = 0; j < LOOPS; j++) {
153 for (i = 0; i < PARALLEL; i++) {
157 for (i = 0; i < PARALLEL; i++)