
I have a need for a way for a regular user (i.e. non root) to "override" a file on a filesystem with one of their own, but just for the lifetime of a script. I'll give you an example. One of my users runs a program which is distributed in a package (i.e. not changeable by them). That program is looking for a file, /path1/file1. My user would like to change this file to a different version of the file in different scripts. I'm not aware of one, but is there a way to redirect file open calls for /path1/file1 to /path2/file2 in a script? It only has to be for file open/read calls, and not write. The /path1 filesystem is not writeable by the user. Is there maybe a FUSE filesystem which will allow this, or something else? Cheers, Sean

Hi, Is unionfs a solution? https://en.wikipedia.org/wiki/UnionFS It layers filesystems. so you can create an upper layer, write the file and remove the layer. (So the modified file disappears). Regards Peter On Wed, Aug 26, 2015 at 2:12 AM, Sean Crosby <richardnixonshead@gmail.com> wrote:
I have a need for a way for a regular user (i.e. non root) to "override" a file on a filesystem with one of their own, but just for the lifetime of a script.
I'll give you an example.
One of my users runs a program which is distributed in a package (i.e. not changeable by them). That program is looking for a file, /path1/file1. My user would like to change this file to a different version of the file in different scripts.
I'm not aware of one, but is there a way to redirect file open calls for /path1/file1 to /path2/file2 in a script? It only has to be for file open/read calls, and not write. The /path1 filesystem is not writeable by the user.
Is there maybe a FUSE filesystem which will allow this, or something else?
Cheers, Sean
_______________________________________________ luv-main mailing list luv-main@luv.asn.au http://lists.luv.asn.au/listinfo/luv-main

Peter Ross <petrosssit@gmail.com> writes:
Is unionfs a solution? https://en.wikipedia.org/wiki/UnionFS
NB: in current Linux kernels this is deprecated by https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/Docume...

On Tue, 25 Aug 2015 18:12:14 Sean Crosby wrote:
I'm not aware of one, but is there a way to redirect file open calls for /path1/file1 to /path2/file2 in a script? It only has to be for file open/read calls, and not write. The /path1 filesystem is not writeable by the user.
This is something that you could do with LD_PRELOAD. There's probably a module out there to do it already if you google it, but if not it's not that hard to write if you've good at C coding. -- My Main Blog http://etbe.coker.com.au/ My Documents Blog http://doc.coker.com.au/ -- Sent from my Samsung Galaxy Note 3 with K-9 Mail.

Russell Coker <russell@coker.com.au> writes:
On Tue, 25 Aug 2015 18:12:14 Sean Crosby wrote:
I'm not aware of one, but is there a way to redirect file open calls for /path1/file1 to /path2/file2 in a script? It only has to be for file open/read calls, and not write. The /path1 filesystem is not writeable by the user.
This is something that you could do with LD_PRELOAD. There's probably a module out there to do it already if you google it, but if not it's not that hard to write if you've good at C coding.
fakeroot(1) can do this, I think. LD_PRELOAD is one of the available strategies. As used by Debian to build packages, it basically says: Anytime you try to do something that's not allowed, I'll claim that I did it, and remember (inside myself) what was done, so if you e.g. install a file then read it, I'll act like it worked. But outside me, nothing has actually changed. It can persist its sate between runs. Ref. http://manpages.debian.org/cgi-bin/man.cgi?query=fakeroot

On Thu, 27 Aug 2015 at 13:08 Trent W. Buck <trentbuck@gmail.com> wrote:
fakeroot(1) can do this, I think. LD_PRELOAD is one of the available strategies.
fakeroot doesn't intercept open(): brian@prune:~$ fakeroot touch /etc/newfile touch: cannot touch ‘/etc/newfile’: Permission denied brian@prune:~$

On 08/27/2015 02:02 PM, Brian May wrote:
On Thu, 27 Aug 2015 at 13:08 Trent W. Buck <trentbuck@gmail.com <mailto:trentbuck@gmail.com>> wrote:
fakeroot(1) can do this, I think. LD_PRELOAD is one of the available strategies.
fakeroot doesn't intercept open():
brian@prune:~$ fakeroot touch /etc/newfile touch: cannot touch ‘/etc/newfile’: Permission denied brian@prune:~$
_______________________________________________ luv-main mailing list luv-main@luv.asn.au http://lists.luv.asn.au/listinfo/luv-main Hi, Some time ago I needed a script which would detect that Cheese had taken a photo, it then acted on that by printing the file and then sending it to the "Printed" folder. I forget the handle of the guy who sent me the script but it relied on "inotify" and to my mind it may be close to what is needed, this is not my work but here it is:
inotifywait -m -e close_write ~/Pictures/webcam --format "%w%f" | \ while read filename; do lpr -P Photosmart-C5200-Series "$filename"; mv "$filename" ~/Pictures/webcam/printed; done The inotifywait (part of the inotifytools package) waits for writes to the folder. The '-m' flag makes it run indefinitely (instead of running it in a script loop which could mean it might miss an event). The '--format' outputs only the file names that were written. The output of the inotify is piped to a while loop (alternatively xargs could be used to run a command for each filename input). The while loop reads the filename from standard input, prints it to the printer, and then moves it to the destination directory. If you are using CUPS for your printing, then there are some image processing options that can be specified if the default is not what you want. BTW the resulting Photobooth was a resounding success Andrew Greig (I noticed your question on the MLUG list, but hadn't had a chance to respond).

On Tue, 25 Aug 2015 18:12:14 Sean Crosby wrote:
I'm not aware of one, but is there a way to redirect file open calls for /path1/file1 to /path2/file2 in a script? It only has to be for file open/read calls, and not write. The /path1 filesystem is not writeable by the user.
This is something that you could do with LD_PRELOAD. There's probably a module out there to do it already if you google it, but if not it's not that hard to write if you've good at C coding. -- My Main Blog http://etbe.coker.com.au/ My Documents Blog http://doc.coker.com.au/ -- Sent from my Samsung Galaxy Note 3 with K-9 Mail.

On 26/08/2015 2:12 AM, Sean Crosby wrote:
I have a need for a way for a regular user (i.e. non root) to "override" a file on a filesystem with one of their own, but just for the lifetime of a script.
I'll give you an example.
One of my users runs a program which is distributed in a package (i.e. not changeable by them). That program is looking for a file, /path1/file1. My user would like to change this file to a different version of the file in different scripts.
I'm not aware of one, but is there a way to redirect file open calls for /path1/file1 to /path2/file2 in a script? It only has to be for file open/read calls, and not write. The /path1 filesystem is not writeable by the user.
How about something as simple as this: if [ -f /path2/file2 ] then FILEX=/path2/file2 else FILEX=/path1/file1 fi If /path2/file2 is too, errr variable, then perhaps an environment variable or a passed parameter? Cheers A.
participants (7)
-
Andrew Greig
-
Andrew McGlashan
-
Brian May
-
Peter Ross
-
Russell Coker
-
Sean Crosby
-
trentbuck@gmail.com