Commit e4755bfa authored by Ramon Nou's avatar Ramon Nou Committed by Ramon Nou
Browse files

Adding pthread_atfork to syscall

parent 8dcb2dab
Loading
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -49,4 +49,11 @@ void
destroy_preload() __attribute__((destructor));
#endif

void
at_fork_syscall();
void
at_child_syscall();
void
at_parent_syscall();

#endif // IOINTERCEPT_PRELOAD_HPP
+28 −1
Original line number Diff line number Diff line
@@ -337,6 +337,9 @@ init_environment() {

} // namespace gkfs::preload


std::atomic<bool> init{false};

/**
 * Called initially ONCE when preload library is used with the LD_PRELOAD
 * environment variable
@@ -346,7 +349,10 @@ init_preload() {
    // The original errno value will be restored after initialization to not
    // leak internal error codes
    auto oerrno = errno;

    if(!init) {
        init = true;
        pthread_atfork(&at_fork_syscall, &at_parent_syscall, &at_child_syscall);
    }
    CTX->enable_interception();
    gkfs::preload::start_self_interception();

@@ -459,3 +465,24 @@ gkfs_end() {

    return 0;
}

void
at_fork_syscall() {
    printf("%d ->At fork, %d\n", gettid(), CTX->interception_enabled());
    destroy_preload();
}
void
at_parent_syscall() {
    printf("%d ->At fork parent %d\n", gettid(), CTX->interception_enabled());
    init_preload();
    printf("%d -> x At fork parent %d\n", gettid(),
           CTX->interception_enabled());
}

void
at_child_syscall() {

    printf("%d ->At fork child %d\n", gettid(), CTX->interception_enabled());
    init_preload();
    printf("%d -> x At fork child %d\n", gettid(), CTX->interception_enabled());
}