Subject: Re: Files-that-are-commands.
To: None <netbsd-help@netbsd.org, rkr@rkr.kcnet.com>
From: Paul Sander <paul@wakawaka.com>
List: netbsd-help
Date: 01/12/2000 02:13:46
rkr@rkr.kcnet.com wrote:

>A passing thought just hit me, something that I don't know how to do under
>UNIX-like systems.  (Surely, it _is_ possible?)

>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
>under a kind of pipe-device (I believe the one that worked this way was a
>part of the AmiTCP/IP distribution, but that's neither here nor there).

>Effectively, this is like telling the program to popen() the command, save
>that the program doesn't have to know to use popen()---it just uses
>open() or fopen() or whatever.

>(As I write this, it occurs to me that there are potential security
>problems---you don't want to run this in the reader's aegis, and running
>it as the file-owner makes it effectively a setuid program.  An important
>point, however, is that the program, while running, isn't available to the
>user, save via stdout (and stderr?) coming out of read() calls...if the
>executing command tries to read stdin, it should obviously get EOF.)


>Anyway, can it be done with commands that ship with NetBSD?


Have you considered writing a daemon that writes to a named pipe?
Use mknod to create a fifo file, and run a program that writes to
the pipe, then closes it, then writes to it again.  When a second
program opens the pipe for reading, it will read the initial content
from the daemon, then get an EOF when the daemon closes the pipe.

The two programs run in different processes, so setid issues don't
come into play.  You might put some thought into the permissions on
the pipe, though.