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().

--

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. The pipe to child is held open for reading
       so child can be restarted if it dies without losing data.

       fifo also prints anything it sees on stdin to child  without  intermin-
       gling partial messages. If end of file is seen on stdin, fifo will stop
       monitoring it and not restart.

       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  normally  runs  forever. If child stops after reading the banner,
       fifo will restart it.  fifo never gives up.

       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 propagated 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 propagate ALRM sig-
       nals to child.

       In  situations where fifo receives data from both stdin and file at the
       same time, fifo will eventually stop reading one stream  if  the  other
       fails  to  properly  newline-terminate  its messages. This is currently
       considered a feature in the sense that messages will  not  intermingle,
       but it's conceivable that it could be a problem.

SEE ALSO

       mkfifo(1), mkfifo(2), pipe(7)