3

I am not able to understand the working of the following code that basically intercept the fork system call

pid_t fork(void)
{
    pid_t result;
    if (!actual_fork) {
        const int saved_errno = errno;

        *(void **)&actual_fork = dlsym(RTLD_NEXT, "fork");
        if (!actual_fork) {
            errno = EAGAIN;
            return (pid_t)-1;
        }

        errno = saved_errno;
    }

    result = (*actual_fork)();
    if (!result && commfd != -1) {
        struct message msg;
        notify(TYPE_FORK, &msg, sizeof msg);
    }

    printf("\n%d",result);
    fflush(stdout);
    return result;
}

when exporting the following intercepted code with LD_PRELOAD, then any process that calls for nested fork throws Segmentation fault

0 Answers0