smbd: Modernize a DEBUG statement
[Samba.git] / nsswitch / b15464-testcase.c
blobdecb474a81eeb03042d6044268806026f0f113ca
1 #include "replace.h"
2 #include "system/wait.h"
3 #include "system/threads.h"
4 #include <assert.h>
6 int main(int argc, const char *argv[])
8 pid_t pid;
9 int wstatus;
10 pthread_key_t k1;
11 pthread_key_t k2;
12 pthread_key_t k3;
13 char *val = NULL;
14 const char *nss_winbind = (argc >= 2 ? argv[1] : "bin/plugins/libnss_winbind.so.2");
15 void *nss_winbind_handle = NULL;
16 union {
17 int (*fn)(void);
18 void *symbol;
19 } nss_winbind_endpwent = { .symbol = NULL, };
22 * load and invoke something simple like
23 * _nss_winbind_endpwent in order to
24 * get the libnss_winbind internal going
26 nss_winbind_handle = dlopen(nss_winbind, RTLD_NOW);
27 printf("%d: nss_winbind[%s] nss_winbind_handle[%p]\n",
28 getpid(), nss_winbind, nss_winbind_handle);
29 assert(nss_winbind_handle != NULL);
31 nss_winbind_endpwent.symbol = dlsym(nss_winbind_handle,
32 "_nss_winbind_endpwent");
33 printf("%d: nss_winbind_handle[%p] _nss_winbind_endpwent[%p]\n",
34 getpid(), nss_winbind_handle, nss_winbind_endpwent.symbol);
35 assert(nss_winbind_endpwent.symbol != NULL);
36 (void)nss_winbind_endpwent.fn();
38 val = malloc(1);
39 assert(val != NULL);
41 pthread_key_create(&k1, NULL);
42 pthread_setspecific(k1, val);
43 printf("%d: k1=%d\n", getpid(), k1);
45 pid = fork();
46 if (pid) {
47 free(val);
48 wait(&wstatus);
49 return WEXITSTATUS(wstatus);
52 pthread_key_create(&k2, NULL);
53 pthread_setspecific(k2, val);
55 printf("%d: Hello after fork, k1=%d, k2=%d\n", getpid(), k1, k2);
57 pid = fork();
59 if (pid) {
60 free(val);
61 wait(&wstatus);
62 return WEXITSTATUS(wstatus);
65 pthread_key_create(&k3, NULL);
66 pthread_setspecific(k3, val);
68 printf("%d: Hello after fork2, k1=%d, k2=%d, k3=%d\n", getpid(), k1, k2, k3);
70 if (k1 == k2 || k2 == k3) {
71 printf("%d: FAIL inconsistent keys\n", getpid());
72 return 1;
75 printf("%d: OK consistent keys\n", getpid());
76 return 0;