Dynamic file content generation: Satisfying a 'file open' by a 'process execution'
I have a read-only file, F.
A program, P, that I'm not the author of, needs to read F.
I want the content of F to come from another 'generator' program, G, whenever P tries to read F (taking F to be an ordinary file) and not any earlier.
I tried doing the following:
$ mkfifo /well-known/path/to/F # line #1
$ G > /well-known/path/to/F # line #2
Now, when P starts up and tries to read F, it appears to be able to read the output generated by G just as I wished it to. However, it can do so only once, since G after all gets to run only once! So, if P had a need to read F again later in its execution, it would end up blocking on the fifo!
My question is, other than bracketing line #2 above in some sort of an infinite loop, is there any other (elegant) alternative for the above?
What I'm hoping for is, some way of registering a 'hook' program into the file-open system call such that the file-open would result in the launching of the hook-program and the file-read in the reading of the hook-program output. Obviously the assumption here is: the read will happen sequentially from file beginning to file end, and never in random seeks.
I have a read-only file, F.
A program, P, that I'm not the author of, needs to read F.
I want the content of F to come from another 'generator' program, G, whenever P tries to read F (taking F to be an ordinary file) and not any earlier.
I tried doing the following:
$ mkfifo /well-known/path/to/F # line #1
$ G > /well-known/path/to/F # line #2
Now, when P starts up and tries to read F, it appears to be able to read the output generated by G just as I wished it to. However, it can do so only once, since G after all gets to run only once! So, if P had a need to read F again later in its execution, it would end up blocking on the fifo!
My question is, other than bracketing line #2 above in some sort of an infinite loop, is there any other (elegant) alternative for the above?
What I'm hoping for is, some way of registering a 'hook' program into the file-open system call such that the file-open would result in the launching of the hook-program and the file-read in the reading of the hook-program output. Obviously the assumption here is: the read will happen sequentially from file beginning to file end, and never in random seeks.
No comments:
Post a Comment