hi, Is there a way to intercept file access calls ?
Some way to catch open()? or something like that ?

What I have is a modules which access/modify config files in many dirs. The problem is that the path to the files is hardcoded
What I will do is go over all the modules and change in any place I see suspicious code to get the the path from function I write, so I can modify it to whatever I want...but still after this I can't be 100% sure i'll find them all (i haven't written the code).
So I was thinking of a way to intercept these accesses and fix the code. The problem is that it is running system, I mean I need to run both scenarios together for some time to find the offending code.
I was thinking of using lsof and inotify, but both of these doesn't work. Because the new structure will include symlinks (both scenarios at the same time), for which inotify can't detect accesses/changes.
And I want to detect in what part of the code this happens so i can fix it
So if it is perl solution I can print caller() info and find it easy ?
Any ideas


UPDATE:
Probably this was the thing I was searching for :
http://search.cpan.org/~ctweten/ex-override-1.01/override.pm
I will need this for some time and then will revert back to the original open()
Unless there is more elegant way

In reply to Intercepting IO file access by rootcho

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.