title: Explanation: fork system call interception
body: <p>I am not able to understand the working of the following code that basically intercept the fork system call</p>
  
  <pre><code>pid_t fork(void)
  {
      pid_t result;
      if (!actual_fork) {
          const int saved_errno = errno;
  
          *(void **)&amp;actual_fork = dlsym(RTLD_NEXT, "fork");
          if (!actual_fork) {
              errno = EAGAIN;
              return (pid_t)-1;
          }
  
          errno = saved_errno;
      }
  
      result = (*actual_fork)();
      if (!result &amp;&amp; commfd != -1) {
          struct message msg;
          notify(TYPE_FORK, &amp;msg, sizeof msg);
      }
  
      printf("\n%d",result);
      fflush(stdout);
      return result;
  }
  </code></pre>
  
  <p>when exporting the following intercepted code with LD_PRELOAD, then any process that calls for nested fork throws <strong>Segmentation fault</strong></p>