On Thu, May 6, 2010 at 5:36 PM, Bob Proulx <b...@proulx.com> wrote:
> Peng Yu wrote:
>> Is there a way to overload operators like '>' and '>>' in bash, just
>> as overloading in C++, etc. Suppose I have already made some bash
>> program using '>' and '>>' without thinking about symbolic link, but I
>> begin aware of them later. I would be cumbersome to add a test
>> statement and deciding whether 'rm' or not for each usage of '>' and
>> '>>'.
>
> It sounds to me like you are trying to implement a "script space"
> version of copy-on-write semantics?  Perhaps you should investigate
> using one of the filesystem based solutions.  It would probably give
> you a better result.
>
>> A more general question is how to change the behavior of a program
>> (for example compiled from C code) to delete symbolic link and write a
>> new file, without recompiling the program.
>
> A Comment: Symbolic links are designed to be transparent.  Normal
> programs are not aware of them.
>
> You could probably create an LD_PRELOAD library to intercept file
> modification calls and then handle them in your own code.  But I think
> it would be difficult to do it all completely correctly and not to
> introduce bugs.  I advise against it.

Would you please elaborate a little more on how to use LD_PRELOAD to
modify the call. If the library (for example, 'open' from stdlib.h)
is statically compiled in the binary, is LD_PRELOAD going to replace
it with a different 'open' function?

-- 
Regards,
Peng


Reply via email to