Skip to content

Commit c662793

Browse files
committed
Fixes
1 parent c0d3a4f commit c662793

4 files changed

Lines changed: 32 additions & 15 deletions

File tree

src/posix/utils/cache/consent_request_cache.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,12 @@ class ConsentRequestCache {
3434
START_LOG(capio_syscall(SYS_gettid), "call(path=%s, tid=%ld, source=%s)", path.c_str(), tid,
3535
source_func.c_str());
3636

37-
std::string resolved_path;
38-
resolved_path.reserve(PATH_MAX);
39-
syscall_no_intercept(SYS_readlink, path.c_str(), resolved_path.data(), PATH_MAX);
40-
resolved_path = capio_absolute(resolved_path);
41-
LOG("Resolved path from %s to %s. Using resolved path for query", path.c_str(),
42-
resolved_path.c_str());
43-
4437
/**
4538
* If entry is not present in cache, then proceed to perform request. othrewise if present,
4639
* there is no need to perform request to server and can proceed
4740
*/
48-
if (available_consent->find(resolved_path) == available_consent->end()) {
41+
if (const auto resolved_path = resolve_possible_symlink(path);
42+
available_consent->find(resolved_path) == available_consent->end()) {
4943
LOG("File not present in cache. performing request");
5044
auto res = _consent_to_proceed_request(resolved_path, tid, source_func);
5145
LOG("Registering new file for consent to proceed");

src/posix/utils/cache/read_request_cache_fs.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ class ReadRequestCacheFS {
1212
const long tid, const long fd) {
1313
START_LOG(capio_syscall(SYS_gettid), "call(path=%s, end_of_Read=%ld, tid=%ld, fd=%ld)",
1414
path.c_str(), end_of_Read, tid, fd);
15+
const auto resolved_path = resolve_possible_symlink(path);
16+
1517
char req[CAPIO_REQ_MAX_SIZE];
16-
sprintf(req, "%04d %ld %ld %s %ld", CAPIO_REQUEST_READ, tid, fd, path.c_str(), end_of_Read);
18+
sprintf(req, "%04d %ld %ld %s %ld", CAPIO_REQUEST_READ, tid, fd, resolved_path.c_str(),
19+
end_of_Read);
1720
LOG("Sending read request %s", req);
1821
buf_requests->write(req, CAPIO_REQ_MAX_SIZE);
1922
const capio_off64_t res = bufs_response->at(tid)->read();

src/posix/utils/filesystem.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,20 @@ inline void set_current_dir(const std::filesystem::path &cwd) {
300300
current_dir = std::make_unique<std::filesystem::path>(cwd);
301301
}
302302

303+
/**
304+
* Resolve a possible symbolic link to the absolute path that it points to
305+
* @param path
306+
* @return
307+
*/
308+
[[nodiscard]] static std::string resolve_possible_symlink(const std::filesystem::path &path) {
309+
START_LOG(capio_syscall(SYS_gettid), "call(path=%s)", path.c_str());
310+
311+
std::string resolved_path(PATH_MAX, 0);
312+
syscall_no_intercept(SYS_readlink, path.c_str(), resolved_path.data(), PATH_MAX);
313+
resolved_path = capio_absolute(resolved_path);
314+
LOG("Resolved path from %s to %s. Using resolved path for query", path.c_str(),
315+
resolved_path.c_str());
316+
return resolved_path;
317+
}
318+
303319
#endif // CAPIO_POSIX_UTILS_FILESYSTEM_HPP

src/posix/utils/requests.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,16 @@ inline capio_off64_t posix_directory_committed_request(const long pid,
8888
const std::filesystem::path &path,
8989
char *token_path) {
9090
START_LOG(capio_syscall(SYS_gettid), "call(path=%s)", path.c_str());
91+
92+
const auto resolved_path = resolve_possible_symlink(path);
93+
9194
char req[CAPIO_REQ_MAX_SIZE];
9295

93-
sprintf(req, "%04d %ld %s ", CAPIO_REQUEST_POSIX_DIR_COMMITTED, pid, path.c_str());
96+
sprintf(req, "%04d %ld %s ", CAPIO_REQUEST_POSIX_DIR_COMMITTED, pid, resolved_path.c_str());
9497
buf_requests->write(req, CAPIO_REQ_MAX_SIZE);
95-
LOG("Sent query for directory committement");
98+
LOG("Sent query for directory commitment");
9699
capio_off64_t path_len = bufs_response->at(pid)->read();
97-
LOG("Directory %s has the token length of %llu", path.c_str(), path_len);
100+
LOG("Directory %s has the token length of %llu", resolved_path.c_str(), path_len);
98101

99102
stc_queue->read(token_path, path_len);
100103
LOG("commit token path will exist at %s", token_path);
@@ -105,8 +108,9 @@ inline capio_off64_t posix_directory_committed_request(const long pid,
105108
inline void close_request(const std::filesystem::path &path, const long tid) {
106109
START_LOG(capio_syscall(SYS_gettid), "call(path=%s, tid=%ld)", path.c_str(), tid);
107110
write_request_cache_fs->flush(tid);
111+
const auto resolved_path = resolve_possible_symlink(path);
108112
char req[CAPIO_REQ_MAX_SIZE];
109-
sprintf(req, "%04d %ld %s", CAPIO_REQUEST_CLOSE, tid, path.c_str());
113+
sprintf(req, "%04d %ld %s", CAPIO_REQUEST_CLOSE, tid, resolved_path.c_str());
110114
buf_requests->write(req, CAPIO_REQ_MAX_SIZE);
111115
}
112116

@@ -131,9 +135,9 @@ inline void exit_group_request(const long tid) {
131135
inline void open_request(const int fd, const std::filesystem::path &path, const long tid) {
132136
START_LOG(capio_syscall(SYS_gettid), "call(fd=%ld, path=%s, tid=%ld)", fd, path.c_str(), tid);
133137
write_request_cache_fs->flush(tid);
134-
138+
const auto resolved_path = resolve_possible_symlink(path);
135139
char req[CAPIO_REQ_MAX_SIZE];
136-
sprintf(req, "%04d %ld %d %s", CAPIO_REQUEST_OPEN, tid, fd, path.c_str());
140+
sprintf(req, "%04d %ld %d %s", CAPIO_REQUEST_OPEN, tid, fd, resolved_path.c_str());
137141
buf_requests->write(req, CAPIO_REQ_MAX_SIZE);
138142
capio_off64_t res = bufs_response->at(tid)->read();
139143
LOG("Obtained from server %llu", res);

0 commit comments

Comments
 (0)