Added unlink-wrapper, syscall wrapper example
authorHarvie <tomas@mudrunka.cz>
Sun, 31 Oct 2010 19:02:43 +0000 (20:02 +0100)
committerHarvie <tomas@mudrunka.cz>
Sun, 31 Oct 2010 19:02:43 +0000 (20:02 +0100)
c/unlink-wrapper/Makefile [new file with mode: 0644]
c/unlink-wrapper/unlink-wrapper.c [new file with mode: 0644]

diff --git a/c/unlink-wrapper/Makefile b/c/unlink-wrapper/Makefile
new file mode 100644 (file)
index 0000000..2d2f1f2
--- /dev/null
@@ -0,0 +1,8 @@
+proj=unlink-wrapper
+
+unexport LD_PRELOAD
+$(proj).so: $(proj).c
+       $(CC) -shared -fPIC -ldl $? -o $@
+       # To test:
+       # export LD_PRELOAD=$(PWD)/$@
+       # touch /tmp/deleteme; rm /tmp/deleteme
diff --git a/c/unlink-wrapper/unlink-wrapper.c b/c/unlink-wrapper/unlink-wrapper.c
new file mode 100644 (file)
index 0000000..e97e86c
--- /dev/null
@@ -0,0 +1,16 @@
+#define _GNU_SOURCE
+#include <dlfcn.h>
+#include <stdio.h>
+//#include <unistd.h>
+//#define RTLD_NEXT ((void *) -1l)
+
+
+int unlinkat(int dirfd, const char *pathname, int flags)
+{
+       puts("unlinkat");
+       int (*orig_unlinkat)(int, const char*, int) = dlsym(RTLD_NEXT, "unlinkat");
+       return orig_unlinkat(dirfd,pathname,flags);
+}
+
+//int unlink(const char *pathname)
+//ssize_t write(int fd, const void *buf, size_t count)
This page took 0.1161 seconds and 4 git commands to generate.