hw7: initial HW7 commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.so
|
||||||
22
07_DebuggingTracing/Makefile
Normal file
22
07_DebuggingTracing/Makefile
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
GENERATES = preloader.so testfile testFIXfile
|
||||||
|
TRASH = *.o *~ o.*
|
||||||
|
|
||||||
|
all: lib test
|
||||||
|
|
||||||
|
lib:
|
||||||
|
gcc -g -fPIC -shared preloader.c -o preloader.so -ldl
|
||||||
|
|
||||||
|
test:
|
||||||
|
touch testfile
|
||||||
|
LD_PRELOAD="./preloader.so" rm testfile
|
||||||
|
[ ! -f testfile ]
|
||||||
|
touch testFIXfile
|
||||||
|
-LD_PRELOAD="./preloader.so" rm testFIXfile
|
||||||
|
[ -f testFIXfile ]
|
||||||
|
rm testFIXfile
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(TRASH)
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
rm -rf $(GENERATES)
|
||||||
16
07_DebuggingTracing/preloader.c
Normal file
16
07_DebuggingTracing/preloader.c
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static int (*real_unlinkat)(int dirfd, const char* pathname, int flags) = NULL;
|
||||||
|
|
||||||
|
int unlinkat(int dirfd, const char* pathname, int flags) {
|
||||||
|
printf("unlinkat: %s\n", pathname);
|
||||||
|
real_unlinkat = dlsym(RTLD_NEXT, "unlinkat");
|
||||||
|
if (strstr(pathname, "FIX") != NULL)
|
||||||
|
return EPERM;
|
||||||
|
return real_unlinkat(dirfd, pathname, flags);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user