diff --git a/AUTHORS b/AUTHORS index 6b244913fa18..186ed2093187 100644 --- a/AUTHORS +++ b/AUTHORS @@ -988,6 +988,7 @@ Michael Somos Michael Stevens Michael van Elst Michael Witten +Michal Josef Špaček Michele Sardo Michiel Beijen Mik Firestone diff --git a/perl.c b/perl.c index 5c87e47ee294..e7dab8376b7f 100644 --- a/perl.c +++ b/perl.c @@ -4227,6 +4227,19 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, bool *suidscript) Safefree(PL_origfilename); PL_origfilename = (char *)scriptname; } + else { + char proc_fd_path[64]; + snprintf(proc_fd_path, sizeof(proc_fd_path), "/proc/self/fd/%d", fdscript); + char target_path[MAXPATHLEN]; + SSize_t len = readlink(proc_fd_path, target_path, sizeof(target_path) - 1); + if (len != -1) { + Stat_t statbuf; + target_path[len] = '\0'; + if (PerlLIO_stat(target_path, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) { + scriptname = PL_origfilename = find_script(target_path, dosearch, NULL, 1); + } + } + } } }