Back to index

glibc  2.9
restest2.c
Go to the documentation of this file.
00001 #include <sys/types.h>
00002 #include <dlfcn.h>
00003 #include <error.h>
00004 #include <mcheck.h>
00005 #include <stdlib.h>
00006 #include <unistd.h>
00007 
00008 pid_t pid, pid2;
00009 
00010 pid_t getpid(void)
00011 {
00012   pid_t (*f)(void);
00013   f = (pid_t (*)(void)) dlsym (RTLD_NEXT, "getpid");
00014   if (f == NULL)
00015     error (EXIT_FAILURE, 0, "dlsym (RTLD_NEXT, \"getpid\"): %s", dlerror ());
00016   return (pid2 = f()) + 26;
00017 }
00018 
00019 int
00020 main (void)
00021 {
00022   pid_t (*f)(void);
00023 
00024   mtrace ();
00025 
00026   f = (pid_t (*)(void)) dlsym (RTLD_DEFAULT, "getpid");
00027   if (f == NULL)
00028     error (EXIT_FAILURE, 0, "dlsym (RTLD_DEFAULT, \"getpid\"): %s", dlerror ());
00029   pid = f();
00030   if (pid != pid2 + 26)
00031     error (EXIT_FAILURE, 0, "main getpid() not called");
00032   return 0;
00033 }