MetPX / sarrac

C implementation of (a subset of) Sarracenia (large scale file transfer utility)
GNU General Public License v2.0
4 stars 1 forks source link

Handle renameat2 on RHEL 8 and systems with glibc < 2.28 #147

Closed reidsunderland closed 4 months ago

reidsunderland commented 4 months ago

RedHat 8 has glibc 2.28 which provides renameat2, but its mv command uses syscall(316...) instead of renameat2 provided by glibc.

On RHEL8, we have to manually define INTERCEPT_SYSCALL at compile time. On systems with glibc < 2.28, it's automatically defined with

#if !__GLIBC_PREREQ(2,28)
#define INTERCEPT_SYSCALL
#endif

With INTERCEPT_SYSCALL defined, test_shim_post fails on RHEL8 with 19 good and 2 bad (RESULT: BAD! missing expected {'sha512': 1} for 160 stdout redirection in a subdir) instead of 5 bad without it.

With INTERCEPT_SYSCALL:

RESULT: BAD! missing expected {'sha512': 1} for 160 stdout redirection in a subdir
RESULT: BAD! missing expected {'sha512': 1} for 180 stdout redirection in a subsubdir
RESULT: summary: good: 19, bad 2, total 21

Without INTERCEPT_SYSCALL:

RESULT: BAD! missing expected {'rename': 1} for 050 rename directory
RESULT: BAD! missing expected {'rename': 1} for 120 moving a file.
RESULT: BAD! missing expected {'sha512': 1} for 160 stdout redirection in a subdir
RESULT: BAD! missing expected {'sha512': 1} for 180 stdout redirection in a subsubdir
RESULT: BAD! missing expected {'rename': 1} for 190 renaming subdirs should cause file rename events.
RESULT: summary: good: 16, bad 5, total 21
reidsunderland commented 4 months ago

I also commented out the renameat2_fn_ptr = (renameat2_fn) dlsym(RTLD_NEXT, "renameat2"); line and tested to confirm that this code works:

        } else if (syscall_fn_ptr) {
            sr_shimdebug_msg(1, " renameorlink using renameat2 via syscall(316, ...)\n");
            status = syscall_fn_ptr(316, olddirfd, oldpath, newdirfd, newpath, flags);

it does.

[pid 3949195] write(2, "SR_SHIMDEBUG 1 3949195 0.411893 ", 32SR_SHIMDEBUG 1 3949195 0.411893 ) = 32
[pid 3949195] write(2, "syscall 316\n", 12syscall 316
) = 12
[pid 3949195] write(2, "SR_SHIMDEBUG 1 3949195 0.411921 ", 32SR_SHIMDEBUG 1 3949195 0.411921 ) = 32
[pid 3949195] write(2, "syscall 316\n --> renameat2, will"..., 50syscall 316
 --> renameat2, will call renameorlink) = 50
[pid 3949195] write(2, "SR_SHIMDEBUG 1 3949195 0.411946 ", 32SR_SHIMDEBUG 1 3949195 0.411946 ) = 32
[pid 3949195] write(2, "-100, sub_dir1, -100, sub_dir2, "..., 33-100, sub_dir1, -100, sub_dir2, 1) = 33
[pid 3949195] write(2, "SR_SHIMDEBUG 1 3949195 0.411979 ", 32SR_SHIMDEBUG 1 3949195 0.411979 ) = 32
[pid 3949195] write(2, " renameorlink sub_dir1 sub_dir2\n", 32 renameorlink sub_dir1 sub_dir2
) = 32
[pid 3949195] write(2, "SR_SHIMDEBUG 1 3949195 0.412007 ", 32SR_SHIMDEBUG 1 3949195 0.412007 ) = 32
[pid 3949195] write(2, " renameorlink using renameat2 vi"..., 52 renameorlink using renameat2 via syscall(316, ...)
) = 52
[pid 3949195] renameat2(AT_FDCWD, "sub_dir1", AT_FDCWD, "sub_dir2", RENAME_NOREPLACE) = 0
[pid 3949195] write(2, "SR_SHIMDEBUG 3 3949195 0.412063 ", 32SR_SHIMDEBUG 3 3949195 0.412063 ) = 32
[pid 3949195] write(2, "srshim_initialize shim starting."..., 34srshim_initialize shim starting..
) = 34
[pid 3949195] write(2, "SR_SHIMDEBUG 9 3949195 0.412088 ", 32SR_SHIMDEBUG 9 3949195 0.412088 ) = 32
[pid 3949195] write(2, "srshim_initialize shim about to "..., 47srshim_initialize shim about to sr_config_init
) = 47