Fix invalid file descriptor reuse while sending DNS query (BZ #15946)
[glibc.git] / elf / tst-tls-dlinfo.c
blob28661b19c2f507148bafa22e30437386fc0ecbe9
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
6 #define TEST_FUNCTION do_test ()
7 static int
8 do_test (void)
10 static const char modname[] = "tst-tlsmod2.so";
11 int result = 0;
12 int *foop;
13 int (*fp) (int, int *);
14 void *h;
16 h = dlopen (modname, RTLD_LAZY);
17 if (h == NULL)
19 printf ("cannot open '%s': %s\n", modname, dlerror ());
20 exit (1);
23 fp = dlsym (h, "in_dso");
24 if (fp == NULL)
26 printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
27 exit (1);
30 size_t modid = -1;
31 if (dlinfo (h, RTLD_DI_TLS_MODID, &modid))
33 printf ("dlinfo RTLD_DI_TLS_MODID failed: %s\n", dlerror ());
34 result = 1;
36 else
37 printf ("dlinfo says TLS module ID %Zu\n", modid);
39 void *block;
40 if (dlinfo (h, RTLD_DI_TLS_DATA, &block))
42 printf ("dlinfo RTLD_DI_TLS_DATA failed: %s\n", dlerror ());
43 result = 1;
45 else if (block != NULL)
47 printf ("dlinfo RTLD_DI_TLS_DATA says %p but should be unallocated\n",
48 block);
49 result = 1;
52 result |= fp (0, NULL);
54 foop = dlsym (h, "foo");
55 if (foop == NULL)
57 printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
58 exit (1);
60 if (*foop != 16)
62 puts ("foo != 16");
63 result = 1;
66 /* Now the module's TLS block has been used and should appear. */
67 if (dlinfo (h, RTLD_DI_TLS_DATA, &block))
69 printf ("dlinfo RTLD_DI_TLS_DATA failed the second time: %s\n",
70 dlerror ());
71 result = 1;
73 else if (block != foop)
75 printf ("dlinfo RTLD_DI_TLS_DATA says %p but should be %p\n",
76 block, foop);
77 result = 1;
80 dlclose (h);
82 return result;
86 #include "../test-skeleton.c"