Subject: Re: Files-that-are-commands.
To: Paul Sander <paul@wakawaka.com>
From: Richard Rauch <rkr@rkr.kcnet.com>
List: netbsd-help
Date: 01/12/2000 07:19:40
> >I'd like to have a file (say, my .signature) run a shell command everytime
> >it is read.  On the dear old Amiga, one could do this by using a filename
 [...]
> Have you considered writing a daemon that writes to a named pipe?

Not until it was suggested to me (Dmitri hinted at it as well, by
mentioning mkfifo).  (^&

But there are some problems:

 * Unless I modify the system boot scripts, I will have to at least
   logon to start the daemon.  (Supposing that I want the appearance
   of the fifo always emitting command output, regardless of whether
   I've logged on since the most recent reboot.  In a multi-user
   environment, finger-info .plan/.project files might be good
   candidates for this kind of amusement.)

 * If two readers access the pipe at the same time, what happens?
   Is the pipe busy?  Do they get bytes/lines in round-robin?
   Something else?  Will they both get the same EOF?  The man-page
   doesn't say, so there probably is no guarantee against the future.

 * The pipe-filling command normally starts ``whenever'' rather
   than when the pipe is opened for reading.  A subtle point, but
   date-/time-sensitive actions (or ``current status'' outputs)
   will have problems.  Of course, if the fifo is suitably blocked
   on write until there's a reader, one can wrap the ``real'' program
   in a script that emits a blank line into the pipe, first.

 * If the daemon dies, readers can end up stalled indefinitely.

Then there are a few lesser problems (e.g., the named pipe getting
deleted) which can be guarded against with suitably inelegant code.


Currently, a portal-filesystem approach seems much better, though it
requires super-user manipulation, it isn't portable, and the whole thing
really shouldn't involve a TCP connection.

Midway between fifo's and /p in terms of desirability, I could just have a
daemon regenerate the file in question, then sleep for a second or two (or
for a minute or two), then repeat...  Stupid, inefficient, and ugly, but
relatively bullet-proof and portable while providing nearly all of the
desired features.  (Even if the daemon isn't running, the file contents
will be there.  If updated contents are put in place with a mv, there
should be no race condition, correct?)


From the sound of it, though, what I really want doesn't exist.  Is that
safe to say?  (^&


  "I probably don't know what I'm talking about."  --rkr@rkr.kcnet.com