Skip to content

Commit

Permalink
Bugfix: Fix for handle AT_FDCWD for readlinkat (#209)
Browse files Browse the repository at this point in the history
* check for fd < 0

* fixed readlinkat to handle AT_FDCWD
  • Loading branch information
hariharan-devarajan authored Sep 30, 2024
1 parent 8971c82 commit d9757dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/dftracer/brahma/posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,21 @@ ssize_t brahma::POSIXDFTracer::readlink(const char *path, char *buf,
ssize_t brahma::POSIXDFTracer::readlinkat(int fd, const char *path, char *buf,
size_t bufsize) {
BRAHMA_MAP_OR_FAIL(readlinkat);
DFT_LOGGER_START(fd);
DFT_LOGGER_UPDATE(fd);
DFT_LOGGER_UPDATE(bufsize);
ssize_t ret = __real_readlinkat(fd, path, buf, bufsize);
DFT_LOGGER_END();
ssize_t ret;
if (fd != AT_FDCWD) {
DFT_LOGGER_START(fd);
DFT_LOGGER_UPDATE(fd);
DFT_LOGGER_UPDATE(path);
DFT_LOGGER_UPDATE(bufsize);
ret = __real_readlinkat(fd, path, buf, bufsize);
DFT_LOGGER_END();
} else {
DFT_LOGGER_START(path);
DFT_LOGGER_UPDATE(fd);
DFT_LOGGER_UPDATE(bufsize);
ret = __real_readlinkat(fd, path, buf, bufsize);
DFT_LOGGER_END();
}
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dftracer/brahma/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class POSIXDFTracer : public POSIX {
bool trace_all_files;

inline uint16_t is_traced(int fd, const char *func) {
if (fd == -1) return 0;
if (fd < 0) return 0;
uint16_t trace = tracked_fd[fd % MAX_FD];
if (trace != 0) {
DFTRACER_LOG_DEBUG(
Expand Down

0 comments on commit d9757dc

Please sign in to comment.