So, basically, if we start arbitrary commands, then
the classic loop 
    /* Wait for the child to exit.  */
    while (waitpid(cpid, &status, 0) == -1 && errno == EINTR)
            continue;


is not quite enough.

See the small note in manpages (not only us, but everyone):
     WIFSTOPPED(status)
             True if the process has not terminated, but has stopped and can
             be restarted.  This macro can be true only if the wait call
             specified the WUNTRACED option or if the child process is being
             traced (see ptrace(2)).

this means that somebody could run a command that forks, and then its child
(our grand-child) could use ptrace on its parent, and then we would get
a notification with WIFSTOPPED (assuming the current kernel bug is fixed).

e.g., something like that:

while (1) {
        if (waitpid(cpid, &status, 0) == -1) {
                if (errno == EINTR)
                        continue;
        } else {
                if (WIFSTOPPED(status))
                        continue;
        }
        break;
}

or should we just assume no-one will be nasty enough to do that ?

Reply via email to