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 /* Omit -- it causes too much grief on mixed systems.
24 dEXT char rcsid[] = "perl.c\nPatch level: ###\n";
32 #ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
38 static void find_beginning _((void));
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);
124 #if defined(SUBVERSION) && SUBVERSION > 0
125 sprintf(patchlevel, "%7.5f", 5.0 + (PATCHLEVEL / 1000.0)
126 + (SUBVERSION / 100000.0));
128 sprintf(patchlevel, "%5.3f", 5.0 + (PATCHLEVEL / 1000.0));
131 #if defined(LOCAL_PATCH_COUNT)
132 localpatches = local_patches; /* For possible -v */
135 fdpid = newAV(); /* for remembering popen pids by fd */
136 pidstatus = newHV();/* for remembering status of dead pids */
143 perl_destruct(sv_interp)
144 register PerlInterpreter *sv_interp;
146 int destruct_level; /* 0=none, 1=full, 2=full with checks */
150 if (!(curinterp = sv_interp))
153 destruct_level = perl_destruct_level;
157 if (s = getenv("PERL_DESTRUCT_LEVEL"))
158 destruct_level = atoi(s);
165 /* We must account for everything. First the syntax tree. */
167 curpad = AvARRAY(comppad);
173 * Try to destruct global references. We do this first so that the
174 * destructors and destructees still exist. Some sv's might remain.
175 * Non-referenced objects are on their own.
182 if (destruct_level == 0){
184 DEBUG_P(debprofdump());
186 /* The exit() function will do everything that needs doing. */
190 /* Prepare to destruct main symbol table. */
196 if (destruct_level >= 2) {
197 if (scopestack_ix != 0)
198 warn("Unbalanced scopes: %d more ENTERs than LEAVEs\n", scopestack_ix);
199 if (savestack_ix != 0)
200 warn("Unbalanced saves: %d more saves than restores\n", savestack_ix);
201 if (tmps_floor != -1)
202 warn("Unbalanced tmps: %d more allocs than frees\n", tmps_floor + 1);
203 if (cxstack_ix != -1)
204 warn("Unbalanced context: %d more PUSHes than POPs\n", cxstack_ix + 1);
207 /* Now absolutely destruct everything, somehow or other, loops or no. */
209 SvFLAGS(strtab) |= SVTYPEMASK; /* don't clean out strtab now */
210 while (sv_count != 0 && sv_count != last_sv_count) {
211 last_sv_count = sv_count;
214 SvFLAGS(strtab) &= ~SVTYPEMASK;
215 SvFLAGS(strtab) |= SVt_PVHV;
217 /* Destruct the global string table. */
219 /* Yell and reset the HeVAL() slots that are still holding refcounts,
220 * so that sv_free() won't fail on them.
229 array = HvARRAY(strtab);
233 warn("Unbalanced string table refcount: (%d) for \"%s\"",
234 HeVAL(hent) - Nullsv, HeKEY(hent));
235 HeVAL(hent) = Nullsv;
245 SvREFCNT_dec(strtab);
248 warn("Scalars leaked: %d\n", sv_count);
252 linestr = NULL; /* No SVs have survived, need to clean out */
254 Safefree(origfilename);
256 hints = 0; /* Reset hints. Should hints be per-interpreter ? */
258 DEBUG_P(debprofdump());
263 PerlInterpreter *sv_interp;
265 if (!(curinterp = sv_interp))
269 #if !defined(STANDARD_C) && !defined(HAS_GETENV_PROTOTYPE)
270 char *getenv _((char *)); /* Usually in <stdlib.h> */
274 perl_parse(sv_interp, xsinit, argc, argv, env)
275 PerlInterpreter *sv_interp;
276 void (*xsinit)_((void));
283 char *scriptname = NULL;
284 VOL bool dosearch = FALSE;
288 #ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
291 croak("suidperl is no longer needed since the kernel can now execute\n\
292 setuid perl scripts securely.\n");
296 if (!(curinterp = sv_interp))
299 #if defined(NeXT) && defined(__DYNAMIC__)
300 _dyld_lookup_and_bind
301 ("__environ", (unsigned long *) &environ_pointer, NULL);
306 #ifndef VMS /* VMS doesn't have environ array */
307 origenviron = environ;
313 /* Come here if running an undumped a.out. */
315 origfilename = savepv(argv[0]);
317 cxstack_ix = -1; /* start label stack again */
319 init_postdump_symbols(argc,argv,env);
327 switch (Sigsetjmp(top_env,1)) {
338 return(statusvalue); /* my_exit() was called */
340 fprintf(stderr, "panic: top_env\n");
344 sv_setpvn(linestr,"",0);
345 sv = newSVpv("",0); /* first used for -I flags */
348 for (argc--,argv++; argc > 0; argc--,argv++) {
349 if (argv[0][0] != '-' || !argv[0][1])
353 validarg = " PHOOEY ";
379 if (s = moreswitches(s))
384 if (euid != uid || egid != gid)
385 croak("No -e allowed in setuid scripts");
387 e_tmpname = savepv(TMPPATH);
388 (void)mktemp(e_tmpname);
390 croak("Can't mktemp()");
391 e_fp = fopen(e_tmpname,"w");
393 croak("Cannot open temporary file");
399 (void)putc('\n', e_fp);
407 av_push(GvAVn(incgv),newSVpv(s,0));
410 av_push(GvAVn(incgv),newSVpv(argv[1],0));
411 sv_catpv(sv,argv[1]);
428 preambleav = newAV();
429 av_push(preambleav, newSVpv("use Config qw(myconfig config_vars)",0));
431 Sv = newSVpv("print myconfig();",0);
433 sv_catpv(Sv,"print \"\\nCharacteristics of this PERLSHR image: \\n\",");
435 sv_catpv(Sv,"print \"\\nCharacteristics of this binary (from libperl): \\n\",");
437 #if defined(DEBUGGING) || defined(NOEMBED) || defined(MULTIPLICITY)
438 strcpy(buf,"\" Compile-time options:");
440 strcat(buf," DEBUGGING");
443 strcat(buf," NOEMBED");
446 strcat(buf," MULTIPLICITY");
448 strcat(buf,"\\n\",");
451 #if defined(LOCAL_PATCH_COUNT)
452 if (LOCAL_PATCH_COUNT > 0)
454 sv_catpv(Sv,"print \" Locally applied patches:\\n\",");
455 for (i = 1; i <= LOCAL_PATCH_COUNT; i++) {
456 if (localpatches[i]) {
457 sprintf(buf,"\" \\t%s\\n\",",localpatches[i]);
463 sprintf(buf,"\" Built under %s\\n\",",OSNAME);
467 sprintf(buf,"\" Compiled at %s %s\\n\"",__DATE__,__TIME__);
469 sprintf(buf,"\" Compiled on %s\\n\"",__DATE__);
473 sv_catpv(Sv,"; $\"=\"\\n \"; print \" \\@INC:\\n @INC\\n\"");
476 Sv = newSVpv("config_vars(qw(",0);
481 av_push(preambleav, Sv);
482 scriptname = BIT_BUCKET; /* don't look for script or read stdin */
496 croak("Unrecognized switch: -%s",s);
501 scriptname = argv[0];
503 if (Fflush(e_fp) || ferror(e_fp) || fclose(e_fp))
504 croak("Can't write to temp file for -e: %s", Strerror(errno));
507 scriptname = e_tmpname;
509 else if (scriptname == Nullch) {
511 if ( isatty(fileno(stdin)) )
519 open_script(scriptname,dosearch,sv);
521 validate_suid(validarg, scriptname);
526 compcv = (CV*)NEWSV(1104,0);
527 sv_upgrade((SV *)compcv, SVt_PVCV);
530 av_push(comppad, Nullsv);
531 curpad = AvARRAY(comppad);
532 comppad_name = newAV();
533 comppad_name_fill = 0;
534 min_intro_pending = 0;
537 comppadlist = newAV();
538 AvREAL_off(comppadlist);
539 av_store(comppadlist, 0, (SV*)comppad_name);
540 av_store(comppadlist, 1, (SV*)comppad);
541 CvPADLIST(compcv) = comppadlist;
543 boot_core_UNIVERSAL();
545 (*xsinit)(); /* in case linked C routines want magical variables */
550 init_predump_symbols();
552 init_postdump_symbols(argc,argv,env);
556 /* now parse the script */
559 if (yyparse() || error_count) {
561 croak("%s had compilation errors.\n", origfilename);
563 croak("Execution of %s aborted due to compilation errors.\n",
567 curcop->cop_line = 0;
571 (void)UNLINK(e_tmpname);
576 /* now that script is parsed, we can modify record separator */
578 rs = SvREFCNT_inc(nrs);
579 sv_setsv(GvSV(gv_fetchpv("/", TRUE, SVt_PV)), rs);
590 #ifdef DEBUGGING_MSTATS
591 if ((s=getenv("PERL_DEBUG_MSTATS")) && atoi(s) >= 2)
592 dump_mstats("after compilation:");
602 PerlInterpreter *sv_interp;
604 if (!(curinterp = sv_interp))
606 switch (Sigsetjmp(top_env,1)) {
608 cxstack_ix = -1; /* start context stack again */
615 #ifdef DEBUGGING_MSTATS
616 if (getenv("PERL_DEBUG_MSTATS"))
617 dump_mstats("after execution: ");
619 return(statusvalue); /* my_exit() was called */
622 fprintf(stderr, "panic: restartop\n");
626 if (curstack != mainstack) {
628 SWITCHSTACK(curstack, mainstack);
633 DEBUG_r(fprintf(stderr, "%s $` $& $' support.\n",
634 sawampersand ? "Enabling" : "Omitting"));
638 DEBUG(fprintf(Perl_debug_log,"\nEXECUTING...\n\n"));
641 fprintf(stderr,"%s syntax OK\n", origfilename);
644 if (perldb && DBsingle)
645 sv_setiv(DBsingle, 1);
655 else if (main_start) {
668 register CONTEXT *cx;
672 statusvalue = FIXSTATUS(status);
673 if (cxstack_ix >= 0) {
679 Siglongjmp(top_env, 2);
683 perl_get_sv(name, create)
687 GV* gv = gv_fetchpv(name, create, SVt_PV);
694 perl_get_av(name, create)
698 GV* gv = gv_fetchpv(name, create, SVt_PVAV);
707 perl_get_hv(name, create)
711 GV* gv = gv_fetchpv(name, create, SVt_PVHV);
720 perl_get_cv(name, create)
724 GV* gv = gv_fetchpv(name, create, SVt_PVCV);
725 if (create && !GvCV(gv))
726 return newSUB(start_subparse(),
727 newSVOP(OP_CONST, 0, newSVpv(name,0)),
735 /* Be sure to refetch the stack pointer after calling these routines. */
738 perl_call_argv(subname, flags, argv)
740 I32 flags; /* See G_* flags in cop.h */
741 register char **argv; /* null terminated arg list */
748 XPUSHs(sv_2mortal(newSVpv(*argv,0)));
753 return perl_call_pv(subname, flags);
757 perl_call_pv(subname, flags)
758 char *subname; /* name of the subroutine */
759 I32 flags; /* See G_* flags in cop.h */
761 return perl_call_sv((SV*)perl_get_cv(subname, TRUE), flags);
765 perl_call_method(methname, flags)
766 char *methname; /* name of the subroutine */
767 I32 flags; /* See G_* flags in cop.h */
773 XPUSHs(sv_2mortal(newSVpv(methname,0)));
776 return perl_call_sv(*stack_sp--, flags);
779 /* May be called with any of a CV, a GV, or an SV containing the name. */
781 perl_call_sv(sv, flags)
783 I32 flags; /* See G_* flags in cop.h */
785 LOGOP myop; /* fake syntax tree node */
787 I32 oldmark = TOPMARK;
793 if (flags & G_DISCARD) {
803 oldscope = scopestack_ix;
805 if (!(flags & G_NOARGS))
806 myop.op_flags = OPf_STACKED;
807 myop.op_next = Nullop;
808 myop.op_flags |= OPf_KNOW;
810 myop.op_flags |= OPf_LIST;
812 if (perldb && curstash != debstash
813 && (DBcv || (DBcv = GvCV(DBsub)))) /* to handle first BEGIN of -d */
814 op->op_private |= OPpENTERSUB_DB;
816 if (flags & G_EVAL) {
817 Copy(top_env, oldtop, 1, Sigjmp_buf);
819 cLOGOP->op_other = op;
821 /* we're trying to emulate pp_entertry() here */
823 register CONTEXT *cx;
829 push_return(op->op_next);
830 PUSHBLOCK(cx, CXt_EVAL, stack_sp);
832 eval_root = op; /* Only needed so that goto works right. */
835 if (flags & G_KEEPERR)
838 sv_setpv(GvSV(errgv),"");
843 switch (Sigsetjmp(top_env,1)) {
848 statusvalue = 255; /* XXX I don't think we use 1 anymore. */
854 /* my_exit() was called */
857 Copy(oldtop, top_env, 1, Sigjmp_buf);
859 croak("Callback called exit");
860 my_exit(statusvalue);
868 stack_sp = stack_base + oldmark;
873 *++stack_sp = &sv_undef;
879 if (op == (OP*)&myop)
883 retval = stack_sp - (stack_base + oldmark);
884 if ((flags & G_EVAL) && !(flags & G_KEEPERR))
885 sv_setpv(GvSV(errgv),"");
888 if (flags & G_EVAL) {
889 if (scopestack_ix > oldscope) {
893 register CONTEXT *cx;
902 Copy(oldtop, top_env, 1, Sigjmp_buf);
904 if (flags & G_DISCARD) {
905 stack_sp = stack_base + oldmark;
913 /* Eval a string. The G_EVAL flag is always assumed. */
916 perl_eval_sv(sv, flags)
918 I32 flags; /* See G_* flags in cop.h */
920 UNOP myop; /* fake syntax tree node */
922 I32 oldmark = sp - stack_base;
927 if (flags & G_DISCARD) {
937 oldscope = scopestack_ix;
939 if (!(flags & G_NOARGS))
940 myop.op_flags = OPf_STACKED;
941 myop.op_next = Nullop;
942 myop.op_type = OP_ENTEREVAL;
943 myop.op_flags |= OPf_KNOW;
944 if (flags & G_KEEPERR)
945 myop.op_flags |= OPf_SPECIAL;
947 myop.op_flags |= OPf_LIST;
949 Copy(top_env, oldtop, 1, Sigjmp_buf);
952 switch (Sigsetjmp(top_env,1)) {
957 statusvalue = 255; /* XXX I don't think we use 1 anymore. */
963 /* my_exit() was called */
966 Copy(oldtop, top_env, 1, Sigjmp_buf);
968 croak("Callback called exit");
969 my_exit(statusvalue);
977 stack_sp = stack_base + oldmark;
982 *++stack_sp = &sv_undef;
987 if (op == (OP*)&myop)
991 retval = stack_sp - (stack_base + oldmark);
992 if (!(flags & G_KEEPERR))
993 sv_setpv(GvSV(errgv),"");
996 Copy(oldtop, top_env, 1, Sigjmp_buf);
997 if (flags & G_DISCARD) {
998 stack_sp = stack_base + oldmark;
1006 /* Require a module. */
1012 SV* sv = sv_newmortal();
1013 sv_setpv(sv, "require '");
1016 perl_eval_sv(sv, G_DISCARD);
1020 magicname(sym,name,namlen)
1027 if (gv = gv_fetchpv(sym,TRUE, SVt_PV))
1028 sv_magic(GvSV(gv), (SV*)gv, 0, name, namlen);
1032 # define PERLLIB_SEP ';'
1035 # define PERLLIB_SEP '|'
1037 # define PERLLIB_SEP ':'
1050 /* Break at all separators */
1052 /* First, skip any consecutive separators */
1053 while ( *p == PERLLIB_SEP ) {
1054 /* Uncomment the next line for PATH semantics */
1055 /* av_push(GvAVn(incgv), newSVpv(".", 1)); */
1058 if ( (s = strchr(p, PERLLIB_SEP)) != Nullch ) {
1059 av_push(GvAVn(incgv), newSVpv(p, (STRLEN)(s - p)));
1062 av_push(GvAVn(incgv), newSVpv(p, 0));
1069 usage(name) /* XXX move this out into a module ? */
1072 /* This message really ought to be max 23 lines.
1073 * Removed -h because the user already knows that opton. Others? */
1074 printf("\nUsage: %s [switches] [--] [programfile] [arguments]", name);
1075 printf("\n -0[octal] specify record separator (\\0, if no argument)");
1076 printf("\n -a autosplit mode with -n or -p (splits $_ into @F)");
1077 printf("\n -c check syntax only (runs BEGIN and END blocks)");
1078 printf("\n -d[:debugger] run scripts under debugger");
1079 printf("\n -D[number/list] set debugging flags (argument is a bit mask or flags)");
1080 printf("\n -e 'command' one line of script. Several -e's allowed. Omit [programfile].");
1081 printf("\n -F/pattern/ split() pattern for autosplit (-a). The //'s are optional.");
1082 printf("\n -i[extension] edit <> files in place (make backup if extension supplied)");
1083 printf("\n -Idirectory specify @INC/#include directory (may be used more then once)");
1084 printf("\n -l[octal] enable line ending processing, specifies line teminator");
1085 printf("\n -[mM][-]module.. executes `use/no module...' before executing your script.");
1086 printf("\n -n assume 'while (<>) { ... }' loop arround your script");
1087 printf("\n -p assume loop like -n but print line also like sed");
1088 printf("\n -P run script through C preprocessor before compilation");
1089 printf("\n -s enable some switch parsing for switches after script name");
1090 printf("\n -S look for the script using PATH environment variable");
1091 printf("\n -T turn on tainting checks");
1092 printf("\n -u dump core after parsing script");
1093 printf("\n -U allow unsafe operations");
1094 printf("\n -v print version number and patchlevel of perl");
1095 printf("\n -V[:variable] print perl configuration information");
1096 printf("\n -w TURN WARNINGS ON FOR COMPILATION OF YOUR SCRIPT.");
1097 printf("\n -x[directory] strip off text before #!perl line and perhaps cd to directory\n");
1100 /* This routine handles any switches that can be given during run */
1111 rschar = scan_oct(s, 4, &numlen);
1113 if (rschar & ~((U8)~0))
1115 else if (!rschar && numlen >= 2)
1116 nrs = newSVpv("", 0);
1119 nrs = newSVpv(&ch, 1);
1124 splitstr = savepv(s + 1);
1138 if (*s == ':' || *s == '=') {
1139 sprintf(buf, "use Devel::%s;", ++s);
1141 my_setenv("PERL5DB",buf);
1151 if (isALPHA(s[1])) {
1152 static char debopts[] = "psltocPmfrxuLHXD";
1155 for (s++; *s && (d = strchr(debopts,*s)); s++)
1156 debug |= 1 << (d - debopts);
1160 for (s++; isDIGIT(*s); s++) ;
1162 debug |= 0x80000000;
1164 warn("Recompile perl with -DDEBUGGING to use -D switch\n");
1165 for (s++; isALNUM(*s); s++) ;
1175 inplace = savepv(s+1);
1177 for (s = inplace; *s && !isSPACE(*s); s++) ;
1184 for (e = s; *e && !isSPACE(*e); e++) ;
1185 av_push(GvAVn(incgv),newSVpv(s,e-s));
1190 croak("No space allowed after -I");
1200 *ors = scan_oct(s, 3 + (*s == '0'), &numlen);
1209 ors = SvPV(nrs, orslen);
1210 ors = savepvn(ors, orslen);
1214 taint_not("-M"); /* XXX ? */
1217 taint_not("-m"); /* XXX ? */
1221 /* -M-foo == 'no foo' */
1222 if (*s == '-') { use = "no "; ++s; }
1223 Sv = newSVpv(use,0);
1225 /* We allow -M'Module qw(Foo Bar)' */
1226 while(isALNUM(*s) || *s==':') ++s;
1228 sv_catpv(Sv, start);
1229 if (*(start-1) == 'm') {
1231 croak("Can't use '%c' after -mname", *s);
1232 sv_catpv( Sv, " ()");
1235 sv_catpvn(Sv, start, s-start);
1236 sv_catpv(Sv, " split(/,/,q{");
1241 if (preambleav == NULL)
1242 preambleav = newAV();
1243 av_push(preambleav, Sv);
1246 croak("No space allowed after -%c", *(s-1));
1274 #if defined(SUBVERSION) && SUBVERSION > 0
1275 printf("\nThis is perl, version 5.%03d_%02d", PATCHLEVEL, SUBVERSION);
1277 printf("\nThis is perl, version %s",patchlevel);
1280 fputs("\n\nCopyright 1987-1996, Larry Wall\n",stdout);
1281 fputs("\n\t+ suidperl security patch", stdout);
1283 fputs("MS-DOS port Copyright (c) 1989, 1990, Diomidis Spinellis\n",
1287 fputs("OS/2 port Copyright (c) 1990, 1991, Raymond Chen, Kai Uwe Rommel\n"
1288 "Version 5 port Copyright (c) 1994-1996, Andreas Kaiser, Ilya Zakharevich\n", stdout);
1291 fputs("atariST series port, ++jrb bammi@cadence.com\n", stdout);
1294 Perl may be copied only under the terms of either the Artistic License or the\n\
1295 GNU General Public License, which may be found in the Perl 5.0 source kit.\n\n",stdout);
1306 if (s[1] == '-') /* Additional switches on #! line. */
1319 croak("Can't emulate -%.1s on #! line",s);
1324 /* compliments of Tom Christiansen */
1326 /* unexec() can be found in the Gnu emacs distribution */
1335 sprintf (buf, "%s.perldump", origfilename);
1336 sprintf (tokenbuf, "%s/perl", BIN);
1338 status = unexec(buf, tokenbuf, &etext, sbrk(0), 0);
1340 fprintf(stderr, "unexec of %s into %s failed!\n", tokenbuf, buf);
1344 # include <lib$routines.h>
1345 lib$signal(SS$_DEBUG); /* ssdef.h #included from vmsish.h */
1347 ABORT(); /* for use with undump */
1357 /* Note that strtab is a rather special HV. Assumptions are made
1358 about not iterating on it, and not adding tie magic to it.
1359 It is properly deallocated in perl_destruct() */
1361 HvSHAREKEYS_off(strtab); /* mandatory */
1362 Newz(506,((XPVHV*)SvANY(strtab))->xhv_array,
1363 sizeof(HE*) * (((XPVHV*)SvANY(strtab))->xhv_max + 1), char);
1365 curstash = defstash = newHV();
1366 curstname = newSVpv("main",4);
1367 gv = gv_fetchpv("main::",TRUE, SVt_PVHV);
1368 SvREFCNT_dec(GvHV(gv));
1369 GvHV(gv) = (HV*)SvREFCNT_inc(defstash);
1371 HvNAME(defstash) = savepv("main");
1372 incgv = gv_HVadd(gv_AVadd(gv_fetchpv("INC",TRUE, SVt_PVAV)));
1374 defgv = gv_fetchpv("_",TRUE, SVt_PVAV);
1375 errgv = gv_HVadd(gv_fetchpv("@", TRUE, SVt_PV));
1377 curstash = defstash;
1378 compiling.cop_stash = defstash;
1379 debstash = GvHV(gv_fetchpv("DB::", GV_ADDMULTI, SVt_PVHV));
1380 /* We must init $/ before switches are processed. */
1381 sv_setpvn(GvSV(gv_fetchpv("/", TRUE, SVt_PV)), "\n", 1);
1384 #ifdef CAN_PROTOTYPE
1386 open_script(char *scriptname, bool dosearch, SV *sv)
1389 open_script(scriptname,dosearch,sv)
1395 char *xfound = Nullch;
1396 char *xfailed = Nullch;
1400 #if defined(DOSISH) && !defined(OS2) && !defined(atarist)
1401 #define SEARCH_EXTS ".bat", ".cmd", NULL
1404 # define SEARCH_EXTS ".pl", ".com", NULL
1406 /* additional extensions to try in each dir if scriptname not found */
1408 char *ext[] = { SEARCH_EXTS };
1409 int extidx = (strchr(scriptname,'.')) ? -1 : 0; /* has ext already */
1414 int hasdir, idx = 0, deftypes = 1;
1416 hasdir = (strpbrk(scriptname,":[</") != Nullch) ;
1417 /* The first time through, just add SEARCH_EXTS to whatever we
1418 * already have, so we can check for default file types. */
1419 while (deftypes || (!hasdir && my_trnlnm("DCL$PATH",tokenbuf,idx++)) ) {
1420 if (deftypes) { deftypes = 0; *tokenbuf = '\0'; }
1421 strcat(tokenbuf,scriptname);
1423 if (dosearch && !strchr(scriptname, '/') && (s = getenv("PATH"))) {
1425 bufend = s + strlen(s);
1428 s = cpytill(tokenbuf,s,bufend,':',&len);
1431 for (len = 0; *s && *s != ',' && *s != ';'; tokenbuf[len++] = *s++);
1432 tokenbuf[len] = '\0';
1434 for (len = 0; *s && *s != ';'; tokenbuf[len++] = *s++);
1435 tokenbuf[len] = '\0';
1441 if (len && tokenbuf[len-1] != '/')
1444 if (len && ((tokenbuf[len-1] != '\\') && (tokenbuf[len-1] != '/')))
1446 if (len && tokenbuf[len-1] != '\\')
1449 (void)strcat(tokenbuf+len,"/");
1450 (void)strcat(tokenbuf+len,scriptname);
1454 len = strlen(tokenbuf);
1455 if (extidx > 0) /* reset after previous loop */
1459 DEBUG_p(fprintf(Perl_debug_log,"Looking for %s\n",tokenbuf));
1460 retval = Stat(tokenbuf,&statbuf);
1462 } while ( retval < 0 /* not there */
1463 && extidx>=0 && ext[extidx] /* try an extension? */
1464 && strcpy(tokenbuf+len, ext[extidx++])
1469 if (S_ISREG(statbuf.st_mode)
1470 && cando(S_IRUSR,TRUE,&statbuf) && cando(S_IXUSR,TRUE,&statbuf)) {
1471 xfound = tokenbuf; /* bingo! */
1475 xfailed = savepv(tokenbuf);
1478 croak("Can't execute %s", xfailed ? xfailed : scriptname );
1481 scriptname = xfound;
1484 if (strnEQ(scriptname, "/dev/fd/", 8) && isDIGIT(scriptname[8]) ) {
1485 char *s = scriptname + 8;
1494 origfilename = savepv(e_tmpname ? "-e" : scriptname);
1495 curcop->cop_filegv = gv_fetchfile(origfilename);
1496 if (strEQ(origfilename,"-"))
1498 if (fdscript >= 0) {
1499 rsfp = fdopen(fdscript,"r");
1500 #if defined(HAS_FCNTL) && defined(F_SETFD)
1501 fcntl(fileno(rsfp),F_SETFD,1); /* ensure close-on-exec */
1504 else if (preprocess) {
1505 char *cpp = CPPSTDIN;
1507 if (strEQ(cpp,"cppstdin"))
1508 sprintf(tokenbuf, "%s/%s", SCRIPTDIR, cpp);
1510 sprintf(tokenbuf, "%s", cpp);
1512 sv_catpv(sv,PRIVLIB_EXP);
1514 (void)sprintf(buf, "\
1515 sed %s -e \"/^[^#]/b\" \
1516 -e \"/^#[ ]*include[ ]/b\" \
1517 -e \"/^#[ ]*define[ ]/b\" \
1518 -e \"/^#[ ]*if[ ]/b\" \
1519 -e \"/^#[ ]*ifdef[ ]/b\" \
1520 -e \"/^#[ ]*ifndef[ ]/b\" \
1521 -e \"/^#[ ]*else/b\" \
1522 -e \"/^#[ ]*elif[ ]/b\" \
1523 -e \"/^#[ ]*undef[ ]/b\" \
1524 -e \"/^#[ ]*endif/b\" \
1527 (doextract ? "-e \"1,/^#/d\n\"" : ""),
1529 (void)sprintf(buf, "\
1530 %s %s -e '/^[^#]/b' \
1531 -e '/^#[ ]*include[ ]/b' \
1532 -e '/^#[ ]*define[ ]/b' \
1533 -e '/^#[ ]*if[ ]/b' \
1534 -e '/^#[ ]*ifdef[ ]/b' \
1535 -e '/^#[ ]*ifndef[ ]/b' \
1536 -e '/^#[ ]*else/b' \
1537 -e '/^#[ ]*elif[ ]/b' \
1538 -e '/^#[ ]*undef[ ]/b' \
1539 -e '/^#[ ]*endif/b' \
1547 (doextract ? "-e '1,/^#/d\n'" : ""),
1549 scriptname, tokenbuf, SvPV(sv, na), CPPMINUS);
1551 #ifdef IAMSUID /* actually, this is caught earlier */
1552 if (euid != uid && !euid) { /* if running suidperl */
1554 (void)seteuid(uid); /* musn't stay setuid root */
1557 (void)setreuid((Uid_t)-1, uid);
1559 #ifdef HAS_SETRESUID
1560 (void)setresuid((Uid_t)-1, uid, (Uid_t)-1);
1566 if (geteuid() != uid)
1567 croak("Can't do seteuid!\n");
1569 #endif /* IAMSUID */
1570 rsfp = my_popen(buf,"r");
1572 else if (!*scriptname) {
1573 taint_not("program input from stdin");
1577 rsfp = fopen(scriptname,"r");
1578 #if defined(HAS_FCNTL) && defined(F_SETFD)
1579 fcntl(fileno(rsfp),F_SETFD,1); /* ensure close-on-exec */
1582 if ((FILE*)rsfp == Nullfp) {
1584 #ifndef IAMSUID /* in case script is not readable before setuid */
1585 if (euid && Stat(SvPVX(GvSV(curcop->cop_filegv)),&statbuf) >= 0 &&
1586 statbuf.st_mode & (S_ISUID|S_ISGID)) {
1587 (void)sprintf(buf, "%s/sperl%s", BIN, patchlevel);
1588 execv(buf, origargv); /* try again */
1589 croak("Can't do setuid\n");
1593 croak("Can't open perl script \"%s\": %s\n",
1594 SvPVX(GvSV(curcop->cop_filegv)), Strerror(errno));
1599 validate_suid(validarg, scriptname)
1605 /* do we need to emulate setuid on scripts? */
1607 /* This code is for those BSD systems that have setuid #! scripts disabled
1608 * in the kernel because of a security problem. Merely defining DOSUID
1609 * in perl will not fix that problem, but if you have disabled setuid
1610 * scripts in the kernel, this will attempt to emulate setuid and setgid
1611 * on scripts that have those now-otherwise-useless bits set. The setuid
1612 * root version must be called suidperl or sperlN.NNN. If regular perl
1613 * discovers that it has opened a setuid script, it calls suidperl with
1614 * the same argv that it had. If suidperl finds that the script it has
1615 * just opened is NOT setuid root, it sets the effective uid back to the
1616 * uid. We don't just make perl setuid root because that loses the
1617 * effective uid we had before invoking perl, if it was different from the
1620 * DOSUID must be defined in both perl and suidperl, and IAMSUID must
1621 * be defined in suidperl only. suidperl must be setuid root. The
1622 * Configure script will set this up for you if you want it.
1628 if (Fstat(fileno(rsfp),&statbuf) < 0) /* normal stat is insecure */
1629 croak("Can't stat script \"%s\"",origfilename);
1630 if (fdscript < 0 && statbuf.st_mode & (S_ISUID|S_ISGID)) {
1634 #ifndef HAS_SETREUID
1635 /* On this access check to make sure the directories are readable,
1636 * there is actually a small window that the user could use to make
1637 * filename point to an accessible directory. So there is a faint
1638 * chance that someone could execute a setuid script down in a
1639 * non-accessible directory. I don't know what to do about that.
1640 * But I don't think it's too important. The manual lies when
1641 * it says access() is useful in setuid programs.
1643 if (access(SvPVX(GvSV(curcop->cop_filegv)),1)) /*double check*/
1644 croak("Permission denied");
1646 /* If we can swap euid and uid, then we can determine access rights
1647 * with a simple stat of the file, and then compare device and
1648 * inode to make sure we did stat() on the same file we opened.
1649 * Then we just have to make sure he or she can execute it.
1652 struct stat tmpstatbuf;
1656 setreuid(euid,uid) < 0
1659 setresuid(euid,uid,(Uid_t)-1) < 0
1662 || getuid() != euid || geteuid() != uid)
1663 croak("Can't swap uid and euid"); /* really paranoid */
1664 if (Stat(SvPVX(GvSV(curcop->cop_filegv)),&tmpstatbuf) < 0)
1665 croak("Permission denied"); /* testing full pathname here */
1666 if (tmpstatbuf.st_dev != statbuf.st_dev ||
1667 tmpstatbuf.st_ino != statbuf.st_ino) {
1669 if (rsfp = my_popen("/bin/mail root","w")) { /* heh, heh */
1671 "User %d tried to run dev %d ino %d in place of dev %d ino %d!\n\
1672 (Filename of set-id script was %s, uid %d gid %d.)\n\nSincerely,\nperl\n",
1673 uid,tmpstatbuf.st_dev, tmpstatbuf.st_ino,
1674 statbuf.st_dev, statbuf.st_ino,
1675 SvPVX(GvSV(curcop->cop_filegv)),
1676 statbuf.st_uid, statbuf.st_gid);
1677 (void)my_pclose(rsfp);
1679 croak("Permission denied\n");
1683 setreuid(uid,euid) < 0
1685 # if defined(HAS_SETRESUID)
1686 setresuid(uid,euid,(Uid_t)-1) < 0
1689 || getuid() != uid || geteuid() != euid)
1690 croak("Can't reswap uid and euid");
1691 if (!cando(S_IXUSR,FALSE,&statbuf)) /* can real uid exec? */
1692 croak("Permission denied\n");
1694 #endif /* HAS_SETREUID */
1695 #endif /* IAMSUID */
1697 if (!S_ISREG(statbuf.st_mode))
1698 croak("Permission denied");
1699 if (statbuf.st_mode & S_IWOTH)
1700 croak("Setuid/gid script is writable by world");
1701 doswitches = FALSE; /* -s is insecure in suid */
1703 if (fgets(tokenbuf,sizeof tokenbuf, rsfp) == Nullch ||
1704 strnNE(tokenbuf,"#!",2) ) /* required even on Sys V */
1705 croak("No #! line");
1708 while (!isSPACE(*s)) s++;
1709 for (s2 = s; (s2 > tokenbuf+2 &&
1710 (isDIGIT(s2[-1]) || strchr("._-", s2[-1]))); s2--) ;
1711 if (strnNE(s2-4,"perl",4) && strnNE(s-9,"perl",4)) /* sanity check */
1712 croak("Not a perl script");
1713 while (*s == ' ' || *s == '\t') s++;
1715 * #! arg must be what we saw above. They can invoke it by
1716 * mentioning suidperl explicitly, but they may not add any strange
1717 * arguments beyond what #! says if they do invoke suidperl that way.
1719 len = strlen(validarg);
1720 if (strEQ(validarg," PHOOEY ") ||
1721 strnNE(s,validarg,len) || !isSPACE(s[len]))
1722 croak("Args must match #! line");
1725 if (euid != uid && (statbuf.st_mode & S_ISUID) &&
1726 euid == statbuf.st_uid)
1728 croak("YOU HAVEN'T DISABLED SET-ID SCRIPTS IN THE KERNEL YET!\n\
1729 FIX YOUR KERNEL, PUT A C WRAPPER AROUND THIS SCRIPT, OR USE -u AND UNDUMP!\n");
1730 #endif /* IAMSUID */
1732 if (euid) { /* oops, we're not the setuid root perl */
1735 (void)sprintf(buf, "%s/sperl%s", BIN, patchlevel);
1736 execv(buf, origargv); /* try again */
1738 croak("Can't do setuid\n");
1741 if (statbuf.st_mode & S_ISGID && statbuf.st_gid != egid) {
1743 (void)setegid(statbuf.st_gid);
1746 (void)setregid((Gid_t)-1,statbuf.st_gid);
1748 #ifdef HAS_SETRESGID
1749 (void)setresgid((Gid_t)-1,statbuf.st_gid,(Gid_t)-1);
1751 setgid(statbuf.st_gid);
1755 if (getegid() != statbuf.st_gid)
1756 croak("Can't do setegid!\n");
1758 if (statbuf.st_mode & S_ISUID) {
1759 if (statbuf.st_uid != euid)
1761 (void)seteuid(statbuf.st_uid); /* all that for this */
1764 (void)setreuid((Uid_t)-1,statbuf.st_uid);
1766 #ifdef HAS_SETRESUID
1767 (void)setresuid((Uid_t)-1,statbuf.st_uid,(Uid_t)-1);
1769 setuid(statbuf.st_uid);
1773 if (geteuid() != statbuf.st_uid)
1774 croak("Can't do seteuid!\n");
1776 else if (uid) { /* oops, mustn't run as root */
1778 (void)seteuid((Uid_t)uid);
1781 (void)setreuid((Uid_t)-1,(Uid_t)uid);
1783 #ifdef HAS_SETRESUID
1784 (void)setresuid((Uid_t)-1,(Uid_t)uid,(Uid_t)-1);
1790 if (geteuid() != uid)
1791 croak("Can't do seteuid!\n");
1794 if (!cando(S_IXUSR,TRUE,&statbuf))
1795 croak("Permission denied\n"); /* they can't do this */
1798 else if (preprocess)
1799 croak("-P not allowed for setuid/setgid script\n");
1800 else if (fdscript >= 0)
1801 croak("fd script not allowed in suidperl\n");
1803 croak("Script is not setuid/setgid in suidperl\n");
1805 /* We absolutely must clear out any saved ids here, so we */
1806 /* exec the real perl, substituting fd script for scriptname. */
1807 /* (We pass script name as "subdir" of fd, which perl will grok.) */
1809 lseek(fileno(rsfp),(Off_t)0,0); /* just in case rewind didn't */
1810 for (which = 1; origargv[which] && origargv[which] != scriptname; which++) ;
1811 if (!origargv[which])
1812 croak("Permission denied");
1813 (void)sprintf(buf, "/dev/fd/%d/%.127s", fileno(rsfp), origargv[which]);
1814 origargv[which] = buf;
1816 #if defined(HAS_FCNTL) && defined(F_SETFD)
1817 fcntl(fileno(rsfp),F_SETFD,0); /* ensure no close-on-exec */
1820 (void)sprintf(tokenbuf, "%s/perl%s", BIN, patchlevel);
1821 execv(tokenbuf, origargv); /* try again */
1822 croak("Can't do setuid\n");
1823 #endif /* IAMSUID */
1825 if (euid != uid || egid != gid) { /* (suidperl doesn't exist, in fact) */
1826 #ifndef SETUID_SCRIPTS_ARE_SECURE_NOW
1827 Fstat(fileno(rsfp),&statbuf); /* may be either wrapped or real suid */
1828 if ((euid != uid && euid == statbuf.st_uid && statbuf.st_mode & S_ISUID)
1830 (egid != gid && egid == statbuf.st_gid && statbuf.st_mode & S_ISGID)
1833 croak("YOU HAVEN'T DISABLED SET-ID SCRIPTS IN THE KERNEL YET!\n\
1834 FIX YOUR KERNEL, PUT A C WRAPPER AROUND THIS SCRIPT, OR USE -u AND UNDUMP!\n");
1835 #endif /* SETUID_SCRIPTS_ARE_SECURE_NOW */
1836 /* not set-id, must be wrapped */
1844 register char *s, *s2;
1846 /* skip forward in input to the real script? */
1850 if ((s = sv_gets(linestr, rsfp, 0)) == Nullch)
1851 croak("No Perl script found in input\n");
1852 if (*s == '#' && s[1] == '!' && (s = instr(s,"perl"))) {
1853 ungetc('\n',rsfp); /* to keep line count right */
1855 while (*s && !(isSPACE (*s) || *s == '#')) s++;
1857 while (*s == ' ' || *s == '\t') s++;
1859 while (isDIGIT(s2[-1]) || strchr("-._", s2[-1])) s2--;
1860 if (strnEQ(s2-4,"perl",4))
1862 while (s = moreswitches(s)) ;
1864 if (cddir && chdir(cddir) < 0)
1865 croak("Can't chdir to %s",cddir);
1873 uid = (int)getuid();
1874 euid = (int)geteuid();
1875 gid = (int)getgid();
1876 egid = (int)getegid();
1881 tainting |= (uid && (euid != uid || egid != gid));
1887 curstash = debstash;
1888 dbargs = GvAV(gv_AVadd((gv_fetchpv("args", GV_ADDMULTI, SVt_PVAV))));
1890 DBgv = gv_fetchpv("DB", GV_ADDMULTI, SVt_PVGV);
1891 DBline = gv_fetchpv("dbline", GV_ADDMULTI, SVt_PVAV);
1892 DBsub = gv_HVadd(gv_fetchpv("sub", GV_ADDMULTI, SVt_PVHV));
1893 DBsingle = GvSV((gv_fetchpv("single", GV_ADDMULTI, SVt_PV)));
1894 sv_setiv(DBsingle, 0);
1895 DBtrace = GvSV((gv_fetchpv("trace", GV_ADDMULTI, SVt_PV)));
1896 sv_setiv(DBtrace, 0);
1897 DBsignal = GvSV((gv_fetchpv("signal", GV_ADDMULTI, SVt_PV)));
1898 sv_setiv(DBsignal, 0);
1899 curstash = defstash;
1906 mainstack = curstack; /* remember in case we switch stacks */
1907 AvREAL_off(curstack); /* not a real array */
1908 av_extend(curstack,127);
1910 stack_base = AvARRAY(curstack);
1911 stack_sp = stack_base;
1912 stack_max = stack_base + 127;
1914 /* Shouldn't these stacks be per-interpreter? */
1916 markstack_ptr = markstack;
1918 New(54,markstack,64,I32);
1919 markstack_ptr = markstack;
1920 markstack_max = markstack + 64;
1926 New(54,scopestack,32,I32);
1928 scopestack_max = 32;
1934 New(54,savestack,128,ANY);
1936 savestack_max = 128;
1942 New(54,retstack,16,OP*);
1947 cxstack_max = 8192 / sizeof(CONTEXT) - 2; /* Use most of 8K. */
1948 New(50,cxstack,cxstack_max + 1,CONTEXT);
1951 New(50,tmps_stack,128,SV*);
1956 New(51,debname,128,char);
1957 New(52,debdelim,128,char);
1965 Safefree(tmps_stack);
1968 static FILE *tmpfp; /* moved outside init_lexer() because of UNICOS bug */
1976 subname = newSVpv("main",4);
1980 init_predump_symbols()
1985 sv_setpvn(GvSV(gv_fetchpv("\"", TRUE, SVt_PV)), " ", 1);
1987 stdingv = gv_fetchpv("STDIN",TRUE, SVt_PVIO);
1988 GvMULTI_on(stdingv);
1989 IoIFP(GvIOp(stdingv)) = stdin;
1990 tmpgv = gv_fetchpv("stdin",TRUE, SVt_PV);
1992 GvIOp(tmpgv) = (IO*)SvREFCNT_inc(GvIOp(stdingv));
1994 tmpgv = gv_fetchpv("STDOUT",TRUE, SVt_PVIO);
1996 IoOFP(GvIOp(tmpgv)) = IoIFP(GvIOp(tmpgv)) = stdout;
1998 tmpgv = gv_fetchpv("stdout",TRUE, SVt_PV);
2000 GvIOp(tmpgv) = (IO*)SvREFCNT_inc(GvIOp(defoutgv));
2002 othergv = gv_fetchpv("STDERR",TRUE, SVt_PVIO);
2003 GvMULTI_on(othergv);
2004 IoOFP(GvIOp(othergv)) = IoIFP(GvIOp(othergv)) = stderr;
2005 tmpgv = gv_fetchpv("stderr",TRUE, SVt_PV);
2007 GvIOp(tmpgv) = (IO*)SvREFCNT_inc(GvIOp(othergv));
2009 statname = NEWSV(66,0); /* last filename we did stat on */
2012 osname = savepv(OSNAME);
2016 init_postdump_symbols(argc,argv,env)
2018 register char **argv;
2019 register char **env;
2025 argc--,argv++; /* skip name of script */
2027 for (; argc > 0 && **argv == '-'; argc--,argv++) {
2030 if (argv[0][1] == '-') {
2034 if (s = strchr(argv[0], '=')) {
2036 sv_setpv(GvSV(gv_fetchpv(argv[0]+1,TRUE, SVt_PV)),s);
2039 sv_setiv(GvSV(gv_fetchpv(argv[0]+1,TRUE, SVt_PV)),1);
2042 toptarget = NEWSV(0,0);
2043 sv_upgrade(toptarget, SVt_PVFM);
2044 sv_setpvn(toptarget, "", 0);
2045 bodytarget = NEWSV(0,0);
2046 sv_upgrade(bodytarget, SVt_PVFM);
2047 sv_setpvn(bodytarget, "", 0);
2048 formtarget = bodytarget;
2051 if (tmpgv = gv_fetchpv("0",TRUE, SVt_PV)) {
2052 sv_setpv(GvSV(tmpgv),origfilename);
2053 magicname("0", "0", 1);
2055 if (tmpgv = gv_fetchpv("\024",TRUE, SVt_PV))
2057 if (tmpgv = gv_fetchpv("\030",TRUE, SVt_PV))
2058 sv_setpv(GvSV(tmpgv),origargv[0]);
2059 if (argvgv = gv_fetchpv("ARGV",TRUE, SVt_PVAV)) {
2061 (void)gv_AVadd(argvgv);
2062 av_clear(GvAVn(argvgv));
2063 for (; argc > 0; argc--,argv++) {
2064 av_push(GvAVn(argvgv),newSVpv(argv[0],0));
2067 if (envgv = gv_fetchpv("ENV",TRUE, SVt_PVHV)) {
2072 #ifndef VMS /* VMS doesn't have environ array */
2073 /* Note that if the supplied env parameter is actually a copy
2074 of the global environ then it may now point to free'd memory
2075 if the environment has been modified since. To avoid this
2076 problem we treat env==NULL as meaning 'use the default'
2080 if (env != environ) {
2081 environ[0] = Nullch;
2082 hv_magic(hv, envgv, 'E');
2084 for (; *env; env++) {
2085 if (!(s = strchr(*env,'=')))
2088 sv = newSVpv(s--,0);
2089 sv_magic(sv, sv, 'e', *env, s - *env);
2090 (void)hv_store(hv, *env, s - *env, sv, 0);
2094 #ifdef DYNAMIC_ENV_FETCH
2095 HvNAME(hv) = savepv(ENV_HV_NAME);
2097 hv_magic(hv, envgv, 'E');
2100 if (tmpgv = gv_fetchpv("$",TRUE, SVt_PV))
2101 sv_setiv(GvSV(tmpgv),(I32)getpid());
2110 s = getenv("PERL5LIB");
2114 incpush(getenv("PERLLIB"));
2118 incpush(APPLLIB_EXP);
2122 incpush(ARCHLIB_EXP);
2125 #define PRIVLIB_EXP "/usr/local/lib/perl5:/usr/local/lib/perl"
2127 incpush(PRIVLIB_EXP);
2130 incpush(SITEARCH_EXP);
2133 incpush(SITELIB_EXP);
2135 #ifdef OLDARCHLIB_EXP /* 5.00[01] compatibility */
2136 incpush(OLDARCHLIB_EXP);
2149 line_t oldline = curcop->cop_line;
2151 Copy(top_env, oldtop, 1, Sigjmp_buf);
2153 while (AvFILL(list) >= 0) {
2154 CV *cv = (CV*)av_shift(list);
2158 switch (Sigsetjmp(top_env,1)) {
2160 SV* atsv = GvSV(errgv);
2162 perl_call_sv((SV*)cv, G_EVAL|G_DISCARD);
2163 (void)SvPV(atsv, len);
2165 Copy(oldtop, top_env, 1, Sigjmp_buf);
2166 curcop = &compiling;
2167 curcop->cop_line = oldline;
2168 if (list == beginav)
2169 sv_catpv(atsv, "BEGIN failed--compilation aborted");
2171 sv_catpv(atsv, "END failed--cleanup aborted");
2172 croak("%s", SvPVX(atsv));
2178 statusvalue = 255; /* XXX I don't think we use 1 anymore. */
2184 /* my_exit() was called */
2185 curstash = defstash;
2189 Copy(oldtop, top_env, 1, Sigjmp_buf);
2190 curcop = &compiling;
2191 curcop->cop_line = oldline;
2193 if (list == beginav)
2194 croak("BEGIN failed--compilation aborted");
2196 croak("END failed--cleanup aborted");
2198 my_exit(statusvalue);
2203 fprintf(stderr, "panic: restartop\n");
2207 Copy(oldtop, top_env, 1, Sigjmp_buf);
2208 curcop = &compiling;
2209 curcop->cop_line = oldline;
2210 Siglongjmp(top_env, 3);
2214 Copy(oldtop, top_env, 1, Sigjmp_buf);