Hi, I have a script that needs to find out where it was executed from. The following script:
#!/usr/bin/perl -w
print "$0\n";
normally works ok. However, if the script is set-uid (to any user) it prints something like "/dev/fd/3". This is under Solaris 2.7. The FindBin modules uses $0 as its starting point, so it doesn't work either.

I read somewhere that this is a trick used by some kernels to safely execute set-uid scripts: when a set-uid script is invoked, the kernel passes the script to the interpreter using a file descriptor instead of the file name directly, to avoid race conditions. If this is the case, my problem may be unsolvable, but I thought I would ask anyway.

I asked in comp.lang.perl.misc about this, and got two main suggestions, which I list with their drawbacks:

So I'm still looking for a real answer to my question. Any ideas will be very appreciated!

Thanks,

--Diego


In reply to How to determine the program path from a set-uid program by ZZamboni

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.