added mkdir_preload
[tridge/junkcode.git] / mkdir_preload / mkdir_preload.c
1 #define _GNU_SOURCE
2 #include <stdio.h>
3 #include <fcntl.h>
4 #include <pwd.h>
5 #include <sys/types.h>
6 #include <dlfcn.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <stdarg.h>
10 #include <errno.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13
14 int mkdir(const char *pathname, mode_t mode)
15 {
16         static int (*mkdir_orig)(const char *pathname, mode_t mode);
17         int logfd;
18         struct stat st;
19         if (!mkdir_orig) {
20                 mkdir_orig = dlsym(RTLD_NEXT, "mkdir");
21         }
22         logfd = open("/tmp/mkdir.log", O_APPEND|O_WRONLY|O_CREAT, 0666);
23         if (logfd != -1) {
24                 dprintf(logfd, "%-8s %s\n", 
25                         stat(pathname, &st) == 0? "exist":"notexist",
26                         pathname);
27                 close(logfd);
28         }
29         return mkdir_orig(pathname, mode);
30 }