title: Ptrace options not working in parent process
body: <p>Ptrace options dont set the correct status when the desired systemcalls resume in the parent process. I can only use whats seen here no PEEKUSER, SYSGOOD or SYSCALL. Ive read the ptrace man and looked for examples for the past few days, Im mentally exhausted.</p>
  <p>Any ideas/tips, no matter how small, are welcome. thanks.</p>
  <p>argument: <code>/bin/bash -c &quot;echo 'first test' | wc -c&quot;</code></p>
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;sys/ptrace.h&gt;
  
  int wait_for_syscall(pid_t child) {
      int status;
      while (1) {
          ptrace(PTRACE_CONT, child, 0, 0);
          waitpid(child, &amp;status, 0);
          if (WIFSTOPPED(status) &amp;&amp; WSTOPSIG(status) | 0x80)
              return 0;
          if (WIFEXITED(status))
              return 1;
      }
  }
  
  int main(int argc, char *argv[]) {
      int status;
      int counter = 0;
      pid_t pid = fork();
      if (pid &lt; 0)
          exit(1);
      else if (pid == 0) {
          ptrace(PTRACE_TRACEME, pid, NULL, NULL);
          raise(SIGSTOP);
          return execve(argv[1], &amp;argv[1], NULL);
      } else {
          wait(&amp;status);
          ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_EXITKILL | PTRACE_O_TRACEEXEC | PTRACE_O_TRACESECCOMP);
  
          while (1) {
              if (wait_for_syscall(pid) != 0) break;
              
              if (status &gt;&gt; 8 == (SIGTRAP | (PTRACE_EVENT_EXEC &lt;&lt; 8)))
                  counter++;
  
              if (status &gt;&gt; 8 == (SIGTRAP | (PTRACE_EVENT_SECCOMP &lt;&lt; 8)))
                  counter++;
  
              if (wait_for_syscall(pid) != 0) break;
          }
      }
      return 0;
  }
  </code></pre>