1#!/bin/sh 2 3# 4# Copyright (c) 2013 EMC Corp. 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 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. 15# 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 26# SUCH DAMAGE. 27# 28 29# Page fault seen 30# http://people.freebsd.org/~pho/stress/log/kostik654.txt 31# Fixed by r259521. 32 33[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 34 35. ../default.cfg 36 37odir=`pwd` 38cd /tmp 39sed '1,/^EOF/d' < $odir/$0 > fifo2.c 40rm -f /tmp/fifo2 41mycc -o fifo2 -Wall -Wextra -O2 -g fifo2.c -lpthread || exit 1 42rm -f fifo2.c 43 44mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint 45mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart 46 47mdconfig -a -t swap -s 1g -u $mdstart || exit 1 48bsdlabel -w md$mdstart auto 49newfs $newfs_flags md${mdstart}$part > /dev/null 50mount /dev/md${mdstart}$part $mntpoint 51chmod 777 $mntpoint 52mkfifo $mntpoint/f 53chmod 777 $mntpoint/f 54 55sleeptime=12 56st=`date '+%s'` 57while [ $((`date '+%s'` - st)) -lt $((10 * sleeptime)) ]; do 58 (cd $mntpoint; /tmp/fifo2) & 59 start=`date '+%s'` 60 while [ $((`date '+%s'` - start)) -lt $sleeptime ]; do 61 pgrep -q fifo2 || break 62 sleep .5 63 done 64 while pkill -9 fifo2; do :; done 65 wait 66done 67 68for i in `jot 10`; do 69 mount | grep -q md${mdstart}$part && \ 70 umount $mntpoint > /dev/null 2>&1 && 71 mdconfig -d -u $mdstart && break 72 sleep 10 73done 74s=0 75mount | grep -q md${mdstart}$part && 76 { echo "umount $mntpoint failed"; s=1; } 77rm -f /tmp/fifo2 78exit $s 79EOF 80#include <sys/types.h> 81#include <sys/resource.h> 82#include <sys/stat.h> 83#include <sys/syscall.h> 84#include <sys/wait.h> 85 86#include <err.h> 87#include <errno.h> 88#include <fcntl.h> 89#include <libutil.h> 90#include <pthread.h> 91#include <pwd.h> 92#include <signal.h> 93#include <stdint.h> 94#include <stdio.h> 95#include <stdlib.h> 96#include <string.h> 97#include <unistd.h> 98 99#define N (128 * 1024 / (int)sizeof(u_int32_t)) 100u_int32_t r[N]; 101 102static void 103hand(int i __unused) { /* handler */ 104 _exit(1); 105} 106 107static unsigned long 108makearg(void) 109{ 110 unsigned int i; 111 unsigned long val; 112 113 val = arc4random(); 114 i = arc4random() % 100; 115 if (i < 20) 116 val = val & 0xff; 117 if (i >= 20 && i < 40) 118 val = val & 0xffff; 119 if (i >= 40 && i < 60) 120 val = (unsigned long)(r) | (val & 0xffff); 121#if defined(__LP64__) 122 if (i >= 60) { 123 val = (val << 32) | arc4random(); 124 if (i > 80) 125 val = val & 0x00007fffffffffffUL; 126 } 127#endif 128 129 return(val); 130} 131 132static void * 133calls(void *arg __unused) 134{ 135 unsigned long arg1, arg2, arg3, arg4, arg5, arg6, arg7; 136 int i; 137 138 for (i = 0;; i++) { 139 arg1 = (unsigned long)(void *)"f"; 140 arg2 = makearg(); 141 arg3 = makearg(); 142 arg4 = makearg(); 143 arg5 = makearg(); 144 arg6 = makearg(); 145 arg7 = makearg(); 146 147#if 0 148 fprintf(stderr, "%2d : syscall(%3d, %lx, %lx, %lx, %lx, %lx, %lx, %lx)\n", 149 i, SYS_open, arg1, arg2, arg3, arg4, arg5, arg6, arg7); 150 usleep(100000); 151#endif 152 alarm(1); 153 syscall(SYS_open, arg1, arg2, arg3, arg4, arg5, arg6, arg7); 154 } 155 156 return (0); 157} 158 159int 160main(void) 161{ 162 struct passwd *pw; 163 struct rlimit limit; 164 pthread_t cp[50]; 165 time_t start; 166 int e, j; 167 168 if ((pw = getpwnam("nobody")) == NULL) 169 err(1, "no such user: nobody"); 170 171 if (setgroups(1, &pw->pw_gid) || 172 setegid(pw->pw_gid) || setgid(pw->pw_gid) || 173 seteuid(pw->pw_uid) || setuid(pw->pw_uid)) 174 err(1, "Can't drop privileges to \"nobody\""); 175 endpwent(); 176 177 limit.rlim_cur = limit.rlim_max = 1000; 178 if (setrlimit(RLIMIT_NPTS, &limit) < 0) 179 err(1, "setrlimit"); 180 181 signal(SIGALRM, hand); 182 signal(SIGILL, hand); 183 signal(SIGFPE, hand); 184 signal(SIGSEGV, hand); 185 signal(SIGBUS, hand); 186 signal(SIGURG, hand); 187 signal(SIGSYS, hand); 188 signal(SIGTRAP, hand); 189 190 start = time(NULL); 191 while ((time(NULL) - start) < 120) { 192 if (fork() == 0) { 193 for (j = 0; j < 1; j++) 194 if ((e = pthread_create(&cp[j], NULL, calls, NULL)) != 0) 195 errc(1, e,"pthread_create"); 196 197 for (j = 0; j < 1; j++) 198 pthread_join(cp[j], NULL); 199 _exit(0); 200 } 201 wait(NULL); 202 } 203 204 return (0); 205} 206