Unfortunately, the box is solaris 8, not 10 ...

I was afraid you were going to say that :) — in this case you're essentially out of luck...

On anything older than Solaris 10, the proc filesystem is rather limited. AFAIK, the only info remotely similar to /proc/self/exe (or /proc/self/path/a.out for that matter), is in /proc/self/auxv (aux vector — a binary structure), but it's not really the same, in particular on Solaris 8 (things have gotten somewhat better starting with Solaris 9).

If you're really determined, you could try to hack up something based on the standard C library functions getexecname, which extracts the appropriate structure from /proc/self/auxv, together with realpath, which resolves all "..", "." and symbolic links in a path (, and possibly also getcwd).

One ugly problem with getexecname on Solaris 8 is that it doesn't make a distinction between an executable script and its associated interpreter invoked via the shebang line. For example, with the following naive snippet

#include <stdlib.h> #include <limits.h> #include <stdio.h> int main() { const char *execname; char *execpath; char pathbuf[PATH_MAX]; execname = getexecname(); execpath = realpath(execname, pathbuf); printf("execname: %s\n", execname); printf("realpath: %s\n", execpath); }

if you compile this with cc foo.c -o foo and put the resulting binary in - let's say - /home/ck/bin/, and then create a dummy script bar with the shebang line #!/home/ck/bin/foo in some other directory like /home/ck/myscripts/, and call it from there, you'd get on Solaris 8:

$ ./bar execname: bar realpath: /home/ck/myscripts/bar

while on Solaris 9 or 10, the execname would be more useful

$ ./bar execname: /home/ck/bin/foo realpath: /home/ck/bin/foo

You see the problem with Solaris 8 — and this is not the only one...

(note that the code would of course have to be linked into perl (to set $^X), i.e. the foo in the example represents the Perl binary)


In reply to Re^3: Relocatable Perl 5.10.0 on Solaris by almut
in thread Relocatable Perl 5.10.0 on Solaris by Anonymous Monk

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.