Revert "sshd(8): Add USE_PAM handling defaults."
[dragonfly.git] / test / stress / stress2 / misc / kevent.sh
blobdeeb0787e6be5206b395b35131a5659f943cccd2
1 #!/bin/sh
4 # Copyright (c) 2008 Peter Holm <pho@FreeBSD.org>
5 # All rights reserved.
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.
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.
28 # $FreeBSD$
31 # panic: KN_INFLUX set when not suppose to be
33 . ../default.cfg
35 odir=`pwd`
37 cd /tmp
38 sed '1,/^EOF/d' < $odir/$0 > kevent.c
39 cc -o kevent -Wall kevent.c -pthread
40 rm -f kevent.c
41 cd $RUNDIR
43 for i in `jot 10`; do
44 for j in `jot 12`; do
45 /tmp/kevent > /dev/null 2>&1 &
46 done
47 for j in `jot 12`; do
48 wait
49 done
50 done
51 exit
52 EOF
53 #include <pthread.h>
54 #include <sys/types.h>
55 #include <sys/event.h>
56 #include <err.h>
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <string.h>
60 #include <unistd.h>
62 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
63 pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
64 static int waiting;
66 static int fd1[2];
67 static int fd2[2];
68 static int fd3[2];
70 void *
71 thr1(void *arg)
73 int n;
74 int kq = -1;
75 struct kevent ev[3];
77 if ((kq = kqueue()) < 0)
78 err(1, "kqueue(). %s:%d", __FILE__, __LINE__);
80 n = 0;
81 EV_SET(&ev[n], fd1[1], EVFILT_WRITE,
82 EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0);
83 n++;
84 EV_SET(&ev[n], fd2[1], EVFILT_WRITE,
85 EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0);
86 n++;
87 EV_SET(&ev[n], fd3[1], EVFILT_WRITE,
88 EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0);
89 n++;
91 if (kevent(kq, ev, n, NULL, 0, NULL) < 0)
92 err(1, "kevent(). %s:%d", __FILE__, __LINE__);
94 if (pthread_mutex_lock(&mutex) == -1)
95 err(1, "pthread_mutex_lock");
96 waiting = 0;
97 if (pthread_cond_signal(&cond) == -1)
98 err(1, "pthread_cond_signal");
99 if (pthread_mutex_unlock(&mutex) == -1)
100 err(1, "pthread_mutex_unlock");
102 n = 0;
103 EV_SET(&ev[n], fd1[1], EVFILT_WRITE,
104 EV_DELETE, 0, 0, 0);
105 n++;
106 if (kevent(kq, ev, n, NULL, 0, NULL) < 0)
107 err(1, "kevent(). %s:%d", __FILE__, __LINE__);
108 close(kq);
110 // printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout);
111 return (0);
114 void *
115 thr2(void *arg)
117 if (pthread_mutex_lock(&mutex) == -1)
118 err(1, "pthread_mutex_lock");
119 while (waiting == 1) {
120 if (pthread_cond_wait(&cond, &mutex) == -1)
121 err(1, "pthread_cond_wait");
123 if (pthread_mutex_unlock(&mutex) == -1)
124 err(1, "pthread_mutex_unlock");
125 // printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout);
126 close(fd1[0]);
127 close(fd1[1]);
128 close(fd2[0]);
129 close(fd2[1]);
130 close(fd3[0]);
131 close(fd3[1]);
132 return (0);
136 main(int argc, char **argv)
138 pthread_t threads[2];
139 int r;
140 int i;
142 for (i = 0; i < 1000; i++) {
143 waiting = 1;
144 // printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout);
145 if (pipe(fd1) == -1)
146 err(1, "pipe()");
147 if (pipe(fd2) == -1)
148 err(1, "pipe()");
149 if (pipe(fd3) == -1)
150 err(1, "pipe()");
152 if (pthread_mutex_init(&mutex, 0) == -1)
153 err(1, "pthread_mutex_init");
154 if (pthread_cond_init(&cond, NULL) == -1)
155 err(1, "pthread_cond_init");
157 if ((r = pthread_create(&threads[0], NULL, thr1, 0)) != 0)
158 err(1, "pthread_create(): %s\n", strerror(r));
159 if ((r = pthread_create(&threads[1], NULL, thr2, 0)) != 0)
160 err(1, "pthread_create(): %s\n", strerror(r));
162 if (pthread_join(threads[0], NULL) != 0)
163 err(1, "pthread_join(%d)", 0);
164 if (pthread_join(threads[1], NULL) != 0)
165 err(1, "pthread_join(%d)", 1);
166 if (pthread_mutex_destroy(&mutex) == -1)
167 err(1, "pthread_mutex_destroy");
168 if (pthread_cond_destroy(&cond) == -1)
169 err(1, "pthread_condattr_destroy");
172 return (0);