13 #define INIT(x) real_ ## x = dlsym(RTLD_NEXT, #x); \
15 fprintf(stderr, "Would the real " #x " please stand up? %s\n", dlerror()); \
19 DIR *opendir(const char *name)
21 int fd = open(name, O_RDONLY|O_NDELAY|O_DIRECTORY|O_LARGEFILE);
27 DIR *__opendir(const char *name)
32 static int (*real_glob)(const char *pattern, int flags,
33 int (*errfunc) (const char *epath, int eerrno),
36 int glob(const char *pattern, int flags,
37 int (*errfunc) (const char *epath, int eerrno),
40 if (!(flags & GLOB_ALTDIRFUNC)) {
41 pglob->gl_closedir = closedir;
42 pglob->gl_readdir = readdir;
43 pglob->gl_opendir = opendir;
44 pglob->gl_lstat = lstat;
45 pglob->gl_stat = stat;
46 flags |= GLOB_ALTDIRFUNC;
51 return real_glob(pattern, flags, errfunc, pglob);
54 #define PWD_LOCKFILE "/etc/.pwd.lock"
56 static int lock_fd = -1;
58 /* FIXME: Ignores multi-thread issues.
59 * Doesn't wait for the file to become lockable
63 struct flock fl = { 0 };
65 /* This process already holds the lock */
69 lock_fd = open(PWD_LOCKFILE, O_WRONLY|O_CREAT, 0600);
73 if (fcntl(lock_fd, F_SETFD, fcntl(lock_fd, F_GETFD, 0) | FD_CLOEXEC) == -1) {
79 fl.l_whence = SEEK_SET;
80 return fcntl(lock_fd, F_SETLKW, &fl);
90 result = close(lock_fd);
95 static (*real_open)(const char *name, int flags, ...);
96 int open(const char *name, int flags, ...)
99 if (flags & O_CREAT) {
102 mode = va_arg(va, mode_t);
108 return real_open(name, flags, mode);
111 static FILE *(*real_fopen)(const char *name, const char *flags);
112 FILE *fopen(const char *name, const char *flags)
114 char *str, *ptr = strchr(flags, 'e');
118 ptr = (str + (ptr - flags));
119 strcpy(ptr, ptr + 1);
126 ret = real_fopen(name, str);
132 static void _init() __attribute__((constructor));