summaryrefslogtreecommitdiff
path: root/perl.c
diff options
context:
space:
mode:
authorRicardo Signes <rjbs@cpan.org>2013-01-05 20:30:48 -0500
committerRicardo Signes <rjbs@cpan.org>2013-01-12 19:39:26 -0500
commit1dfef69b3a0643e5cf8879e1476b0163c3e8a9b2 (patch)
tree96797af59786735f74934ce4e821a60f09fa6d55 /perl.c
parenteeace61d181813f7b93c686e9d16cd914a90dd7d (diff)
downloadperl-1dfef69b3a0643e5cf8879e1476b0163c3e8a9b2.tar.gz
croak on an attempt to run a directory as a script
How many times have I meant to run "perl -I lib myprog" but instead run "perl lib myprog" only to exit 0 because that's what perl does when you try to run a directory as a script (at least on unix)? Many. perl should croak when instructed to execute a directory. [perl #61362] suggests it already does so on Win32. Now it does it everywhere. Tests not yet written.
Diffstat (limited to 'perl.c')
-rw-r--r--perl.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/perl.c b/perl.c
index c7e1d540d8..d4f13df445 100644
--- a/perl.c
+++ b/perl.c
@@ -3649,6 +3649,7 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, bool *suidscript)
int fdscript = -1;
PerlIO *rsfp = NULL;
dVAR;
+ Stat_t tmpstatbuf;
PERL_ARGS_ASSERT_OPEN_SCRIPT;
@@ -3758,6 +3759,13 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, bool *suidscript)
/* ensure close-on-exec */
fcntl(PerlIO_fileno(rsfp), F_SETFD, 1);
#endif
+
+ if (PerlLIO_fstat(PerlIO_fileno(rsfp), &tmpstatbuf) >= 0
+ && S_ISDIR(tmpstatbuf.st_mode))
+ Perl_croak(aTHX_ "Can't open perl script \"%s\": %s\n",
+ CopFILE(PL_curcop),
+ strerror(EISDIR));
+
return rsfp;
}