From: Jarkko Hietaniemi Date: Sat, 24 Nov 2001 15:23:34 +0000 (+0000) Subject: Use /proc/self/auxv in Solaris to figure out the $^X. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b51d9c98646cc7c622f6896e9d6e994eeebd7ba5;p=p5sagit%2Fp5-mst-13.2.git Use /proc/self/auxv in Solaris to figure out the $^X. (It seems that "./perl" gets resolved to "perl" now.) p4raw-id: //depot/perl@13234 --- diff --git a/perl.c b/perl.c index 5d4e5bb..13c7d31 100644 --- a/perl.c +++ b/perl.c @@ -3421,7 +3421,7 @@ Perl_init_argv_symbols(pTHX_ register int argc, register char **argv) #ifdef HAS_PROCSELFEXE /* This is a function so that we don't hold on to MAXPATHLEN - bytes of stack longer than necessary + bytes of stack longer than necessary. */ STATIC void S_procself_val(pTHX_ SV *sv, char *arg0) @@ -3437,6 +3437,35 @@ S_procself_val(pTHX_ SV *sv, char *arg0) } #endif /* HAS_PROCSELFEXE */ +#if defined(sun) && defined(__svr4__) /* solaris */ +#include +STATIC void +S_procselfauxv(pTHX_ SV *sv, char *arg0) { + auxv_t auxv; + int fh; + int n; + + fh = open("/proc/self/auxv", O_RDONLY); + if (fh < 0) { + sv_setpv(sv, arg0); + return; + } + + while (1) { + n = read(fh, &auxv, sizeof(auxv)); + if (n != sizeof(auxv)) + break; + if (auxv.a_type == AT_SUN_EXECNAME) { + close(fh); + sv_setpv(sv, auxv.a_un.a_ptr); + return; + } + } + close(fh); + sv_setpv(sv, arg0); +} +#endif /* solaris */ + STATIC void S_init_postdump_symbols(pTHX_ register int argc, register char **argv, register char **env) { @@ -3473,11 +3502,15 @@ S_init_postdump_symbols(pTHX_ register int argc, register char **argv, register #ifdef HAS_PROCSELFEXE S_procself_val(aTHX_ GvSV(tmpgv), PL_origargv[0]); #else -#ifdef OS2 +# ifdef OS2 sv_setpv(GvSV(tmpgv), os2_execname(aTHX)); -#else - sv_setpv(GvSV(tmpgv),PL_origargv[0]); -#endif +# else +# if defined(sun) && defined(__svr4__) /* solaris */ + S_procselfauxv(aTHX_ GvSV(tmpgv), PL_origargv[0]); +# else + sv_setpv(GvSV(tmpgv), PL_origargv[0]); +# endif +# endif #endif } if ((PL_envgv = gv_fetchpv("ENV",TRUE, SVt_PVHV))) {