From 725133ebb550d9bbeeca4a257e4cfe69929f1062 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Tue, 18 Oct 2022 13:33:32 -0500 Subject: [PATCH] Restore original interceptor.cc --- adapter/interceptor.cc | 55 ++++++++---------------------------------- adapter/interceptor.h | 35 ++++++++++----------------- ci/lint.sh | 13 +++++----- 3 files changed, 30 insertions(+), 73 deletions(-) diff --git a/adapter/interceptor.cc b/adapter/interceptor.cc index 41180f30b..ca477c476 100644 --- a/adapter/interceptor.cc +++ b/adapter/interceptor.cc @@ -73,8 +73,7 @@ void PopulateBufferingPath() { populated = true; } -bool IsTracked(const std::string& path, bool log) { - if (log) { LOG(INFO) << "IsTracked path? " << path << std::endl; } +bool IsTracked(const std::string& path) { if (hermes::adapter::exit) { return false; } @@ -83,12 +82,7 @@ bool IsTracked(const std::string& path, bool log) { std::string abs_path = WeaklyCanonical(path).string(); for (const auto& pth : INTERCEPTOR_LIST->hermes_flush_exclusion) { - if (abs_path.rfind(pth) != std::string::npos) { - if (log) { - LOG(INFO) << "Path " << path - << " is not tracked (hermes_flush_exclusion)" - << " because: " << pth << std::endl; - } + if (abs_path.find(pth) != std::string::npos) { return false; } } @@ -98,32 +92,20 @@ bool IsTracked(const std::string& path, bool log) { } for (const auto& pth : INTERCEPTOR_LIST->hermes_paths_inclusion) { - if (abs_path.rfind(pth) != std::string::npos) { - if (log) { - LOG(INFO) << "Path " << path << "is tracked (hermes_paths_inclusion)" - << " because: " << pth << std::endl; - } + if (abs_path.find(pth) != std::string::npos) { return true; } } for (auto &pth : kPathExclusions) { - if (abs_path.rfind(pth) != std::string::npos) { - if (log) { - LOG(INFO) << "Path " << path << " is not tracked (kPathExclusions)" - << " because: " << pth << std::endl; - } + if (abs_path.find(pth) != std::string::npos) { return false; } } for (const auto& pth : INTERCEPTOR_LIST->hermes_paths_exclusion) { - if (abs_path.rfind(pth) != std::string::npos) { - if (log) { - LOG(INFO) << "Path " << path - << " is not tracked (hermes_paths_exclusion)" - << " because: " << pth << std::endl; - } + if (abs_path.find(pth) != std::string::npos || + pth.find(abs_path) != std::string::npos) { return false; } } @@ -132,18 +114,10 @@ bool IsTracked(const std::string& path, bool log) { auto buffer_mode = INTERCEPTOR_LIST->adapter_mode; if (buffer_mode == AdapterMode::kBypass) { if (list->adapter_paths.empty()) { - if (log) { - LOG(INFO) << "Path " << path << " is not tracked (kBypass)" - << " because adapter_paths empty " << std::endl; - } return false; } else { for (const auto& pth : list->adapter_paths) { if (path.find(pth) == 0) { - if (log) { - LOG(INFO) << "Path " << path << " is not tracked (kBypass)" - << " because: " << pth << std::endl; - } return false; } } @@ -154,25 +128,16 @@ bool IsTracked(const std::string& path, bool log) { } } -bool IsTracked(FILE* fh, bool log) { - if (log) { LOG(INFO) << "IsTracked fh?" << std::endl; } +bool IsTracked(FILE* fh) { if (hermes::adapter::exit) return false; atexit(OnExit); - std::string path = GetFilenameFromFP(fh); - if (path == "") return false; - return IsTracked(path, log); + return IsTracked(GetFilenameFromFP(fh)); } -bool IsTracked(int fd, bool log) { - if (log) { LOG(INFO) << "IsTracked fd?" << std::endl; } +bool IsTracked(int fd) { if (hermes::adapter::exit) return false; atexit(OnExit); - std::string path = GetFilenameFromFD(fd); - if (path == "") { - if (log) { LOG(INFO) << fd << "is not tracked" << std::endl; } - return false; - } - return IsTracked(path, log); + return IsTracked(GetFilenameFromFD(fd)); } void OnExit(void) { hermes::adapter::exit = true; } diff --git a/adapter/interceptor.h b/adapter/interceptor.h index 8ede96e0c..bc68196a5 100644 --- a/adapter/interceptor.h +++ b/adapter/interceptor.h @@ -55,24 +55,22 @@ inline std::vector StringSplit(const char* str, char delimiter) { } return v; } - +inline std::string GetFilenameFromFP(FILE* fh) { + char proclnk[kMaxPathLen]; + char filename[kMaxPathLen]; + int fno = fileno(fh); + snprintf(proclnk, kMaxPathLen, "/proc/self/fd/%d", fno); + size_t r = readlink(proclnk, filename, kMaxPathLen); + filename[r] = '\0'; + return filename; +} inline std::string GetFilenameFromFD(int fd) { char proclnk[kMaxPathLen]; char filename[kMaxPathLen]; - if (fd == -1) return ""; snprintf(proclnk, kMaxPathLen, "/proc/self/fd/%d", fd); size_t r = readlink(proclnk, filename, kMaxPathLen); - if (r > 0) { - return std::string(filename, r); - } else { - return ""; - } -} - -inline std::string GetFilenameFromFP(FILE* fh) { - if (fh == nullptr) return ""; - int fno = fileno(fh); - return GetFilenameFromFD(fno); + filename[r] = '\0'; + return filename; } /** @@ -202,12 +200,6 @@ void OnExit(void); } \ } -#define REQUIRE_API(api_name) \ - if (real_api->api_name == nullptr) { \ - LOG(FATAL) << "HERMES Adapter failed to map symbol: " \ - #api_name << std::endl; \ - exit(1); - namespace hermes::adapter { /** * Loads the buffering paths for Hermes Adapter to exclude. It inserts the @@ -224,7 +216,7 @@ void PopulateBufferingPath(); * @return true, if file should be tracked. * false, if file should not be intercepted. */ -bool IsTracked(const std::string& path, bool log = false); +bool IsTracked(const std::string& path); /** * Check if fh should be tracked. In this method, first Convert fh to path. @@ -234,8 +226,7 @@ bool IsTracked(const std::string& path, bool log = false); * @return true, if file should be tracked. * false, if file should not be intercepted. */ -bool IsTracked(FILE* fh, bool log = false); -bool IsTracked(int fd, bool log = false); +bool IsTracked(FILE* fh); } // namespace hermes::adapter #else /** diff --git a/ci/lint.sh b/ci/lint.sh index b35b21522..19e5db779 100644 --- a/ci/lint.sh +++ b/ci/lint.sh @@ -1,10 +1,11 @@ +#!/bin/bash HERMES_ROOT=$1 ADAPTER=${HERMES_ROOT}/adapter cpplint --recursive \ ---exclude=${HERMES_ROOT}/src/stb_ds.h \ ---exclude=${ADAPTER}/posix/real_api.h \ ---exclude=${ADAPTER}/stdio/real_api.h \ ---exclude=${ADAPTER}/mpiio/real_api.h \ -${HERMES_ROOT}/adapter ${HERMES_ROOT}/benchmarks ${HERMES_ROOT}/data_stager \ -${HERMES_ROOT}/src ${HERMES_ROOT}/test +--exclude="${HERMES_ROOT}/src/stb_ds.h" \ +--exclude="${ADAPTER}/posix/real_api.h" \ +--exclude="${ADAPTER}/stdio/real_api.h" \ +--exclude="${ADAPTER}/mpiio/real_api.h" \ +"${HERMES_ROOT}/adapter" "${HERMES_ROOT}/benchmarks" "${HERMES_ROOT}/data_stager" \ +"${HERMES_ROOT}/src" "${HERMES_ROOT}/test"