#define _GNU_SOURCE #include #include #include #include ssize_t readlink(const char *path, char *buf, size_t bufsiz) { static ssize_t (*real_readlink)(const char *, char *, size_t) = NULL; if (!real_readlink) real_readlink = dlsym(RTLD_NEXT, "readlink"); char own_exe[64]; snprintf(own_exe, sizeof own_exe, "/proc/%d/exe", (int)getpid()); if (strcmp(path, own_exe) == 0) path = "/proc/self/exe"; return real_readlink(path, buf, bufsiz); }