lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #include <sys/types.h> |
| 2 | #include <dlfcn.h> |
| 3 | #include <error.h> |
| 4 | #include <mcheck.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <unistd.h> |
| 7 | |
| 8 | pid_t pid, pid2; |
| 9 | |
| 10 | pid_t getpid(void) |
| 11 | { |
| 12 | pid_t (*f)(void); |
| 13 | f = (pid_t (*)(void)) dlsym (RTLD_NEXT, "getpid"); |
| 14 | if (f == NULL) |
| 15 | error (EXIT_FAILURE, 0, "dlsym (RTLD_NEXT, \"getpid\"): %s", dlerror ()); |
| 16 | return (pid2 = f()) + 26; |
| 17 | } |
| 18 | |
| 19 | int |
| 20 | main (void) |
| 21 | { |
| 22 | pid_t (*f)(void); |
| 23 | |
| 24 | mtrace (); |
| 25 | |
| 26 | f = (pid_t (*)(void)) dlsym (RTLD_DEFAULT, "getpid"); |
| 27 | if (f == NULL) |
| 28 | error (EXIT_FAILURE, 0, "dlsym (RTLD_DEFAULT, \"getpid\"): %s", dlerror ()); |
| 29 | pid = f(); |
| 30 | if (pid != pid2 + 26) |
| 31 | error (EXIT_FAILURE, 0, "main getpid() not called"); |
| 32 | return 0; |
| 33 | } |