diff --git a/.gitignore b/.gitignore index e3da621..2e2c724 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ shim_dir* *.tmp *.spec build +call_remove sr3_cpump sr3_cpost libsr3cshim.so diff --git a/Makefile b/Makefile index fdbaf0d..02d3f48 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,7 @@ all: sr_version.h $(SARRA_OBJECT) $(CC) $(CFLAGS) -o sr_cachetest sr_cachetest.c -lsr3c $(SARRA_LINK) -lrabbitmq $(RABBIT_LINK) -lcrypto $(CC) $(CFLAGS) -o sr3_cpost sr3_cpost.c -lsr3c $(SARRA_LINK) -lrabbitmq $(RABBIT_LINK) -lcrypto $(CC) $(CFLAGS) -o sr3_cpump sr3_cpump.c -lsr3c $(SARRA_LINK) -lrabbitmq $(RABBIT_LINK) -lcrypto + $(CC) $(CFLAGS) -o call_remove call_remove.c #debian/changelog: ../sarracenia/debian/changelog # sed 's/^metpx-sarracenia/libsarra-c/' <../sarracenia/debian/changelog >debian/changelog @@ -114,7 +115,7 @@ format: rm *.c~ *.h~ clean: - rm -f *.o *.gcno *.so *.so.* *.links sr3_cpost sr_configtest sr_utiltest sr3_cpump sr_cachetest sr_cache_save.test shim_test.log + rm -f *.o *.gcno *.so *.so.* *.links sr3_cpost sr_configtest sr_utiltest sr3_cpump sr_cachetest sr_cache_save.test shim_test.log call_remove rm -rf build sr_version.h metpx-sr3c_rhel7.spec dir?.links -sr3 cleanup cpost/local_post -sr3 cleanup subscribe/local_copy diff --git a/call_remove.c b/call_remove.c new file mode 100644 index 0000000..ba8f3a3 --- /dev/null +++ b/call_remove.c @@ -0,0 +1,5 @@ +#include +int main(int argc, char* argv[]) +{ + return remove(argv[1]); +} diff --git a/debian/changelog b/debian/changelog index 0437a94..8feb083 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +metpx-sr3c (3.24.10rc2) unstable; urgency=medium + + * implemented remove + + -- Reid Sunderland Thu, 10 Oct 2024 15:39:50 +0000 + metpx-sr3c (3.24.10rc1) unstable; urgency=medium * added more syscalls (getcpu, mremap, shmat, shmdt) diff --git a/libsr3shim.c b/libsr3shim.c index 64d7672..021de8e 100644 --- a/libsr3shim.c +++ b/libsr3shim.c @@ -693,6 +693,52 @@ int rmdir(const char *pathname) return (shimpost(pathname, status)); } +static int remove_init_done = 0; +typedef int (*remove_fn)(const char *); +static remove_fn remove_fn_ptr = remove; + +int remove(const char *pathname) +{ + int status; + struct stat sb; + int statres; + bool isdir = false; + + sr_shimdebug_msg(1, "remove %s\n", pathname); + if (!remove_init_done) { + setup_exit(); + remove_fn_ptr = (remove_fn) dlsym(RTLD_NEXT, "remove"); + remove_init_done = 1; + } + + // before removing, need to know if pathname is a file or dir + // if stat fails, also assuming that pathname is not a dir + statres = lstat(pathname, &sb); + if (!statres) { + isdir = S_ISDIR(sb.st_mode); + } + + status = remove_fn_ptr(pathname); + if (shim_disabled) + return (status); + + sr_shimdebug_msg(1, " remove 2 %s status=%d\n", pathname, status); + + clerror(status); + if (status == -1) + return status; + + if (!strncmp(pathname, "/dev/", 5)) + return (status); + if (!strncmp(pathname, "/proc/", 6)) + return (status); + + if (isdir) { + rmdir_in_progress = 1; + } + return (shimpost(pathname, status)); +} + static int symlink_init_done = 0; typedef int (*symlink_fn)(const char *, const char *); static symlink_fn symlink_fn_ptr = symlink; diff --git a/shim_post_run.sh b/shim_post_run.sh index b7fbeba..cc6e614 100755 --- a/shim_post_run.sh +++ b/shim_post_run.sh @@ -74,5 +74,18 @@ echo "#test 4 remove 200 removing a whole tree events." rm -rf dirthree echo "#test 2 remove 210 removing two files" rm hoho hoohoo -echo "#test 0 comment 220 shim test posting end" -echo "#test 0 comment 230 test to ensure previous completes" + +echo "#test 1 directory 220 make directory for remove test" +mkdir dir_to_remove1 + +echo "#test 1 rmdir 230 remove directory using remove" +./call_remove dir_to_remove1 + +echo "#test 1 sha512 240 make file for remove test" +touch file_to_remove1 + +echo "#test 1 remove 250 remove file using remove" +./call_remove file_to_remove1 + +echo "#test 0 comment 260 shim test posting end" +echo "#test 0 comment 270 test to ensure previous completes"