3 * Copyright (c) 1987-1996 Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "A ship then new they built for him/of mithril and of elven glass" --Bilbo
16 #include "patchlevel.h"
18 /* XXX If this causes problems, set i_unistd=undef in the hint file. */
23 dEXTCONST char rcsid[] = "perl.c\nPatch level: ###\n";
31 #ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
37 static void find_beginning _((void));
38 static void forbid_setid _((char *));
39 static void incpush _((char *));
40 static void init_ids _((void));
41 static void init_debugger _((void));
42 static void init_lexer _((void));
43 static void init_main_stash _((void));
44 static void init_perllib _((void));
45 static void init_postdump_symbols _((int, char **, char **));
46 static void init_predump_symbols _((void));
47 static void init_stacks _((void));
48 static void nuke_stacks _((void));
49 static void open_script _((char *, bool, SV *));
50 static void usage _((char *));
51 static void validate_suid _((char *, char*));
53 static int fdscript = -1;
58 PerlInterpreter *sv_interp;
61 New(53, sv_interp, 1, PerlInterpreter);
66 perl_construct( sv_interp )
67 register PerlInterpreter *sv_interp;
69 if (!(curinterp = sv_interp))
73 Zero(sv_interp, 1, PerlInterpreter);
76 /* Init the real globals? */
78 linestr = NEWSV(65,80);
79 sv_upgrade(linestr,SVt_PVIV);
81 if (!SvREADONLY(&sv_undef)) {
82 SvREADONLY_on(&sv_undef);
86 SvREADONLY_on(&sv_no);
88 sv_setpv(&sv_yes,Yes);
90 SvREADONLY_on(&sv_yes);
93 nrs = newSVpv("\n", 1);
94 rs = SvREFCNT_inc(nrs);
98 * There is no way we can refer to them from Perl so close them to save
99 * space. The other alternative would be to provide STDAUX and STDPRN
102 (void)fclose(stdaux);
103 (void)fclose(stdprn);
120 perl_destruct_level = 1;
125 SET_NUMERIC_STANDARD();
126 #if defined(SUBVERSION) && SUBVERSION > 0
127 sprintf(patchlevel, "%7.5f", (double) 5
128 + ((double) PATCHLEVEL / (double) 1000)
129 + ((double) SUBVERSION / (double) 100000));
131 sprintf(patchlevel, "%5.3f", (double) 5 +
132 ((double) PATCHLEVEL / (double) 1000));
135 #if defined(LOCAL_PATCH_COUNT)
136 localpatches = local_patches; /* For possible -v */
139 PerlIO_init(); /* Hook to IO system */
141 fdpid = newAV(); /* for remembering popen pids by fd */
142 pidstatus = newHV();/* for remembering status of dead pids */
149 perl_destruct(sv_interp)
150 register PerlInterpreter *sv_interp;
152 int destruct_level; /* 0=none, 1=full, 2=full with checks */
156 if (!(curinterp = sv_interp))
159 destruct_level = perl_destruct_level;
163 if (s = getenv("PERL_DESTRUCT_LEVEL")) {
165 if (destruct_level < i)
171 /* unhook hooks which will soon be, or use, destroyed data */
172 SvREFCNT_dec(warnhook);
174 SvREFCNT_dec(diehook);
176 SvREFCNT_dec(parsehook);
182 /* We must account for everything. First the syntax tree. */
184 curpad = AvARRAY(comppad);
190 * Try to destruct global references. We do this first so that the
191 * destructors and destructees still exist. Some sv's might remain.
192 * Non-referenced objects are on their own.
199 if (destruct_level == 0){
201 DEBUG_P(debprofdump());
203 /* The exit() function will do everything that needs doing. */
207 /* loosen bonds of global variables */
222 sv_free((SV*)beginav);
227 /* Prepare to destruct main symbol table. */
234 if (destruct_level >= 2) {
235 if (scopestack_ix != 0)
236 warn("Unbalanced scopes: %d more ENTERs than LEAVEs\n", scopestack_ix);
237 if (savestack_ix != 0)
238 warn("Unbalanced saves: %d more saves than restores\n", savestack_ix);
239 if (tmps_floor != -1)
240 warn("Unbalanced tmps: %d more allocs than frees\n", tmps_floor + 1);
241 if (cxstack_ix != -1)
242 warn("Unbalanced context: %d more PUSHes than POPs\n", cxstack_ix + 1);
245 /* Now absolutely destruct everything, somehow or other, loops or no. */
247 SvFLAGS(strtab) |= SVTYPEMASK; /* don't clean out strtab now */
248 while (sv_count != 0 && sv_count != last_sv_count) {
249 last_sv_count = sv_count;
252 SvFLAGS(strtab) &= ~SVTYPEMASK;
253 SvFLAGS(strtab) |= SVt_PVHV;
255 /* Destruct the global string table. */
257 /* Yell and reset the HeVAL() slots that are still holding refcounts,
258 * so that sv_free() won't fail on them.
267 array = HvARRAY(strtab);
271 warn("Unbalanced string table refcount: (%d) for \"%s\"",
272 HeVAL(hent) - Nullsv, HeKEY(hent));
273 HeVAL(hent) = Nullsv;
283 SvREFCNT_dec(strtab);
286 warn("Scalars leaked: %d\n", sv_count);
290 linestr = NULL; /* No SVs have survived, need to clean out */
292 Safefree(origfilename);
294 hints = 0; /* Reset hints. Should hints be per-interpreter ? */
296 DEBUG_P(debprofdump());
301 PerlInterpreter *sv_interp;
303 if (!(curinterp = sv_interp))
307 #if !defined(STANDARD_C) && !defined(HAS_GETENV_PROTOTYPE)
308 char *getenv _((char *)); /* Usually in <stdlib.h> */
312 perl_parse(sv_interp, xsinit, argc, argv, env)
313 PerlInterpreter *sv_interp;
314 void (*xsinit)_((void));
321 char *scriptname = NULL;
322 VOL bool dosearch = FALSE;
326 #ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
329 croak("suidperl is no longer needed since the kernel can now execute\n\
330 setuid perl scripts securely.\n");
334 if (!(curinterp = sv_interp))
337 #if defined(NeXT) && defined(__DYNAMIC__)
338 _dyld_lookup_and_bind
339 ("__environ", (unsigned long *) &environ_pointer, NULL);
344 #ifndef VMS /* VMS doesn't have environ array */
345 origenviron = environ;
351 /* Come here if running an undumped a.out. */
353 origfilename = savepv(argv[0]);
355 cxstack_ix = -1; /* start label stack again */
357 init_postdump_symbols(argc,argv,env);
365 switch (Sigsetjmp(top_env,1)) {
376 return(statusvalue); /* my_exit() was called */
378 PerlIO_printf(PerlIO_stderr(), "panic: top_env\n");
382 sv_setpvn(linestr,"",0);
383 sv = newSVpv("",0); /* first used for -I flags */
386 for (argc--,argv++; argc > 0; argc--,argv++) {
387 if (argv[0][0] != '-' || !argv[0][1])
391 validarg = " PHOOEY ";
417 if (s = moreswitches(s))
422 if (euid != uid || egid != gid)
423 croak("No -e allowed in setuid scripts");
425 e_tmpname = savepv(TMPPATH);
426 (void)mktemp(e_tmpname);
428 croak("Can't mktemp()");
429 e_fp = PerlIO_open(e_tmpname,"w");
431 croak("Cannot open temporary file");
436 PerlIO_puts(e_fp,argv[1]);
440 croak("No code specified for -e");
441 (void)PerlIO_putc(e_fp,'\n');
449 av_push(GvAVn(incgv),newSVpv(s,0));
452 av_push(GvAVn(incgv),newSVpv(argv[1],0));
453 sv_catpv(sv,argv[1]);
470 preambleav = newAV();
471 av_push(preambleav, newSVpv("use Config qw(myconfig config_vars)",0));
473 Sv = newSVpv("print myconfig();",0);
475 sv_catpv(Sv,"print \"\\nCharacteristics of this PERLSHR image: \\n\",");
477 sv_catpv(Sv,"print \"\\nCharacteristics of this binary (from libperl): \\n\",");
479 #if defined(DEBUGGING) || defined(NOEMBED) || defined(MULTIPLICITY)
480 strcpy(buf,"\" Compile-time options:");
482 strcat(buf," DEBUGGING");
485 strcat(buf," NOEMBED");
488 strcat(buf," MULTIPLICITY");
490 strcat(buf,"\\n\",");
493 #if defined(LOCAL_PATCH_COUNT)
494 if (LOCAL_PATCH_COUNT > 0)
496 sv_catpv(Sv,"print \" Locally applied patches:\\n\",");
497 for (i = 1; i <= LOCAL_PATCH_COUNT; i++) {
498 if (localpatches[i]) {
499 sprintf(buf,"\" \\t%s\\n\",",localpatches[i]);
505 sprintf(buf,"\" Built under %s\\n\",",OSNAME);
509 sprintf(buf,"\" Compiled at %s %s\\n\"",__DATE__,__TIME__);
511 sprintf(buf,"\" Compiled on %s\\n\"",__DATE__);
515 sv_catpv(Sv,"; $\"=\"\\n \"; print \" \\@INC:\\n @INC\\n\"");
518 Sv = newSVpv("config_vars(qw(",0);
523 av_push(preambleav, Sv);
524 scriptname = BIT_BUCKET; /* don't look for script or read stdin */
538 croak("Unrecognized switch: -%s",s);
543 scriptname = argv[0];
545 if (PerlIO_flush(e_fp) || PerlIO_error(e_fp) || PerlIO_close(e_fp))
546 croak("Can't write to temp file for -e: %s", Strerror(errno));
549 scriptname = e_tmpname;
551 else if (scriptname == Nullch) {
553 if ( isatty(PerlIO_fileno(PerlIO_stdin())) )
561 open_script(scriptname,dosearch,sv);
563 validate_suid(validarg, scriptname);
568 compcv = (CV*)NEWSV(1104,0);
569 sv_upgrade((SV *)compcv, SVt_PVCV);
573 av_push(comppad, Nullsv);
574 curpad = AvARRAY(comppad);
575 comppad_name = newAV();
576 comppad_name_fill = 0;
577 min_intro_pending = 0;
580 comppadlist = newAV();
581 AvREAL_off(comppadlist);
582 av_store(comppadlist, 0, (SV*)comppad_name);
583 av_store(comppadlist, 1, (SV*)comppad);
584 CvPADLIST(compcv) = comppadlist;
586 boot_core_UNIVERSAL();
588 (*xsinit)(); /* in case linked C routines want magical variables */
593 init_predump_symbols();
595 init_postdump_symbols(argc,argv,env);
599 /* now parse the script */
602 if (yyparse() || error_count) {
604 croak("%s had compilation errors.\n", origfilename);
606 croak("Execution of %s aborted due to compilation errors.\n",
610 curcop->cop_line = 0;
614 (void)UNLINK(e_tmpname);
619 /* now that script is parsed, we can modify record separator */
621 rs = SvREFCNT_inc(nrs);
622 sv_setsv(GvSV(gv_fetchpv("/", TRUE, SVt_PV)), rs);
633 #ifdef DEBUGGING_MSTATS
634 if ((s=getenv("PERL_DEBUG_MSTATS")) && atoi(s) >= 2)
635 dump_mstats("after compilation:");
645 PerlInterpreter *sv_interp;
647 if (!(curinterp = sv_interp))
649 switch (Sigsetjmp(top_env,1)) {
651 cxstack_ix = -1; /* start context stack again */
658 #ifdef DEBUGGING_MSTATS
659 if (getenv("PERL_DEBUG_MSTATS"))
660 dump_mstats("after execution: ");
662 return(statusvalue); /* my_exit() was called */
665 PerlIO_printf(PerlIO_stderr(), "panic: restartop\n");
669 if (curstack != mainstack) {
671 SWITCHSTACK(curstack, mainstack);
676 DEBUG_r(PerlIO_printf(PerlIO_stderr(), "%s $` $& $' support.\n",
677 sawampersand ? "Enabling" : "Omitting"));
681 DEBUG(PerlIO_printf(Perl_debug_log, "\nEXECUTING...\n\n"));
684 PerlIO_printf(PerlIO_stderr(), "%s syntax OK\n", origfilename);
687 if (perldb && DBsingle)
688 sv_setiv(DBsingle, 1);
698 else if (main_start) {
711 register CONTEXT *cx;
715 statusvalue = FIXSTATUS(status);
716 if (cxstack_ix >= 0) {
722 Siglongjmp(top_env, 2);
726 perl_get_sv(name, create)
730 GV* gv = gv_fetchpv(name, create, SVt_PV);
737 perl_get_av(name, create)
741 GV* gv = gv_fetchpv(name, create, SVt_PVAV);
750 perl_get_hv(name, create)
754 GV* gv = gv_fetchpv(name, create, SVt_PVHV);
763 perl_get_cv(name, create)
767 GV* gv = gv_fetchpv(name, create, SVt_PVCV);
768 if (create && !GvCV(gv))
769 return newSUB(start_subparse(),
770 newSVOP(OP_CONST, 0, newSVpv(name,0)),
778 /* Be sure to refetch the stack pointer after calling these routines. */
781 perl_call_argv(subname, flags, argv)
783 I32 flags; /* See G_* flags in cop.h */
784 register char **argv; /* null terminated arg list */
791 XPUSHs(sv_2mortal(newSVpv(*argv,0)));
796 return perl_call_pv(subname, flags);
800 perl_call_pv(subname, flags)
801 char *subname; /* name of the subroutine */
802 I32 flags; /* See G_* flags in cop.h */
804 return perl_call_sv((SV*)perl_get_cv(subname, TRUE), flags);
808 perl_call_method(methname, flags)
809 char *methname; /* name of the subroutine */
810 I32 flags; /* See G_* flags in cop.h */
816 XPUSHs(sv_2mortal(newSVpv(methname,0)));
819 return perl_call_sv(*stack_sp--, flags);
822 /* May be called with any of a CV, a GV, or an SV containing the name. */
824 perl_call_sv(sv, flags)
826 I32 flags; /* See G_* flags in cop.h */
828 LOGOP myop; /* fake syntax tree node */
830 I32 oldmark = TOPMARK;
836 if (flags & G_DISCARD) {
846 oldscope = scopestack_ix;
848 if (!(flags & G_NOARGS))
849 myop.op_flags = OPf_STACKED;
850 myop.op_next = Nullop;
851 myop.op_flags |= OPf_KNOW;
853 myop.op_flags |= OPf_LIST;
855 if (perldb && curstash != debstash
856 /* Handle first BEGIN of -d. */
857 && (DBcv || (DBcv = GvCV(DBsub)))
858 /* Try harder, since this may have been a sighandler, thus
859 * curstash may be meaningless. */
860 && (SvTYPE(sv) != SVt_PVCV || CvSTASH((CV*)sv) != debstash))
861 op->op_private |= OPpENTERSUB_DB;
863 if (flags & G_EVAL) {
864 Copy(top_env, oldtop, 1, Sigjmp_buf);
866 cLOGOP->op_other = op;
868 /* we're trying to emulate pp_entertry() here */
870 register CONTEXT *cx;
876 push_return(op->op_next);
877 PUSHBLOCK(cx, CXt_EVAL, stack_sp);
879 eval_root = op; /* Only needed so that goto works right. */
882 if (flags & G_KEEPERR)
885 sv_setpv(GvSV(errgv),"");
890 switch (Sigsetjmp(top_env,1)) {
895 statusvalue = 255; /* XXX I don't think we use 1 anymore. */
901 /* my_exit() was called */
904 Copy(oldtop, top_env, 1, Sigjmp_buf);
906 croak("Callback called exit");
907 my_exit(statusvalue);
915 stack_sp = stack_base + oldmark;
920 *++stack_sp = &sv_undef;
926 if (op == (OP*)&myop)
930 retval = stack_sp - (stack_base + oldmark);
931 if ((flags & G_EVAL) && !(flags & G_KEEPERR))
932 sv_setpv(GvSV(errgv),"");
935 if (flags & G_EVAL) {
936 if (scopestack_ix > oldscope) {
940 register CONTEXT *cx;
949 Copy(oldtop, top_env, 1, Sigjmp_buf);
951 if (flags & G_DISCARD) {
952 stack_sp = stack_base + oldmark;
960 /* Eval a string. The G_EVAL flag is always assumed. */
963 perl_eval_sv(sv, flags)
965 I32 flags; /* See G_* flags in cop.h */
967 UNOP myop; /* fake syntax tree node */
969 I32 oldmark = sp - stack_base;
974 if (flags & G_DISCARD) {
984 oldscope = scopestack_ix;
986 if (!(flags & G_NOARGS))
987 myop.op_flags = OPf_STACKED;
988 myop.op_next = Nullop;
989 myop.op_type = OP_ENTEREVAL;
990 myop.op_flags |= OPf_KNOW;
991 if (flags & G_KEEPERR)
992 myop.op_flags |= OPf_SPECIAL;
994 myop.op_flags |= OPf_LIST;
996 Copy(top_env, oldtop, 1, Sigjmp_buf);
999 switch (Sigsetjmp(top_env,1)) {
1004 statusvalue = 255; /* XXX I don't think we use 1 anymore. */
1010 /* my_exit() was called */
1011 curstash = defstash;
1013 Copy(oldtop, top_env, 1, Sigjmp_buf);
1015 croak("Callback called exit");
1016 my_exit(statusvalue);
1024 stack_sp = stack_base + oldmark;
1025 if (flags & G_ARRAY)
1029 *++stack_sp = &sv_undef;
1034 if (op == (OP*)&myop)
1035 op = pp_entereval();
1038 retval = stack_sp - (stack_base + oldmark);
1039 if (!(flags & G_KEEPERR))
1040 sv_setpv(GvSV(errgv),"");
1043 Copy(oldtop, top_env, 1, Sigjmp_buf);
1044 if (flags & G_DISCARD) {
1045 stack_sp = stack_base + oldmark;
1053 /* Require a module. */
1059 SV* sv = sv_newmortal();
1060 sv_setpv(sv, "require '");
1063 perl_eval_sv(sv, G_DISCARD);
1067 magicname(sym,name,namlen)
1074 if (gv = gv_fetchpv(sym,TRUE, SVt_PV))
1075 sv_magic(GvSV(gv), (SV*)gv, 0, name, namlen);
1079 # define PERLLIB_SEP ';'
1082 # define PERLLIB_SEP '|'
1084 # define PERLLIB_SEP ':'
1087 #ifndef PERLLIB_MANGLE
1088 # define PERLLIB_MANGLE(s,n) (s)
1100 /* Break at all separators */
1102 /* First, skip any consecutive separators */
1103 while ( *p == PERLLIB_SEP ) {
1104 /* Uncomment the next line for PATH semantics */
1105 /* av_push(GvAVn(incgv), newSVpv(".", 1)); */
1108 if ( (s = strchr(p, PERLLIB_SEP)) != Nullch ) {
1109 av_push(GvAVn(incgv), newSVpv(PERLLIB_MANGLE(p, (STRLEN)(s - p)),
1113 av_push(GvAVn(incgv), newSVpv(PERLLIB_MANGLE(p, 0), 0));
1120 usage(name) /* XXX move this out into a module ? */
1123 /* This message really ought to be max 23 lines.
1124 * Removed -h because the user already knows that opton. Others? */
1125 printf("\nUsage: %s [switches] [--] [programfile] [arguments]", name);
1126 printf("\n -0[octal] specify record separator (\\0, if no argument)");
1127 printf("\n -a autosplit mode with -n or -p (splits $_ into @F)");
1128 printf("\n -c check syntax only (runs BEGIN and END blocks)");
1129 printf("\n -d[:debugger] run scripts under debugger");
1130 printf("\n -D[number/list] set debugging flags (argument is a bit mask or flags)");
1131 printf("\n -e 'command' one line of script. Several -e's allowed. Omit [programfile].");
1132 printf("\n -F/pattern/ split() pattern for autosplit (-a). The //'s are optional.");
1133 printf("\n -i[extension] edit <> files in place (make backup if extension supplied)");
1134 printf("\n -Idirectory specify @INC/#include directory (may be used more then once)");
1135 printf("\n -l[octal] enable line ending processing, specifies line teminator");
1136 printf("\n -[mM][-]module.. executes `use/no module...' before executing your script.");
1137 printf("\n -n assume 'while (<>) { ... }' loop arround your script");
1138 printf("\n -p assume loop like -n but print line also like sed");
1139 printf("\n -P run script through C preprocessor before compilation");
1140 printf("\n -s enable some switch parsing for switches after script name");
1141 printf("\n -S look for the script using PATH environment variable");
1142 printf("\n -T turn on tainting checks");
1143 printf("\n -u dump core after parsing script");
1144 printf("\n -U allow unsafe operations");
1145 printf("\n -v print version number and patchlevel of perl");
1146 printf("\n -V[:variable] print perl configuration information");
1147 printf("\n -w TURN WARNINGS ON FOR COMPILATION OF YOUR SCRIPT.");
1148 printf("\n -x[directory] strip off text before #!perl line and perhaps cd to directory\n");
1151 /* This routine handles any switches that can be given during run */
1162 rschar = scan_oct(s, 4, &numlen);
1164 if (rschar & ~((U8)~0))
1166 else if (!rschar && numlen >= 2)
1167 nrs = newSVpv("", 0);
1170 nrs = newSVpv(&ch, 1);
1175 splitstr = savepv(s + 1);
1189 if (*s == ':' || *s == '=') {
1190 sprintf(buf, "use Devel::%s;", ++s);
1192 my_setenv("PERL5DB",buf);
1202 if (isALPHA(s[1])) {
1203 static char debopts[] = "psltocPmfrxuLHXD";
1206 for (s++; *s && (d = strchr(debopts,*s)); s++)
1207 debug |= 1 << (d - debopts);
1211 for (s++; isDIGIT(*s); s++) ;
1213 debug |= 0x80000000;
1215 warn("Recompile perl with -DDEBUGGING to use -D switch\n");
1216 for (s++; isALNUM(*s); s++) ;
1226 inplace = savepv(s+1);
1228 for (s = inplace; *s && !isSPACE(*s); s++) ;
1235 for (e = s; *e && !isSPACE(*e); e++) ;
1236 av_push(GvAVn(incgv),newSVpv(s,e-s));
1241 croak("No space allowed after -I");
1251 *ors = scan_oct(s, 3 + (*s == '0'), &numlen);
1260 ors = SvPV(nrs, orslen);
1261 ors = savepvn(ors, orslen);
1265 forbid_setid("-M"); /* XXX ? */
1268 forbid_setid("-m"); /* XXX ? */
1272 /* -M-foo == 'no foo' */
1273 if (*s == '-') { use = "no "; ++s; }
1274 Sv = newSVpv(use,0);
1276 /* We allow -M'Module qw(Foo Bar)' */
1277 while(isALNUM(*s) || *s==':') ++s;
1279 sv_catpv(Sv, start);
1280 if (*(start-1) == 'm') {
1282 croak("Can't use '%c' after -mname", *s);
1283 sv_catpv( Sv, " ()");
1286 sv_catpvn(Sv, start, s-start);
1287 sv_catpv(Sv, " split(/,/,q{");
1292 if (preambleav == NULL)
1293 preambleav = newAV();
1294 av_push(preambleav, Sv);
1297 croak("No space allowed after -%c", *(s-1));
1325 #if defined(SUBVERSION) && SUBVERSION > 0
1326 printf("\nThis is perl, version 5.%03d_%02d", PATCHLEVEL, SUBVERSION);
1328 printf("\nThis is perl, version %s",patchlevel);
1331 printf("\n\nCopyright 1987-1996, Larry Wall\n");
1332 printf("\n\t+ suidperl security patch");
1334 printf("\n\nMS-DOS port Copyright (c) 1989, 1990, Diomidis Spinellis\n");
1337 printf("djgpp v2 port (jpl5003c) by Hirofumi Watanabe, 1996\n");
1340 printf("\n\nOS/2 port Copyright (c) 1990, 1991, Raymond Chen, Kai Uwe Rommel\n"
1341 "Version 5 port Copyright (c) 1994-1996, Andreas Kaiser, Ilya Zakharevich\n");
1344 printf("atariST series port, ++jrb bammi@cadence.com\n");
1347 Perl may be copied only under the terms of either the Artistic License or the\n\
1348 GNU General Public License, which may be found in the Perl 5.0 source kit.\n\n");
1356 if (s[1] == '-') /* Additional switches on #! line. */
1369 croak("Can't emulate -%.1s on #! line",s);
1374 /* compliments of Tom Christiansen */
1376 /* unexec() can be found in the Gnu emacs distribution */
1385 sprintf (buf, "%s.perldump", origfilename);
1386 sprintf (tokenbuf, "%s/perl", BIN);
1388 status = unexec(buf, tokenbuf, &etext, sbrk(0), 0);
1390 PerlIO_printf(PerlIO_stderr(), "unexec of %s into %s failed!\n", tokenbuf, buf);
1394 # include <lib$routines.h>
1395 lib$signal(SS$_DEBUG); /* ssdef.h #included from vmsish.h */
1397 ABORT(); /* for use with undump */
1407 /* Note that strtab is a rather special HV. Assumptions are made
1408 about not iterating on it, and not adding tie magic to it.
1409 It is properly deallocated in perl_destruct() */
1411 HvSHAREKEYS_off(strtab); /* mandatory */
1412 Newz(506,((XPVHV*)SvANY(strtab))->xhv_array,
1413 sizeof(HE*) * (((XPVHV*)SvANY(strtab))->xhv_max + 1), char);
1415 curstash = defstash = newHV();
1416 curstname = newSVpv("main",4);
1417 gv = gv_fetchpv("main::",TRUE, SVt_PVHV);
1418 SvREFCNT_dec(GvHV(gv));
1419 GvHV(gv) = (HV*)SvREFCNT_inc(defstash);
1421 HvNAME(defstash) = savepv("main");
1422 incgv = gv_HVadd(gv_AVadd(gv_fetchpv("INC",TRUE, SVt_PVAV)));
1424 defgv = gv_fetchpv("_",TRUE, SVt_PVAV);
1425 errgv = gv_HVadd(gv_fetchpv("@", TRUE, SVt_PV));
1427 sv_setpvn(GvSV(errgv), "", 0);
1428 curstash = defstash;
1429 compiling.cop_stash = defstash;
1430 debstash = GvHV(gv_fetchpv("DB::", GV_ADDMULTI, SVt_PVHV));
1431 /* We must init $/ before switches are processed. */
1432 sv_setpvn(GvSV(gv_fetchpv("/", TRUE, SVt_PV)), "\n", 1);
1435 #ifdef CAN_PROTOTYPE
1437 open_script(char *scriptname, bool dosearch, SV *sv)
1440 open_script(scriptname,dosearch,sv)
1446 char *xfound = Nullch;
1447 char *xfailed = Nullch;
1451 #if defined(DOSISH) && !defined(OS2) && !defined(atarist)
1452 #define SEARCH_EXTS ".bat", ".cmd", NULL
1455 # define SEARCH_EXTS ".pl", ".com", NULL
1457 /* additional extensions to try in each dir if scriptname not found */
1459 char *ext[] = { SEARCH_EXTS };
1460 int extidx = (strchr(scriptname,'.')) ? -1 : 0; /* has ext already */
1465 int hasdir, idx = 0, deftypes = 1;
1467 hasdir = (strpbrk(scriptname,":[</") != Nullch) ;
1468 /* The first time through, just add SEARCH_EXTS to whatever we
1469 * already have, so we can check for default file types. */
1470 while (deftypes || (!hasdir && my_trnlnm("DCL$PATH",tokenbuf,idx++)) ) {
1471 if (deftypes) { deftypes = 0; *tokenbuf = '\0'; }
1472 strcat(tokenbuf,scriptname);
1474 if (dosearch && !strchr(scriptname, '/') && (s = getenv("PATH"))) {
1476 bufend = s + strlen(s);
1479 s = cpytill(tokenbuf,s,bufend,':',&len);
1482 for (len = 0; *s && *s != ',' && *s != ';'; tokenbuf[len++] = *s++);
1483 tokenbuf[len] = '\0';
1485 for (len = 0; *s && *s != ';'; tokenbuf[len++] = *s++);
1486 tokenbuf[len] = '\0';
1492 if (len && tokenbuf[len-1] != '/')
1495 if (len && ((tokenbuf[len-1] != '\\') && (tokenbuf[len-1] != '/')))
1497 if (len && tokenbuf[len-1] != '\\')
1500 (void)strcat(tokenbuf+len,"/");
1501 (void)strcat(tokenbuf+len,scriptname);
1505 len = strlen(tokenbuf);
1506 if (extidx > 0) /* reset after previous loop */
1510 DEBUG_p(PerlIO_printf(Perl_debug_log, "Looking for %s\n",tokenbuf));
1511 retval = Stat(tokenbuf,&statbuf);
1513 } while ( retval < 0 /* not there */
1514 && extidx>=0 && ext[extidx] /* try an extension? */
1515 && strcpy(tokenbuf+len, ext[extidx++])
1520 if (S_ISREG(statbuf.st_mode)
1521 && cando(S_IRUSR,TRUE,&statbuf) && cando(S_IXUSR,TRUE,&statbuf)) {
1522 xfound = tokenbuf; /* bingo! */
1526 xfailed = savepv(tokenbuf);
1529 croak("Can't execute %s", xfailed ? xfailed : scriptname );
1532 scriptname = xfound;
1535 if (strnEQ(scriptname, "/dev/fd/", 8) && isDIGIT(scriptname[8]) ) {
1536 char *s = scriptname + 8;
1545 origfilename = savepv(e_tmpname ? "-e" : scriptname);
1546 curcop->cop_filegv = gv_fetchfile(origfilename);
1547 if (strEQ(origfilename,"-"))
1549 if (fdscript >= 0) {
1550 rsfp = PerlIO_fdopen(fdscript,"r");
1551 #if defined(HAS_FCNTL) && defined(F_SETFD)
1553 fcntl(PerlIO_fileno(rsfp),F_SETFD,1); /* ensure close-on-exec */
1556 else if (preprocess) {
1557 char *cpp = CPPSTDIN;
1559 if (strEQ(cpp,"cppstdin"))
1560 sprintf(tokenbuf, "%s/%s", SCRIPTDIR, cpp);
1562 sprintf(tokenbuf, "%s", cpp);
1564 sv_catpv(sv,PRIVLIB_EXP);
1566 (void)sprintf(buf, "\
1567 sed %s -e \"/^[^#]/b\" \
1568 -e \"/^#[ ]*include[ ]/b\" \
1569 -e \"/^#[ ]*define[ ]/b\" \
1570 -e \"/^#[ ]*if[ ]/b\" \
1571 -e \"/^#[ ]*ifdef[ ]/b\" \
1572 -e \"/^#[ ]*ifndef[ ]/b\" \
1573 -e \"/^#[ ]*else/b\" \
1574 -e \"/^#[ ]*elif[ ]/b\" \
1575 -e \"/^#[ ]*undef[ ]/b\" \
1576 -e \"/^#[ ]*endif/b\" \
1579 (doextract ? "-e \"1,/^#/d\n\"" : ""),
1581 (void)sprintf(buf, "\
1582 %s %s -e '/^[^#]/b' \
1583 -e '/^#[ ]*include[ ]/b' \
1584 -e '/^#[ ]*define[ ]/b' \
1585 -e '/^#[ ]*if[ ]/b' \
1586 -e '/^#[ ]*ifdef[ ]/b' \
1587 -e '/^#[ ]*ifndef[ ]/b' \
1588 -e '/^#[ ]*else/b' \
1589 -e '/^#[ ]*elif[ ]/b' \
1590 -e '/^#[ ]*undef[ ]/b' \
1591 -e '/^#[ ]*endif/b' \
1599 (doextract ? "-e '1,/^#/d\n'" : ""),
1601 scriptname, tokenbuf, SvPV(sv, na), CPPMINUS);
1603 #ifdef IAMSUID /* actually, this is caught earlier */
1604 if (euid != uid && !euid) { /* if running suidperl */
1606 (void)seteuid(uid); /* musn't stay setuid root */
1609 (void)setreuid((Uid_t)-1, uid);
1611 #ifdef HAS_SETRESUID
1612 (void)setresuid((Uid_t)-1, uid, (Uid_t)-1);
1618 if (geteuid() != uid)
1619 croak("Can't do seteuid!\n");
1621 #endif /* IAMSUID */
1622 rsfp = my_popen(buf,"r");
1624 else if (!*scriptname) {
1625 forbid_setid("program input from stdin");
1626 rsfp = PerlIO_stdin();
1629 rsfp = PerlIO_open(scriptname,"r");
1630 #if defined(HAS_FCNTL) && defined(F_SETFD)
1632 fcntl(PerlIO_fileno(rsfp),F_SETFD,1); /* ensure close-on-exec */
1640 #ifndef IAMSUID /* in case script is not readable before setuid */
1641 if (euid && Stat(SvPVX(GvSV(curcop->cop_filegv)),&statbuf) >= 0 &&
1642 statbuf.st_mode & (S_ISUID|S_ISGID)) {
1643 (void)sprintf(buf, "%s/sperl%s", BIN, patchlevel);
1644 execv(buf, origargv); /* try again */
1645 croak("Can't do setuid\n");
1649 croak("Can't open perl script \"%s\": %s\n",
1650 SvPVX(GvSV(curcop->cop_filegv)), Strerror(errno));
1655 validate_suid(validarg, scriptname)
1661 /* do we need to emulate setuid on scripts? */
1663 /* This code is for those BSD systems that have setuid #! scripts disabled
1664 * in the kernel because of a security problem. Merely defining DOSUID
1665 * in perl will not fix that problem, but if you have disabled setuid
1666 * scripts in the kernel, this will attempt to emulate setuid and setgid
1667 * on scripts that have those now-otherwise-useless bits set. The setuid
1668 * root version must be called suidperl or sperlN.NNN. If regular perl
1669 * discovers that it has opened a setuid script, it calls suidperl with
1670 * the same argv that it had. If suidperl finds that the script it has
1671 * just opened is NOT setuid root, it sets the effective uid back to the
1672 * uid. We don't just make perl setuid root because that loses the
1673 * effective uid we had before invoking perl, if it was different from the
1676 * DOSUID must be defined in both perl and suidperl, and IAMSUID must
1677 * be defined in suidperl only. suidperl must be setuid root. The
1678 * Configure script will set this up for you if you want it.
1684 if (Fstat(PerlIO_fileno(rsfp),&statbuf) < 0) /* normal stat is insecure */
1685 croak("Can't stat script \"%s\"",origfilename);
1686 if (fdscript < 0 && statbuf.st_mode & (S_ISUID|S_ISGID)) {
1690 #ifndef HAS_SETREUID
1691 /* On this access check to make sure the directories are readable,
1692 * there is actually a small window that the user could use to make
1693 * filename point to an accessible directory. So there is a faint
1694 * chance that someone could execute a setuid script down in a
1695 * non-accessible directory. I don't know what to do about that.
1696 * But I don't think it's too important. The manual lies when
1697 * it says access() is useful in setuid programs.
1699 if (access(SvPVX(GvSV(curcop->cop_filegv)),1)) /*double check*/
1700 croak("Permission denied");
1702 /* If we can swap euid and uid, then we can determine access rights
1703 * with a simple stat of the file, and then compare device and
1704 * inode to make sure we did stat() on the same file we opened.
1705 * Then we just have to make sure he or she can execute it.
1708 struct stat tmpstatbuf;
1712 setreuid(euid,uid) < 0
1715 setresuid(euid,uid,(Uid_t)-1) < 0
1718 || getuid() != euid || geteuid() != uid)
1719 croak("Can't swap uid and euid"); /* really paranoid */
1720 if (Stat(SvPVX(GvSV(curcop->cop_filegv)),&tmpstatbuf) < 0)
1721 croak("Permission denied"); /* testing full pathname here */
1722 if (tmpstatbuf.st_dev != statbuf.st_dev ||
1723 tmpstatbuf.st_ino != statbuf.st_ino) {
1724 (void)PerlIO_close(rsfp);
1725 if (rsfp = my_popen("/bin/mail root","w")) { /* heh, heh */
1727 "User %d tried to run dev %d ino %d in place of dev %d ino %d!\n\
1728 (Filename of set-id script was %s, uid %d gid %d.)\n\nSincerely,\nperl\n",
1729 uid,tmpstatbuf.st_dev, tmpstatbuf.st_ino,
1730 statbuf.st_dev, statbuf.st_ino,
1731 SvPVX(GvSV(curcop->cop_filegv)),
1732 statbuf.st_uid, statbuf.st_gid);
1733 (void)my_pclose(rsfp);
1735 croak("Permission denied\n");
1739 setreuid(uid,euid) < 0
1741 # if defined(HAS_SETRESUID)
1742 setresuid(uid,euid,(Uid_t)-1) < 0
1745 || getuid() != uid || geteuid() != euid)
1746 croak("Can't reswap uid and euid");
1747 if (!cando(S_IXUSR,FALSE,&statbuf)) /* can real uid exec? */
1748 croak("Permission denied\n");
1750 #endif /* HAS_SETREUID */
1751 #endif /* IAMSUID */
1753 if (!S_ISREG(statbuf.st_mode))
1754 croak("Permission denied");
1755 if (statbuf.st_mode & S_IWOTH)
1756 croak("Setuid/gid script is writable by world");
1757 doswitches = FALSE; /* -s is insecure in suid */
1759 if (sv_gets(linestr, rsfp, 0) == Nullch ||
1760 strnNE(SvPV(linestr,na),"#!",2) ) /* required even on Sys V */
1761 croak("No #! line");
1762 s = SvPV(linestr,na)+2;
1764 while (!isSPACE(*s)) s++;
1765 for (s2 = s; (s2 > SvPV(linestr,na)+2 &&
1766 (isDIGIT(s2[-1]) || strchr("._-", s2[-1]))); s2--) ;
1767 if (strnNE(s2-4,"perl",4) && strnNE(s-9,"perl",4)) /* sanity check */
1768 croak("Not a perl script");
1769 while (*s == ' ' || *s == '\t') s++;
1771 * #! arg must be what we saw above. They can invoke it by
1772 * mentioning suidperl explicitly, but they may not add any strange
1773 * arguments beyond what #! says if they do invoke suidperl that way.
1775 len = strlen(validarg);
1776 if (strEQ(validarg," PHOOEY ") ||
1777 strnNE(s,validarg,len) || !isSPACE(s[len]))
1778 croak("Args must match #! line");
1781 if (euid != uid && (statbuf.st_mode & S_ISUID) &&
1782 euid == statbuf.st_uid)
1784 croak("YOU HAVEN'T DISABLED SET-ID SCRIPTS IN THE KERNEL YET!\n\
1785 FIX YOUR KERNEL, PUT A C WRAPPER AROUND THIS SCRIPT, OR USE -u AND UNDUMP!\n");
1786 #endif /* IAMSUID */
1788 if (euid) { /* oops, we're not the setuid root perl */
1789 (void)PerlIO_close(rsfp);
1791 (void)sprintf(buf, "%s/sperl%s", BIN, patchlevel);
1792 execv(buf, origargv); /* try again */
1794 croak("Can't do setuid\n");
1797 if (statbuf.st_mode & S_ISGID && statbuf.st_gid != egid) {
1799 (void)setegid(statbuf.st_gid);
1802 (void)setregid((Gid_t)-1,statbuf.st_gid);
1804 #ifdef HAS_SETRESGID
1805 (void)setresgid((Gid_t)-1,statbuf.st_gid,(Gid_t)-1);
1807 setgid(statbuf.st_gid);
1811 if (getegid() != statbuf.st_gid)
1812 croak("Can't do setegid!\n");
1814 if (statbuf.st_mode & S_ISUID) {
1815 if (statbuf.st_uid != euid)
1817 (void)seteuid(statbuf.st_uid); /* all that for this */
1820 (void)setreuid((Uid_t)-1,statbuf.st_uid);
1822 #ifdef HAS_SETRESUID
1823 (void)setresuid((Uid_t)-1,statbuf.st_uid,(Uid_t)-1);
1825 setuid(statbuf.st_uid);
1829 if (geteuid() != statbuf.st_uid)
1830 croak("Can't do seteuid!\n");
1832 else if (uid) { /* oops, mustn't run as root */
1834 (void)seteuid((Uid_t)uid);
1837 (void)setreuid((Uid_t)-1,(Uid_t)uid);
1839 #ifdef HAS_SETRESUID
1840 (void)setresuid((Uid_t)-1,(Uid_t)uid,(Uid_t)-1);
1846 if (geteuid() != uid)
1847 croak("Can't do seteuid!\n");
1850 if (!cando(S_IXUSR,TRUE,&statbuf))
1851 croak("Permission denied\n"); /* they can't do this */
1854 else if (preprocess)
1855 croak("-P not allowed for setuid/setgid script\n");
1856 else if (fdscript >= 0)
1857 croak("fd script not allowed in suidperl\n");
1859 croak("Script is not setuid/setgid in suidperl\n");
1861 /* We absolutely must clear out any saved ids here, so we */
1862 /* exec the real perl, substituting fd script for scriptname. */
1863 /* (We pass script name as "subdir" of fd, which perl will grok.) */
1864 PerlIO_rewind(rsfp);
1865 lseek(PerlIO_fileno(rsfp),(Off_t)0,0); /* just in case rewind didn't */
1866 for (which = 1; origargv[which] && origargv[which] != scriptname; which++) ;
1867 if (!origargv[which])
1868 croak("Permission denied");
1869 (void)sprintf(buf, "/dev/fd/%d/%.127s", PerlIO_fileno(rsfp), origargv[which]);
1870 origargv[which] = buf;
1872 #if defined(HAS_FCNTL) && defined(F_SETFD)
1873 fcntl(PerlIO_fileno(rsfp),F_SETFD,0); /* ensure no close-on-exec */
1876 (void)sprintf(tokenbuf, "%s/perl%s", BIN, patchlevel);
1877 execv(tokenbuf, origargv); /* try again */
1878 croak("Can't do setuid\n");
1879 #endif /* IAMSUID */
1881 if (euid != uid || egid != gid) { /* (suidperl doesn't exist, in fact) */
1882 #ifndef SETUID_SCRIPTS_ARE_SECURE_NOW
1883 Fstat(PerlIO_fileno(rsfp),&statbuf); /* may be either wrapped or real suid */
1884 if ((euid != uid && euid == statbuf.st_uid && statbuf.st_mode & S_ISUID)
1886 (egid != gid && egid == statbuf.st_gid && statbuf.st_mode & S_ISGID)
1889 croak("YOU HAVEN'T DISABLED SET-ID SCRIPTS IN THE KERNEL YET!\n\
1890 FIX YOUR KERNEL, PUT A C WRAPPER AROUND THIS SCRIPT, OR USE -u AND UNDUMP!\n");
1891 #endif /* SETUID_SCRIPTS_ARE_SECURE_NOW */
1892 /* not set-id, must be wrapped */
1900 register char *s, *s2;
1902 /* skip forward in input to the real script? */
1906 if ((s = sv_gets(linestr, rsfp, 0)) == Nullch)
1907 croak("No Perl script found in input\n");
1908 if (*s == '#' && s[1] == '!' && (s = instr(s,"perl"))) {
1909 PerlIO_ungetc(rsfp, '\n'); /* to keep line count right */
1911 while (*s && !(isSPACE (*s) || *s == '#')) s++;
1913 while (*s == ' ' || *s == '\t') s++;
1915 while (isDIGIT(s2[-1]) || strchr("-._", s2[-1])) s2--;
1916 if (strnEQ(s2-4,"perl",4))
1918 while (s = moreswitches(s)) ;
1920 if (cddir && chdir(cddir) < 0)
1921 croak("Can't chdir to %s",cddir);
1929 uid = (int)getuid();
1930 euid = (int)geteuid();
1931 gid = (int)getgid();
1932 egid = (int)getegid();
1937 tainting |= (uid && (euid != uid || egid != gid));
1945 croak("No %s allowed while running setuid", s);
1947 croak("No %s allowed while running setgid", s);
1953 curstash = debstash;
1954 dbargs = GvAV(gv_AVadd((gv_fetchpv("args", GV_ADDMULTI, SVt_PVAV))));
1956 DBgv = gv_fetchpv("DB", GV_ADDMULTI, SVt_PVGV);
1957 DBline = gv_fetchpv("dbline", GV_ADDMULTI, SVt_PVAV);
1958 DBsub = gv_HVadd(gv_fetchpv("sub", GV_ADDMULTI, SVt_PVHV));
1959 DBsingle = GvSV((gv_fetchpv("single", GV_ADDMULTI, SVt_PV)));
1960 sv_setiv(DBsingle, 0);
1961 DBtrace = GvSV((gv_fetchpv("trace", GV_ADDMULTI, SVt_PV)));
1962 sv_setiv(DBtrace, 0);
1963 DBsignal = GvSV((gv_fetchpv("signal", GV_ADDMULTI, SVt_PV)));
1964 sv_setiv(DBsignal, 0);
1965 curstash = defstash;
1972 mainstack = curstack; /* remember in case we switch stacks */
1973 AvREAL_off(curstack); /* not a real array */
1974 av_extend(curstack,127);
1976 stack_base = AvARRAY(curstack);
1977 stack_sp = stack_base;
1978 stack_max = stack_base + 127;
1980 cxstack_max = 8192 / sizeof(CONTEXT) - 2; /* Use most of 8K. */
1981 New(50,cxstack,cxstack_max + 1,CONTEXT);
1984 New(50,tmps_stack,128,SV*);
1989 New(51,debname,128,char);
1990 New(52,debdelim,128,char);
1994 * The following stacks almost certainly should be per-interpreter,
1995 * but for now they're not. XXX
1999 markstack_ptr = markstack;
2001 New(54,markstack,64,I32);
2002 markstack_ptr = markstack;
2003 markstack_max = markstack + 64;
2009 New(54,scopestack,32,I32);
2011 scopestack_max = 32;
2017 New(54,savestack,128,ANY);
2019 savestack_max = 128;
2025 New(54,retstack,16,OP*);
2035 Safefree(tmps_stack);
2042 static PerlIO *tmpfp; /* moved outside init_lexer() because of UNICOS bug */
2050 subname = newSVpv("main",4);
2054 init_predump_symbols()
2059 sv_setpvn(GvSV(gv_fetchpv("\"", TRUE, SVt_PV)), " ", 1);
2061 stdingv = gv_fetchpv("STDIN",TRUE, SVt_PVIO);
2062 GvMULTI_on(stdingv);
2063 IoIFP(GvIOp(stdingv)) = PerlIO_stdin();
2064 tmpgv = gv_fetchpv("stdin",TRUE, SVt_PV);
2066 GvIOp(tmpgv) = (IO*)SvREFCNT_inc(GvIOp(stdingv));
2068 tmpgv = gv_fetchpv("STDOUT",TRUE, SVt_PVIO);
2070 IoOFP(GvIOp(tmpgv)) = IoIFP(GvIOp(tmpgv)) = PerlIO_stdout();
2072 tmpgv = gv_fetchpv("stdout",TRUE, SVt_PV);
2074 GvIOp(tmpgv) = (IO*)SvREFCNT_inc(GvIOp(defoutgv));
2076 othergv = gv_fetchpv("STDERR",TRUE, SVt_PVIO);
2077 GvMULTI_on(othergv);
2078 IoOFP(GvIOp(othergv)) = IoIFP(GvIOp(othergv)) = PerlIO_stderr();
2079 tmpgv = gv_fetchpv("stderr",TRUE, SVt_PV);
2081 GvIOp(tmpgv) = (IO*)SvREFCNT_inc(GvIOp(othergv));
2083 statname = NEWSV(66,0); /* last filename we did stat on */
2086 osname = savepv(OSNAME);
2090 init_postdump_symbols(argc,argv,env)
2092 register char **argv;
2093 register char **env;
2099 argc--,argv++; /* skip name of script */
2101 for (; argc > 0 && **argv == '-'; argc--,argv++) {
2104 if (argv[0][1] == '-') {
2108 if (s = strchr(argv[0], '=')) {
2110 sv_setpv(GvSV(gv_fetchpv(argv[0]+1,TRUE, SVt_PV)),s);
2113 sv_setiv(GvSV(gv_fetchpv(argv[0]+1,TRUE, SVt_PV)),1);
2116 toptarget = NEWSV(0,0);
2117 sv_upgrade(toptarget, SVt_PVFM);
2118 sv_setpvn(toptarget, "", 0);
2119 bodytarget = NEWSV(0,0);
2120 sv_upgrade(bodytarget, SVt_PVFM);
2121 sv_setpvn(bodytarget, "", 0);
2122 formtarget = bodytarget;
2125 if (tmpgv = gv_fetchpv("0",TRUE, SVt_PV)) {
2126 sv_setpv(GvSV(tmpgv),origfilename);
2127 magicname("0", "0", 1);
2129 if (tmpgv = gv_fetchpv("\024",TRUE, SVt_PV))
2131 if (tmpgv = gv_fetchpv("\030",TRUE, SVt_PV))
2132 sv_setpv(GvSV(tmpgv),origargv[0]);
2133 if (argvgv = gv_fetchpv("ARGV",TRUE, SVt_PVAV)) {
2135 (void)gv_AVadd(argvgv);
2136 av_clear(GvAVn(argvgv));
2137 for (; argc > 0; argc--,argv++) {
2138 av_push(GvAVn(argvgv),newSVpv(argv[0],0));
2141 if (envgv = gv_fetchpv("ENV",TRUE, SVt_PVHV)) {
2146 #ifndef VMS /* VMS doesn't have environ array */
2147 /* Note that if the supplied env parameter is actually a copy
2148 of the global environ then it may now point to free'd memory
2149 if the environment has been modified since. To avoid this
2150 problem we treat env==NULL as meaning 'use the default'
2154 if (env != environ) {
2155 environ[0] = Nullch;
2156 hv_magic(hv, envgv, 'E');
2158 for (; *env; env++) {
2159 if (!(s = strchr(*env,'=')))
2162 sv = newSVpv(s--,0);
2163 sv_magic(sv, sv, 'e', *env, s - *env);
2164 (void)hv_store(hv, *env, s - *env, sv, 0);
2168 #ifdef DYNAMIC_ENV_FETCH
2169 HvNAME(hv) = savepv(ENV_HV_NAME);
2171 hv_magic(hv, envgv, 'E');
2174 if (tmpgv = gv_fetchpv("$",TRUE, SVt_PV))
2175 sv_setiv(GvSV(tmpgv),(I32)getpid());
2184 s = getenv("PERL5LIB");
2188 incpush(getenv("PERLLIB"));
2190 /* Treat PERL5?LIB as a possible search list logical name -- the
2191 * "natural" VMS idiom for a Unix path string. We allow each
2192 * element to be a set of |-separated directories for compatibility.
2196 if (my_trnlnm("PERL5LIB",buf,0))
2197 do { incpush(buf); } while (my_trnlnm("PERL5LIB",buf,++idx));
2199 while (my_trnlnm("PERLLIB",buf,idx++)) incpush(buf);
2203 /* Use the ~-expanded versions of APPLIB (undocumented),
2204 ARCHLIB PRIVLIB SITEARCH SITELIB and OLDARCHLIB
2207 incpush(APPLLIB_EXP);
2211 incpush(ARCHLIB_EXP);
2214 #define PRIVLIB_EXP "/usr/local/lib/perl5:/usr/local/lib/perl"
2216 incpush(PRIVLIB_EXP);
2219 incpush(SITEARCH_EXP);
2222 incpush(SITELIB_EXP);
2224 #ifdef OLDARCHLIB_EXP /* 5.00[01] compatibility */
2225 incpush(OLDARCHLIB_EXP);
2238 line_t oldline = curcop->cop_line;
2240 Copy(top_env, oldtop, 1, Sigjmp_buf);
2242 while (AvFILL(list) >= 0) {
2243 CV *cv = (CV*)av_shift(list);
2247 switch (Sigsetjmp(top_env,1)) {
2249 SV* atsv = GvSV(errgv);
2251 perl_call_sv((SV*)cv, G_EVAL|G_DISCARD);
2252 (void)SvPV(atsv, len);
2254 Copy(oldtop, top_env, 1, Sigjmp_buf);
2255 curcop = &compiling;
2256 curcop->cop_line = oldline;
2257 if (list == beginav)
2258 sv_catpv(atsv, "BEGIN failed--compilation aborted");
2260 sv_catpv(atsv, "END failed--cleanup aborted");
2261 croak("%s", SvPVX(atsv));
2267 statusvalue = 255; /* XXX I don't think we use 1 anymore. */
2273 /* my_exit() was called */
2274 curstash = defstash;
2278 Copy(oldtop, top_env, 1, Sigjmp_buf);
2279 curcop = &compiling;
2280 curcop->cop_line = oldline;
2282 if (list == beginav)
2283 croak("BEGIN failed--compilation aborted");
2285 croak("END failed--cleanup aborted");
2287 my_exit(statusvalue);
2292 PerlIO_printf(PerlIO_stderr(), "panic: restartop\n");
2296 Copy(oldtop, top_env, 1, Sigjmp_buf);
2297 curcop = &compiling;
2298 curcop->cop_line = oldline;
2299 Siglongjmp(top_env, 3);
2303 Copy(oldtop, top_env, 1, Sigjmp_buf);