Skip to content

Commit

Permalink
Merge pull request #166 from MetPX/issue164_remove
Browse files Browse the repository at this point in the history
Fix #164 : add remove
  • Loading branch information
petersilva authored Oct 11, 2024
2 parents 668a7ce + 79c3355 commit 6411ad7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ shim_dir*
*.tmp
*.spec
build
call_remove
sr3_cpump
sr3_cpost
libsr3cshim.so
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions call_remove.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdio.h>
int main(int argc, char* argv[])
{
return remove(argv[1]);
}
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
metpx-sr3c (3.24.10rc2) unstable; urgency=medium

* implemented remove

-- Reid Sunderland <[email protected]> Thu, 10 Oct 2024 15:39:50 +0000

metpx-sr3c (3.24.10rc1) unstable; urgency=medium

* added more syscalls (getcpu, mremap, shmat, shmdt)
Expand Down
46 changes: 46 additions & 0 deletions libsr3shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 15 additions & 2 deletions shim_post_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 6411ad7

Please sign in to comment.