Verified Commit 5c8a37d4 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Intercept chdir

parent 0399fb40
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@ extern void* libc_opendir;
extern void* libc_readdir;
extern void* libc_closedir;

extern void* libc_chdir;

void init_passthrough_if_needed();

#endif //IFS_PASSTHROUGH_HPP
+13 −1
Original line number Diff line number Diff line
@@ -498,3 +498,15 @@ int intcp_closedir(DIR* dirp) {
    }
    return (reinterpret_cast<decltype(&closedir)>(libc_closedir))(dirp);
}

int chdir(const char* path){
    init_passthrough_if_needed();
    CTX->log()->trace("{}() called with path {}", __func__, path);
    std::string rel_path(path);
    if (CTX->relativize_path(rel_path)) {
        CTX->log()->error("Attempt to chdir into adafs namespace: NOT SUPPORTED", __func__, path);
        errno = ENOTSUP;
        return -1;
    }
    return (reinterpret_cast<decltype(&chdir)>(libc_chdir))(path);
}
+5 −0
Original line number Diff line number Diff line
@@ -67,6 +67,9 @@ void* libc_opendir;
void* libc_readdir;
void* libc_closedir;

void* libc_chdir;


void init_passthrough_() {
    libc = dlopen("libc.so.6", RTLD_LAZY);
    if(libc == nullptr){
@@ -126,6 +129,8 @@ void init_passthrough_() {
    libc_readdir = dlsym(libc, "readdir");
    libc_closedir = dlsym(libc, "closedir");

    libc_chdir = dlsym(libc, "chdir");

    fs_config = std::make_shared<struct FsConfig>();

    //set the spdlogger and initialize it with spdlog