hurd: fix _hurd_self_sigstate reference from ____longjmp_chk
[glibc.git] / resolv / tst-res_hconf_reorder.c
blob2ef7f073ca94523c369022f6ce6c8d34e8679e32
1 /* BZ #17977 _res_hconf_reorder_addrs test.
3 Copyright (C) 2015-2016 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <errno.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <time.h>
24 #include <dlfcn.h>
25 #include <pthread.h>
26 #include <netdb.h>
27 #include <netinet/in.h>
28 #include <sys/socket.h>
30 static struct timespec ts;
32 /* The first thread that gets a lock in _res_hconf_reorder_addrs()
33 should hold the lock long enough to make two other threads blocked.
34 This is achieved by slowing down realloc(3) that is called several times
35 by _res_hconf_reorder_addrs(). */
37 void *
38 realloc (void *ptr, size_t len)
40 static void *(*fun) (void *, size_t);
42 if (!fun)
43 fun = dlsym (RTLD_NEXT, "realloc");
45 if (ts.tv_nsec)
46 nanosleep (&ts, NULL);
48 return (*fun) (ptr, len);
51 static void *
52 resolve (void *arg)
54 struct in_addr addr;
55 struct hostent ent;
56 struct hostent *result;
57 int err;
58 char buf[1024];
60 addr.s_addr = htonl (INADDR_LOOPBACK);
61 (void) gethostbyaddr_r ((void *) &addr, sizeof (addr), AF_INET,
62 &ent, buf, sizeof (buf), &result, &err);
63 return arg;
66 static int
67 do_test (void)
69 #define N 3
70 pthread_t thr[N];
71 unsigned int i;
72 int result = 0;
74 /* turn on realloc slowdown */
75 ts.tv_nsec = 100000000;
77 for (i = 0; i < N; ++i)
79 int rc = pthread_create (&thr[i], NULL, resolve, NULL);
81 if (rc)
83 printf ("pthread_create: %s\n", strerror(rc));
84 exit (1);
88 for (i = 0; i < N; ++i)
90 void *retval;
91 int rc = pthread_join (thr[i], &retval);
93 if (rc)
95 printf ("pthread_join: %s\n", strerror(rc));
96 exit (1);
98 if (retval)
100 printf ("thread %u exit status %p\n", i, retval);
101 result = 1;
105 /* turn off realloc slowdown, no longer needed */
106 ts.tv_nsec = 0;
108 return result;
111 #define TEST_FUNCTION do_test ()
112 #include "../test-skeleton.c"