override - Overriding getdirentries in C -


i override getdirentries (and others, lstat) libc syscalls. can override -for example- lstat , chmod, can't override getdirentries (and amongst others fstatfs).

example code is:

    #include <errno.h>     #include <dlfcn.h>     #include <stdio.h>     #include <strings.h>     #include <string.h>     #include <sys/_timespec.h>     #include <sys/stat.h>     #include <sys/mount.h>      #ifndef rtld_next     #define rtld_next   ((void *) -1l)     #endif      int (*getdirentries_orig)(int fd, char *buf, int nbytes, long *basep);     int (*lstat_orig)(const char *path, struct stat *sb);     int (*fstatfs_orig)(int fd, struct statfs *buf);     int (*chmod_orig)(const char *path, mode_t mode);      #define hook(func) func##_##orig = dlsym(rtld_next,#func)      int getdirentries(int fd, char *buf, int nbytes, long *basep) {         hook(getdirentries);         printf("getdirentries\n");         return getdirentries_orig(fd, buf, nbytes, basep);     }      int lstat(const char *path, struct stat *sb) {         hook(lstat);         printf("lstat\n");         return (lstat_orig(path, sb));     }      int fstatfs(int fd, struct statfs *buf) {         hook(fstatfs);         printf("fstatfs\n");         return fstatfs_orig(fd, buf);     }      int chmod(const char *path, mode_t mode) {         hook(chmod);         printf("chmod\n");         return chmod_orig(path, mode);     } 

i compile on freebsd with:

cc -wall -g -o2 -fpic -shared -o preload.so preload.c 

(on linux, adding -ldl may needed) , use ld_preload=./preload.so bash.

if issue ls -l, "lstat" printed multiple times, that's good. ls calls multiple getdirentries too, according ktrace, , override function not called. fstatfs doesn't work.

how can override getdirentries, fstatfs , possibly other syscalls, , why aren't working in case?

thanks,

as turns out, readdir() in libc/readdir.c (readdir ls calls , should call getdirentries) calls _getdirentries, not getdirentries. if override _getdirentries, works. same fstatfs, why program did not work.


Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -