11 #include <sys/types.h>
18 #define INIT(x) real_ ## x = dlsym(RTLD_NEXT, #x); \
20 fprintf(stderr, "Would the real " #x " please stand up? %s\n", dlerror()); \
24 DIR *opendir(const char *name)
26 int fd = open(name, O_RDONLY|O_NDELAY|O_DIRECTORY|O_LARGEFILE);
32 DIR *__opendir(const char *name)
37 static int (*real_glob)(const char *pattern, int flags,
38 int (*errfunc) (const char *epath, int eerrno),
41 int glob(const char *pattern, int flags,
42 int (*errfunc) (const char *epath, int eerrno),
45 if (!(flags & GLOB_ALTDIRFUNC)) {
46 pglob->gl_closedir = closedir;
47 pglob->gl_readdir = readdir;
48 pglob->gl_opendir = opendir;
49 pglob->gl_lstat = lstat;
50 pglob->gl_stat = stat;
51 flags |= GLOB_ALTDIRFUNC;
56 return real_glob(pattern, flags, errfunc, pglob);
59 #define PWD_LOCKFILE "/etc/.pwd.lock"
61 static int lock_fd = -1;
63 /* FIXME: Ignores multi-thread issues.
64 * Doesn't wait for the file to become lockable
68 struct flock fl = { 0 };
70 /* This process already holds the lock */
74 lock_fd = open(PWD_LOCKFILE, O_WRONLY|O_CREAT, 0600);
78 if (fcntl(lock_fd, F_SETFD, fcntl(lock_fd, F_GETFD, 0) | FD_CLOEXEC) == -1) {
84 fl.l_whence = SEEK_SET;
85 return fcntl(lock_fd, F_SETLKW, &fl);
95 result = close(lock_fd);
100 static (*real_open)(const char *name, int flags, ...);
101 int open(const char *name, int flags, ...)
104 if (flags & O_CREAT) {
107 mode = va_arg(va, mode_t);
113 return real_open(name, flags, mode);
116 static FILE *(*real_fopen)(const char *name, const char *flags);
117 FILE *fopen(const char *name, const char *flags)
119 char *str, *ptr = strchr(flags, 'e');
123 ptr = (str + (ptr - flags));
124 strcpy(ptr, ptr + 1);
131 ret = real_fopen(name, str);
137 static void _init() __attribute__((constructor));