Add fifo program.

This addition replaces the fifo program removed in daemontools-0.60.

This is the second draft. The first version had an infinite loop on platforms that didn't support the FIONREAD ioctl. The ioctl has been removed in favor of a select().

fifo(8)                                                                fifo(8)

NAME
       fifo - create and read a named pipe while writing to child.

SYNOPSIS
       fifo file child

DESCRIPTION
       fifo  prints everything fed to the named pipe file to standard input of
       child.  file is held open  for  writing  so  that  other  programs  can
       repeatedly  open  and  close  file.  The pipe to child is held open for
       reading so child can be restarted if it dies without losing data.

       fifo creates file if file does not exist.

       fifo makes sure file is actually a named pipe.

       fifo prints a newline-terminated banner message ("fifostart") to  child
       on  startup to ensure it is running before reading from file.  If child
       dies before the banner is read, fifo exits  and  prints  a  message  on
       standard error.

       fifo tries to restart child if it stops. It never gives up.

       fifo normally runs forever.

       fifo  can  be  shut  down with a TERM signal.  fifo will then read from
       file until the next newline. If the last character read was  already  a
       newline,  fifo stops reading immediately. If fifo doesn't see a newline
       within 2 seconds, it gives up and stops reading  immediately.  If  fifo
       receives  an  ALRM signal before either of these, it gives up and stops
       reading immediately. ALRM signals are no  longer  propogated  to  child
       once a TERM is received.

       fifo will also wait until its buffers have been flushed and the pipe to
       child has been read before shutting down. If child exits before this is
       done, fifo will restart it.

EXIT CODES
       fifo normally exits 0 after a TERM signal and child stops.

       fifo exits 100 for improper usage with a message on standard error.

       fifo exits 111 for any other problems with a message on standard error.

SIGNALS
       TERM
           fifo  stops  reading  from file, empties its buffer, and closes the
           pipe to child.  child is expected to continue until it notices  end
           of input and exit gracefully.  fifo then stops.

       ALRM
           fifo  sends  an  ALRM  signal  to  child,  unless it has previously
           received a TERM signal. After TERM, fifo considers an ALRM to  sig-
           nal end of next newline search.

BUGS
       If fifo dies, any messages it has in its buffer are lost.

       Once fifo receives a TERM signal, it will no longer propogate ALRM sig-
       nals to child.

SEE ALSO
       mkfifo(1), mkfifo(2)

                                                                       fifo(8)