Unverified Commit 225552aa authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Disable interception during library shutdown

If we intercept function during shutdown we could try to access the
internal file map that has been already freed.

This woun't affect performance at runtime since we are always checking
only one boolean flags on every interception as before.

On the other hand should sppedup the shutdown of the library, because we
disable the interception of glibc library call before performing the
shutdown routines.
parent 624260e7
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ class PreloadContext {
    std::vector<std::string> mountdir_components_;
    std::string mountdir_;
    std::string daemon_addr_str_;
    bool initialized_;
    bool interception_enabled_;

    public:
    static PreloadContext* getInstance() {
@@ -91,8 +91,9 @@ class PreloadContext {
    std::shared_ptr<Distributor> distributor() const;
    const std::shared_ptr<FsConfig>& fs_conf() const;

    void initialized(const bool& flag);
    bool initialized() const;
    void enable_interception();
    void disable_interception();
    bool interception_enabled() const;
};


+84 −84

File changed.

Preview size limit exceeded, changes collapsed.

+2 −1
Original line number Diff line number Diff line
@@ -203,7 +203,7 @@ void init_preload() {
    } else {
        CTX->log()->info("{}() mountdir '{}' loaded", __func__, CTX->mountdir());
    }
    CTX->initialized(true);
    CTX->enable_interception();
    CTX->log()->debug("{}() exit", __func__);
}

@@ -211,6 +211,7 @@ void init_preload() {
 * Called last when preload library is used with the LD_PRELOAD environment variable
 */
void destroy_preload() {
    CTX->disable_interception();
    if (ld_margo_rpc_id == nullptr) {
        CTX->log()->debug("{}() No services in preload library used. Nothing to shut down.", __func__);
        return;
+11 −6
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ RelativizeStatus PreloadContext::relativize_fd_path(int dirfd,
                                                    bool resolve_last_link) const {

    // Relativize path should be called only after the library constructor has been executed
    assert(initialized_);
    assert(interception_enabled_);
    // If we run the constructor we also already setup the mountdir
    assert(!mountdir_.empty());

@@ -100,7 +100,7 @@ RelativizeStatus PreloadContext::relativize_fd_path(int dirfd,

bool PreloadContext::relativize_path(const char * raw_path, std::string& relative_path, bool resolve_last_link) const {
    // Relativize path should be called only after the library constructor has been executed
    assert(initialized_);
    assert(interception_enabled_);
    // If we run the constructor we also already setup the mountdir
    assert(!mountdir_.empty());

@@ -136,10 +136,15 @@ const std::shared_ptr<FsConfig>& PreloadContext::fs_conf() const {
    return fs_conf_;
}

void PreloadContext::initialized(const bool& flag) {
    initialized_ = flag;
void PreloadContext::enable_interception() {
    interception_enabled_ = true;
}

bool PreloadContext::initialized() const {
    return initialized_;
void PreloadContext::disable_interception() {
    interception_enabled_ = false;
}

bool PreloadContext::interception_enabled() const {
    return interception_enabled_;
}