Commit bf833e0e authored by Ramon Nou's avatar Ramon Nou
Browse files

Merge branch...

Merge branch 'rnou/228-cat-and-other-system-commands-use-new-fstatat-with-at_empty_path-flag' into 'master'

Resolve "`cat` and other system commands use (new)fstatat with AT_EMPTY_PATH flag"

Before this MR: The flag is ignored in `relativize_fd_path`, but the man page shows that `dirfd` can be a file if the `EMPTY_PATH` is on. It seems that newer (`kernel/coreutils/etc`) uses that instead of doing a normal stat to the file.

Therefore, we need to handle empty path during relativize paths so that the file descriptor is used instead.

Closes #228

See merge request !149
parents 655b1f8b 9ad65aad
Pipeline #2819 failed
......@@ -21,6 +21,8 @@ to [Semantic Versioning](
### Fixed
- Using `unlink` now fails if it is a directory unless the `AT_REMOVEDIR` flag is used (POSIX compliance) ([!139](
- fchdir generate a SIGSEV in debug mode (due to log) ([!141](
- Fix fstatat to be able to understand `AT_EMPTY_PATH` flag used in coreutils (`cat` ...) ([!149](
## [0.9.1] - 2022-04-29
### New
......@@ -170,7 +170,7 @@ public:
relativize_fd_path(int dirfd, const char* raw_path,
std::string& relative_path,
std::string& relative_path, int flags = 0,
bool resolve_last_link = true) const;
......@@ -203,7 +203,7 @@ hook_fstatat(int dirfd, const char* cpath, struct stat* buf, int flags) {
__func__, cpath, dirfd, fmt::ptr(buf), flags);
std::string resolved;
auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved);
auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved, flags);
switch(rstatus) {
case gkfs::preload::RelativizeStatus::fd_unknown:
return syscall_no_intercept_wrapper(SYS_newfstatat, dirfd, cpath,
......@@ -185,7 +185,7 @@ PreloadContext::auto_sm(bool auto_sm) {
PreloadContext::relativize_fd_path(int dirfd, const char* raw_path,
std::string& relative_path,
std::string& relative_path, int flags,
bool resolve_last_link) const {
// Relativize path should be called only after the library constructor has
......@@ -207,6 +207,13 @@ PreloadContext::relativize_fd_path(int dirfd, const char* raw_path,
} else {
if(!ofm_->exist(dirfd)) {
return RelativizeStatus::fd_unknown;
} else {
// check if we have the AT_EMPTY_PATH flag
// for fstatat.
if(flags & AT_EMPTY_PATH) {
relative_path = ofm_->get(dirfd)->path();
return RelativizeStatus::internal;
// path is relative to fd
auto dir = ofm_->get_dir(dirfd);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment