Page MenuHomeFreeBSD

D24844.diff
No OneTemporary

D24844.diff

Index: head/lib/libc/tests/resolv/resolv_test.c
===================================================================
--- head/lib/libc/tests/resolv/resolv_test.c
+++ head/lib/libc/tests/resolv/resolv_test.c
@@ -34,6 +34,8 @@
#include <sys/types.h>
#include <sys/socket.h>
+#include <assert.h>
+#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <netdb.h>
@@ -55,14 +57,13 @@
};
static StringList *hosts = NULL;
-static enum method method = METHOD_GETADDRINFO;
static int *ask = NULL;
static int *got = NULL;
static void load(const char *);
-static void resolvone(int);
+static void resolvone(int, enum method);
static void *resolvloop(void *);
-static void run(int *);
+static void run(int *, enum method);
static pthread_mutex_t stats = PTHREAD_MUTEX_INITIALIZER;
@@ -173,18 +174,18 @@
}
static void
-resolvone(int n)
+resolvone(int n, enum method method)
{
char buf[1024];
pthread_t self = pthread_self();
size_t i = (random() & 0x0fffffff) % hosts->sl_cur;
char *host = hosts->sl_str[i];
- struct addrinfo hints, *res;
int error, len;
len = snprintf(buf, sizeof(buf), "%p: %d resolving %s %d\n",
self, n, host, (int)i);
(void)write(STDOUT_FILENO, buf, len);
+ error = 0;
switch (method) {
case METHOD_GETADDRINFO:
error = resolv_getaddrinfo(self, host, i);
@@ -196,6 +197,10 @@
error = resolv_getipnodeby(self, host);
break;
default:
+ /* UNREACHABLE */
+ /* XXX Needs an __assert_unreachable() for userland. */
+ assert(0 && "Unreachable segment reached");
+ abort();
break;
}
pthread_mutex_lock(&stats);
@@ -204,35 +209,53 @@
pthread_mutex_unlock(&stats);
}
+struct resolvloop_args {
+ int *nhosts;
+ enum method method;
+};
+
static void *
resolvloop(void *p)
{
- int *nhosts = (int *)p;
- if (*nhosts == 0)
+ struct resolvloop_args *args = p;
+
+ if (*args->nhosts == 0) {
+ free(args);
return NULL;
+ }
+
do
- resolvone(*nhosts);
- while (--(*nhosts));
+ resolvone(*args->nhosts, args->method);
+ while (--(*args->nhosts));
+ free(args);
return NULL;
}
static void
-run(int *nhosts)
+run(int *nhosts, enum method method)
{
pthread_t self;
int rc;
+ struct resolvloop_args *args;
+ /* Created thread is responsible for free(). */
+ args = malloc(sizeof(*args));
+ ATF_REQUIRE(args != NULL);
+
+ args->nhosts = nhosts;
+ args->method = method;
self = pthread_self();
- rc = pthread_create(&self, NULL, resolvloop, nhosts);
+ rc = pthread_create(&self, NULL, resolvloop, args);
ATF_REQUIRE_MSG(rc == 0, "pthread_create failed: %s", strerror(rc));
}
static int
run_tests(const char *hostlist_file, enum method method)
{
- int nthreads = NTHREADS;
- int nhosts = NHOSTS;
- int i, c, done, *nleft;
+ size_t nthreads = NTHREADS;
+ size_t nhosts = NHOSTS;
+ size_t i;
+ int c, done, *nleft;
hosts = sl_init();
srandom(1234);
@@ -252,7 +275,7 @@
for (i = 0; i < nthreads; i++) {
nleft[i] = nhosts;
- run(&nleft[i]);
+ run(&nleft[i], method);
}
for (done = 0; !done;) {

File Metadata

Mime Type
text/plain
Expires
Thu, Nov 21, 6:36 AM (21 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
14756392
Default Alt Text
D24844.diff (2 KB)

Event Timeline