1 /* $NetBSD: h_reconcli.c,v 1.2 2011/02/19 09:56:45 pooka Exp $ */
4 #include <sys/sysctl.h>
6 #include <rump/rumpclient.h>
7 #include <rump/rump_syscalls.h>
16 static volatile int quit, riseandwhine;
18 static pthread_mutex_t closermtx;
19 static pthread_cond_t closercv;
25 pthread_mutex_lock(&closermtx);
28 pthread_cond_wait(&closercv, &closermtx);
30 pthread_mutex_unlock(&closermtx);
32 /* try to catch a random slot */
33 usleep(random() % 100000);
36 * wide-angle disintegration beam, but takes care
37 * of the client rumpkernel communication socket.
41 pthread_mutex_lock(&closermtx);
43 pthread_mutex_unlock(&closermtx);
48 static const int hostnamemib[] = { CTL_KERN, KERN_HOSTNAME };
49 static char goodhostname[128];
54 char hostnamebuf[128];
57 pthread_mutex_lock(&closermtx);
59 pthread_mutex_unlock(&closermtx);
60 if (rump_sys_getpid() == -1)
63 blen = sizeof(hostnamebuf);
64 memset(hostnamebuf, 0, sizeof(hostnamebuf));
65 if (rump_sys___sysctl(hostnamemib, __arraycount(hostnamemib),
66 hostnamebuf, &blen, NULL, 0) == -1)
68 if (strcmp(hostnamebuf, goodhostname) != 0)
70 pthread_mutex_lock(&closermtx);
72 pthread_cond_signal(&closercv);
75 pthread_cond_signal(&closercv);
76 pthread_mutex_unlock(&closermtx);
82 main(int argc, char *argv[])
84 pthread_t pt, w1, w2, w3, w4;
89 errx(1, "need timecount");
90 timecount = atoi(argv[1]);
92 errx(1, "invalid timecount %d\n", timecount);
96 rumpclient_setconnretry(RUMPCLIENT_RETRYCONN_INFTIME);
97 if (rumpclient_init() == -1)
100 blen = sizeof(goodhostname);
101 if (rump_sys___sysctl(hostnamemib, __arraycount(hostnamemib),
102 goodhostname, &blen, NULL, 0) == -1)
105 pthread_create(&pt, NULL, closer, NULL);
106 pthread_create(&w1, NULL, worker, NULL);
107 pthread_create(&w2, NULL, worker, NULL);
108 pthread_create(&w3, NULL, worker, NULL);
109 pthread_create(&w4, NULL, worker, NULL);
114 pthread_join(pt, NULL);
115 pthread_join(w1, NULL);
116 pthread_join(w2, NULL);
117 pthread_join(w3, NULL);
118 pthread_join(w4, NULL);