On Thu, 22 Feb 2018 13:50:13 -0600, Scott Cheloha wrote:

> I think setjmping from a signal handler to put a time limit on
> pclose is too magical, especially when the alternative doesn't
> require much more code.


> But I do think putting a time limit on our wait for wall to do its
> job is a reasonable precaution, though, so:
>   * Replace popen with pipe/fork/execle,
>   * fprintf -> dprintf, fwrite -> write, and
>   * Strip SA_RESTART from SIGALRM's sigaction so we EINTR out
>     of our wait(2) after 30 seconds.
> We wait (instead of waitpid) to pick up any stragglers from prior
> calls to timewarn() that we had to leave behind.

You could use fdopen() and keep using stdio but I suppose it doesn't
really matter--dprintf() will effectively get you line buffering.

The only thing that concerns me is the possibility of closing the
wrong fd if stdin is not actually open (unlikely).  I prefer an
idiom like the following:

        if (dup2(fd[0], STDIN_FILENO) == -1) {
                syslog(LOG_ERR, "dup2: %m");
        if (fd[0] != STDIN_FILENO)

Otherwise OK.

 - todd

Reply via email to