diff --git a/src/common/capio/env.hpp b/src/common/capio/env.hpp index ebc49bf99..e0cc2f002 100644 --- a/src/common/capio/env.hpp +++ b/src/common/capio/env.hpp @@ -85,14 +85,29 @@ inline int get_capio_log_level() { inline std::string get_capio_workflow_name() { static std::string name; + + START_LOG(capio_syscall(SYS_gettid), "call()"); + if (name.empty()) { + LOG("name is empty"); +#ifdef __CAPIO_POSIX + LOG("Fetching name from std::env"); auto tmp = std::getenv("CAPIO_WORKFLOW_NAME"); if (tmp != nullptr) { name = tmp; } else { name = CAPIO_DEFAULT_WORKFLOW_NAME; } +#else + LOG("fetching name from workflow_name"); + name = workflow_name; + if (name.size() == 0) { + LOG("Falling back to default workflow name"); + name = CAPIO_DEFAULT_WORKFLOW_NAME; + } +#endif } + return name; } diff --git a/src/common/capio/shm.hpp b/src/common/capio/shm.hpp index 6a3fcbe37..71128a652 100644 --- a/src/common/capio/shm.hpp +++ b/src/common/capio/shm.hpp @@ -52,9 +52,11 @@ class CapioShmCanary { std::string _canary_name; public: - explicit CapioShmCanary(std::string capio_workflow_name) : _canary_name(capio_workflow_name) { + explicit CapioShmCanary(std::string capio_workflow_name = CAPIO_DEFAULT_WORKFLOW_NAME) + : _canary_name(get_capio_workflow_name()) { START_LOG(capio_syscall(SYS_gettid), "call(capio_workflow_name: %s)", _canary_name.data()); if (_canary_name.empty()) { + LOG("Empty _canary_name"); _canary_name = get_capio_workflow_name(); } _shm_id = shm_open(_canary_name.data(), O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); diff --git a/src/posix/handlers/access.hpp b/src/posix/handlers/access.hpp index 4a7d22622..56c48eabc 100644 --- a/src/posix/handlers/access.hpp +++ b/src/posix/handlers/access.hpp @@ -9,7 +9,7 @@ int access_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long a const std::string_view pathname(reinterpret_cast(arg0)); auto tid = static_cast(syscall_no_intercept(SYS_gettid)); START_LOG(tid, "call()"); - if (is_forbidden_path(pathname)) { + if (is_forbidden_path(pathname) || !is_capio_path(pathname)) { LOG("Path %s is forbidden: skip", pathname.data()); return CAPIO_POSIX_SYSCALL_REQUEST_SKIP; } diff --git a/src/posix/handlers/chdir.hpp b/src/posix/handlers/chdir.hpp index e5ad4f954..30cd69a71 100644 --- a/src/posix/handlers/chdir.hpp +++ b/src/posix/handlers/chdir.hpp @@ -12,8 +12,10 @@ int chdir_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long ar START_LOG(tid, "call(path=%s)", pathname.data()); - if (is_forbidden_path(pathname)) { + syscall_no_intercept_flag = true; + if (is_forbidden_path(pathname) || !is_capio_path(pathname)) { LOG("Path %s is forbidden: skip", pathname.data()); + syscall_no_intercept_flag = false; return CAPIO_POSIX_SYSCALL_SKIP; } @@ -24,6 +26,7 @@ int chdir_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long ar consent_request_cache_fs->consent_request(path, tid, __FUNCTION__); + syscall_no_intercept_flag = false; // if not a capio path, then control is given to kernel return CAPIO_POSIX_SYSCALL_SKIP; } diff --git a/tests/unit/server/src/main.cpp b/tests/unit/server/src/main.cpp index b3c3f3534..c94508840 100644 --- a/tests/unit/server/src/main.cpp +++ b/tests/unit/server/src/main.cpp @@ -1,6 +1,9 @@ +#include "capio/constants.hpp" #include #include +std::string workflow_name = CAPIO_DEFAULT_WORKFLOW_NAME; + std::string node_name; #include "CapioCacheSPSCQueueTests.hpp" diff --git a/tests/unit/syscall/src/main.cpp b/tests/unit/syscall/src/main.cpp index bc5961c3a..c3d8572e1 100644 --- a/tests/unit/syscall/src/main.cpp +++ b/tests/unit/syscall/src/main.cpp @@ -1,5 +1,8 @@ +#include "capio/constants.hpp" #include +std::string workflow_name = CAPIO_DEFAULT_WORKFLOW_NAME; + char **build_args() { char **args = (char **) malloc(3 * sizeof(uintptr_t));