Back to index

glibc  2.9
tst-dlmopen1mod.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 #include <gnu/lib-names.h>
00004 
00005 
00006 static int cnt;
00007 
00008 static void
00009 __attribute ((constructor))
00010 constr (void)
00011 {
00012   ++cnt;
00013 }
00014 
00015 
00016 int
00017 foo (Lmid_t ns2)
00018 {
00019   void *h = dlopen (LIBC_SO, RTLD_LAZY|RTLD_NOLOAD);
00020   if (h == NULL)
00021     {
00022       printf ("cannot get handle for %s: %s\n", LIBC_SO, dlerror ());
00023       return 1;
00024     }
00025 
00026   Lmid_t ns = -10;
00027   if (dlinfo (h, RTLD_DI_LMID, &ns) != 0)
00028     {
00029       printf ("dlinfo for %s in %s failed: %s\n",
00030              LIBC_SO, __func__, dlerror ());
00031       return 1;
00032     }
00033 
00034   if (ns != ns2)
00035     {
00036       printf ("namespace for %s not LM_ID_BASE\n", LIBC_SO);
00037       return 1;
00038     }
00039 
00040   if (dlclose (h) != 0)
00041     {
00042       printf ("dlclose for %s in %s failed: %s\n",
00043              LIBC_SO, __func__, dlerror ());
00044       return 1;
00045     }
00046 
00047   if (cnt == 0)
00048     {
00049       puts ("constructor did not run");
00050       return 1;
00051     }
00052   else if (cnt != 1)
00053     {
00054       puts ("constructor did not run exactly once");
00055       return 1;
00056     }
00057 
00058   return 0;
00059 }