Skip to content

Commit 6411ad7

Browse files
authored
Merge pull request #166 from MetPX/issue164_remove
Fix #164 : add remove
2 parents 668a7ce + 79c3355 commit 6411ad7

File tree

6 files changed

+75
-3
lines changed

6 files changed

+75
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ shim_dir*
77
*.tmp
88
*.spec
99
build
10+
call_remove
1011
sr3_cpump
1112
sr3_cpost
1213
libsr3cshim.so

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ all: sr_version.h $(SARRA_OBJECT)
7171
$(CC) $(CFLAGS) -o sr_cachetest sr_cachetest.c -lsr3c $(SARRA_LINK) -lrabbitmq $(RABBIT_LINK) -lcrypto
7272
$(CC) $(CFLAGS) -o sr3_cpost sr3_cpost.c -lsr3c $(SARRA_LINK) -lrabbitmq $(RABBIT_LINK) -lcrypto
7373
$(CC) $(CFLAGS) -o sr3_cpump sr3_cpump.c -lsr3c $(SARRA_LINK) -lrabbitmq $(RABBIT_LINK) -lcrypto
74+
$(CC) $(CFLAGS) -o call_remove call_remove.c
7475

7576
#debian/changelog: ../sarracenia/debian/changelog
7677
# sed 's/^metpx-sarracenia/libsarra-c/' <../sarracenia/debian/changelog >debian/changelog
@@ -114,7 +115,7 @@ format:
114115
rm *.c~ *.h~
115116

116117
clean:
117-
rm -f *.o *.gcno *.so *.so.* *.links sr3_cpost sr_configtest sr_utiltest sr3_cpump sr_cachetest sr_cache_save.test shim_test.log
118+
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
118119
rm -rf build sr_version.h metpx-sr3c_rhel7.spec dir?.links
119120
-sr3 cleanup cpost/local_post
120121
-sr3 cleanup subscribe/local_copy

call_remove.c

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <stdio.h>
2+
int main(int argc, char* argv[])
3+
{
4+
return remove(argv[1]);
5+
}

debian/changelog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
metpx-sr3c (3.24.10rc2) unstable; urgency=medium
2+
3+
* implemented remove
4+
5+
-- Reid Sunderland <[email protected]> Thu, 10 Oct 2024 15:39:50 +0000
6+
17
metpx-sr3c (3.24.10rc1) unstable; urgency=medium
28

39
* added more syscalls (getcpu, mremap, shmat, shmdt)

libsr3shim.c

+46
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,52 @@ int rmdir(const char *pathname)
693693
return (shimpost(pathname, status));
694694
}
695695

696+
static int remove_init_done = 0;
697+
typedef int (*remove_fn)(const char *);
698+
static remove_fn remove_fn_ptr = remove;
699+
700+
int remove(const char *pathname)
701+
{
702+
int status;
703+
struct stat sb;
704+
int statres;
705+
bool isdir = false;
706+
707+
sr_shimdebug_msg(1, "remove %s\n", pathname);
708+
if (!remove_init_done) {
709+
setup_exit();
710+
remove_fn_ptr = (remove_fn) dlsym(RTLD_NEXT, "remove");
711+
remove_init_done = 1;
712+
}
713+
714+
// before removing, need to know if pathname is a file or dir
715+
// if stat fails, also assuming that pathname is not a dir
716+
statres = lstat(pathname, &sb);
717+
if (!statres) {
718+
isdir = S_ISDIR(sb.st_mode);
719+
}
720+
721+
status = remove_fn_ptr(pathname);
722+
if (shim_disabled)
723+
return (status);
724+
725+
sr_shimdebug_msg(1, " remove 2 %s status=%d\n", pathname, status);
726+
727+
clerror(status);
728+
if (status == -1)
729+
return status;
730+
731+
if (!strncmp(pathname, "/dev/", 5))
732+
return (status);
733+
if (!strncmp(pathname, "/proc/", 6))
734+
return (status);
735+
736+
if (isdir) {
737+
rmdir_in_progress = 1;
738+
}
739+
return (shimpost(pathname, status));
740+
}
741+
696742
static int symlink_init_done = 0;
697743
typedef int (*symlink_fn)(const char *, const char *);
698744
static symlink_fn symlink_fn_ptr = symlink;

shim_post_run.sh

+15-2
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,18 @@ echo "#test 4 remove 200 removing a whole tree events."
7474
rm -rf dirthree
7575
echo "#test 2 remove 210 removing two files"
7676
rm hoho hoohoo
77-
echo "#test 0 comment 220 shim test posting end"
78-
echo "#test 0 comment 230 test to ensure previous completes"
77+
78+
echo "#test 1 directory 220 make directory for remove test"
79+
mkdir dir_to_remove1
80+
81+
echo "#test 1 rmdir 230 remove directory using remove"
82+
./call_remove dir_to_remove1
83+
84+
echo "#test 1 sha512 240 make file for remove test"
85+
touch file_to_remove1
86+
87+
echo "#test 1 remove 250 remove file using remove"
88+
./call_remove file_to_remove1
89+
90+
echo "#test 0 comment 260 shim test posting end"
91+
echo "#test 0 comment 270 test to ensure previous completes"

0 commit comments

Comments
 (0)