Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 16, 2024

Conversation

reidsunderland
Copy link
Member

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
Copy link
Member Author

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

Copy link
Contributor

@petersilva petersilva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, reasonable approach to defining pre-processor symbol.

@petersilva petersilva merged commit af8ed70 into development Jul 16, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants