Commit 9ad65aad authored by Ramon Nou's avatar Ramon Nou
Browse files

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

parent 655b1f8b
......@@ -21,6 +21,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Fixed
- Using `unlink` now fails if it is a directory unless the `AT_REMOVEDIR` flag is used (POSIX compliance) ([!139](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/139)).
- fchdir generate a SIGSEV in debug mode (due to log) ([!141](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/141))
- Fix fstatat to be able to understand `AT_EMPTY_PATH` flag used in coreutils (`cat` ...) ([!149](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/149)).
## [0.9.1] - 2022-04-29
### New
......
......@@ -170,7 +170,7 @@ public:
RelativizeStatus
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;
bool
......
......@@ -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) {
RelativizeStatus
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