質問

Let's assume that we've several non-identical versions of the same folder in different locations as follows:

  • /in/some/location/version1
  • /different/path/version2
  • /third/place/version3

Each version of them contains callerFile, which is a pre-compiled executable that we can't control its working functionality. this callerFile will create and edit a folder called cache

  • /some/fourth/destination/cache

So we've contradiction between the setting of every version so what I want to do is converting the /some/fourth/destination/cache to a link with 3 different destinations

  • /some/fourth/destination/cache --> /in/some/location/version1/cache
  • /some/fourth/destination/cache --> /different/path/version2/cache
  • /some/fourth/destination/cache --> /third/place/version3/cache

so for example:

  • if /in/some/location/version1/callerFile calls /some/fourth/destination/cache it should redirected to /in/some/location/version1/cache
  • and if /different/path/version2/callerFile calls /some/fourth/destination/cache it should redirected to /different/path/version2/cache
  • and if /third/place/version3/callerFile calls /some/fourth/destination/cache it should redirected to /third/place/version3/cache

So, How can I do so on Ubuntu 12.04 64 bit Operating System?

役に立ちましたか?

解決

Assuming you have no control over what callerFile actually does, I mean it does what it wants and always the same, so the conclusion is you need to modify it's environment. This will be quite advanced trick, requiring deep experience of Linux kernel and Unix programming in general, and you should think over if it's worth. It will also require root priviledges on the machine where your callerFile binary exists.

Solution I'd propose would be creating an executable ( or some script calling one of exec() family function ), which will prepare special environment ( or make sure it's ready to use ), based on "mount -o bind" or unshare() system call.

Like said, playing with so called "execution context", is quite advanced trick. Theoretically you could also try some autofs-like solution, however you'll probably end up with the same, and bindmount/unshare will be probably more effective than some FS-detection daemon. I wouldn't recommend diving into FUSE, for the same reason. And playing with some over-complicated game with symlinks is probably not the way too.

http://www.kernel.org/doc/Documentation/unshare.txt

Note: whatever "callerFile" binary does, I'm pretty sure it won't check its own filename, which makes possible replacing it with something else in-between, which will do exec() on "callerFileRenamed".

As I understand it, basically what you want is to get different result with the same activity, distinguished by some condition external to activity itself, like, for example, returning different list for "ls" in same directory, based upon e.g. UID of user who issued "ls" command, without modifying some ./ls program binary.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top