Introduction

track perl and python Script access to files , In the actual process ,perl and python After the parser parses the script , It's closed directly

Script files , The name of the script file that is used to access the file cannot be found in the process .

shell、perl and python Script execution process

bash Script execution process

The script content :

#!/usr/bin/env bash
echo `date`" hello world!" >> /root/log.txt

Use strace Tracking script execution , To save space , Just keep some key execution processes :

# strace -q ./test.sh
execve("./test.sh", ["./test.sh"], [/* 35 vars */]) = 0    ## Start script process
......
open("./test.sh", O_RDONLY)             = 3              ## Open the script file
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff37bb77d0) = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
read(3, "#!/usr/bin/env bash\n\necho `date`"..., 80) = 66
lseek(3, 0, SEEK_SET)                   = 0
getrlimit(RLIMIT_NOFILE, {rlim_cur=1024, rlim_max=4*1024}) = 0
fcntl(255, F_GETFD)                     = -1 EBADF (Bad file descriptor)
dup2(3, 255)                            = 255                ## Copy the opened script file descriptor as 255
close(3)                                = 0                       ## Close the opened script file descriptor 3
......
read(255, "#!/usr/bin/env bash\n\necho `date`"..., 66) = 66     ## Read test.sh The script content
.....
open("/root/log.txt", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3  ## perform test.sh The action of opening a log file in a script
....

read(3, "Sun Feb  3 16:15:31 CST 2019\n", 128) = 29  ## obtain date The result of the order
read(3, "", 128)                        = 0
.....
write(1, "Sun Feb 3 15:51:56 CST 2019 hell"..., 41) = 41    ##  perform test.sh The action of writing log file in script
dup2(10, 1)                             = 1
fcntl(10, F_GETFD)                      = 0x1 (flags FD_CLOEXEC)
close(10)                               = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
read(255, "\n", 66)                     = 1
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
read(255, "", 66)                       = 0
exit_group(0)                           = ?    ## sign out shell Script execution , This will close all open file descriptors

ksh Script execution process :

#!/usr/bin/env ksh
echo `date`" hello world!" >> /root/log.txt

strace -q ./test.sh
execve("./test.sh", ["./test.sh"], [/* 35 vars */]) = 0   ## Start script process
......
open("./test.sh", O_RDONLY)             = 3             ## Open the script
fstat(3, {st_mode=S_IFREG|0755, st_size=65, ...}) = 0
fcntl(3, F_DUPFD, 10)                   = 10              ## Copy the descriptor of the script file
close(3)                                = 0                         ## Close the script file

/*

open("./test.sh", O_RDONLY)             = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=65, ...}) = 0
fcntl(3, F_DUPFD, 10)                   = 11   ## Some systems come to the conclusion that 11
close(3)                                = 0
fcntl(11, F_SETFD, FD_CLOEXEC)          = 0

*/
......
read(10, "#!/usr/bin/env ksh\n\necho `date`\""..., 8192) = 65   ## Read the contents of the script file
read(10, "", 8192)                      = 0
brk(0xf09000)                           = 0xf09000       
......
read(3, "Sun Feb  3 16:24:53 CST 2019\n", 8192) = 29   ## obtain date Command content
read(3, "", 8192)                       = 0
close(3)                                = 0
......
write(3, "Sun Feb  3 16:24:53 CST 2019\n", 29) = 29   
......
open("/root/log.txt", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3  ## open the log file
......
write(1, "Sun Feb 3 16:24:53 CST 2019 hell"..., 41) = 41    ## Write a log file
lseek(1, 0, SEEK_CUR)                   = 492
......
exit_group(0)                           = ?             ## sign out shell Script execution , This will close all open file descriptors

perl Script execution process

 #!/usr/bin/env perl
$datestring = localtime();
open(logfile,">>/mnt/newlog3.txt") or die "Cant't open /mnt/newlog3.txt";
print logfile "$datestring hello world! I am Perl!\n";
close(logfile);

# strace /usr/bin/perl ../hello.pl
execve("/usr/bin/perl", ["/usr/bin/perl", "../hello.pl"], [/* 62 vars */]) = 0  ## perform hello.pl Script
......
open("../hello.pl", O_RDONLY)           = 3    ## The following code is open hello.pl Script and read the script content ( Contains script parsing )
......
read(3, "#!/usr/bin/env perl\n\n$datestring"..., 4096) = 194
read(3, "", 4096)                       = 0
close(3)                                = 0            ## Close the already open hello.pl Script
open("/etc/localtime", O_RDONLY)        = 3     ## Open time file , Acquisition time : Corresponding to the third line of the script
fstat(3, {st_mode=S_IFREG|0644, st_size=414, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=414, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb976b7b000
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\0\0\0\3\0\0\0\0"..., 4096) = 414
lseek(3, -249, SEEK_CUR)                = 165
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\0\0\0\3\0\0\0\0"..., 4096) = 249
close(3)                                = 0
munmap(0x7fb976b7b000, 4096)            = 0
open("/mnt/newlog3.txt", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3    ## open the log file   /mnt/newlog3.txt: Corresponding to script No 5 and 6 That's ok
lseek(3, 0, SEEK_END)                   = 389
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7ffd3b444fb0) = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 389
fstat(3, {st_mode=S_IFREG|0644, st_size=389, ...}) = 0
fcntl(3, F_SETFD, FD_CLOEXEC)           = 0
write(3, "Mon Feb 11 18:31:40 2019 hello w"..., 49) = 49
close(3)                                = 0   ## Close log file   /mnt/newlog3.txt
exit_group(0)                           = ?

python Script execution process

 #!/usr/bin/python
import os
import datetime,time with open("/mnt/newlog3.txt", 'a+') as fp:
cur_date=datetime.datetime.now()
cur_date_str=cur_date.strftime("%Y-%m-%d %H:%M:%S")
fp.write("{0} Hello world! I am python!\n".format(cur_date_str))
fp.close()

# strace ./hello.py
execve("./hello.py", ["./hello.py"], [/* 62 vars */]) = 0   ## perform hello.py Script
......
getcwd("/root/liangjs", 4096)           = 14
lstat("/root/liangjs/hello.py", {st_mode=S_IFREG|0750, st_size=263, ...}) = 0
stat("./hello.py", {st_mode=S_IFREG|0750, st_size=263, ...}) = 0
open("./hello.py", O_RDONLY)            = 3                  ## open hello.py Script and parse the python Script
fstat(3, {st_mode=S_IFREG|0750, st_size=263, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f67ad9e8000
fstat(3, {st_mode=S_IFREG|0750, st_size=263, ...}) = 0
lseek(3, 0, SEEK_SET)                   = 0
read(3, "#!/usr/bin/python\n\nimport os\nimp"..., 241) = 241
read(3, "e_str))\n\tfp.close()\n\n\n", 4096) = 22
close(3)                                = 0
munmap(0x7f67ad9e8000, 4096)            = 0
stat("./hello.py", {st_mode=S_IFREG|0750, st_size=263, ...}) = 0
open("./hello.py", O_RDONLY)            = 3
fstat(3, {st_mode=S_IFREG|0750, st_size=263, ...}) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff46f2d390) = -1 ENOTTY (Inappropriate ioctl for device)
fstat(3, {st_mode=S_IFREG|0750, st_size=263, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f67ad9e8000
lseek(3, 0, SEEK_CUR)                   = 0
read(3, "#!/usr/bin/python\n\nimport os\nimp"..., 4096) = 263
lseek(3, 263, SEEK_SET)                 = 263
brk(0x6c7000)                           = 0x6c7000
read(3, "", 4096)                       = 0
brk(0x6be000)                           = 0x6be000
brk(0x6bc000)                           = 0x6bc000
close(3)                                = 0                           ## Close the already open hello.py Script files
munmap(0x7f67ad9e8000, 4096)            = 0
......
open("/etc/localtime", O_RDONLY)        = 4                    ## Get time information
fstat(4, {st_mode=S_IFREG|0644, st_size=414, ...}) = 0
fstat(4, {st_mode=S_IFREG|0644, st_size=414, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f67ad9e8000
read(4, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\0\0\0\3\0\0\0\0"..., 4096) = 414
lseek(4, -249, SEEK_CUR)                = 165
read(4, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\0\0\0\3\0\0\0\0"..., 4096) = 249
close(4)                                = 0
munmap(0x7f67ad9e8000, 4096)            = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=414, ...}) = 0
close(3)                                = 0
open("/mnt/newlog3.txt", O_RDWR|O_CREAT|O_APPEND, 0666) = 3   ## open /mnt/newlog3.txt file : Corresponding to script No 7 That's ok
fstat(3, {st_mode=S_IFREG|0644, st_size=438, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=414, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=438, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f67ad9e8000
write(3, "2019-02-11 18:41:16 Hello world!"..., 46) = 46    ## Write /mnt/newlog3.txt file : Corresponding to script No 10 That's ok
close(3)                                = 0                                        ## close /mnt/newlog3.txt file : Corresponding to script No 11 That's ok
munmap(0x7f67ad9e8000, 4096)            = 0
rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER, 0x7f67ad2ac850}, {0x7f67ad54ed38, [], SA_RESTORER, 0x7f67ad2ac850}, 8) = 0
exit_group(0)                           = ?

From the above analysis ,shell Scripts are executed while parsing , After executing the script , Close the script file ;perl and python Scripts are parsed before execution , Before executing the script ,

Finished parsing the script , Close the script file directly .

How to control perl or python The script does not close the script file when executing the script ? We need to go from perl and python Source code analysis .

perl and python Source code analysis

python Source code analysis execution process

notes : With python-2.7.9 The source code is the analysis blueprint

 /* Main program */
int
Py_Main(int argc, char **argv)
{
......
if (sts==-) {
/* call pending calls like signal handlers (SIGINT) */
if (Py_MakePendingCalls() == -) {
PyErr_Print();
sts = ;
} else {
sts = PyRun_AnyFileExFlags(
fp,
filename == NULL ? "<stdin>" : filename,
filename != NULL, &cf) != ; /* Whether to carry out python The script file is used as the basis for closing the script file */
}
}
......
}
 /* Parse input from a file and execute it */
int
PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit,
PyCompilerFlags *flags)
{
if (filename == NULL)
filename = "???";
if (Py_FdIsInteractive(fp, filename)) { /* Interactive execution python command */
int err = PyRun_InteractiveLoopFlags(fp, filename, flags);
if (closeit)
fclose(fp);
return err;
}
else
return PyRun_SimpleFileExFlags(fp, filename, closeit, flags); /* perform python Script files */
}
PyRun_SimpleFileExFlags call PyRun_FileExFlags function :
 PyObject *
PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals,
PyObject *locals, int closeit, PyCompilerFlags *flags)
{
PyObject *ret;
mod_ty mod;
PyArena *arena = PyArena_New();
if (arena == NULL)
return NULL;
/* Author: analysis python Script files */
mod = PyParser_ASTFromFile(fp, filename, start, , ,
flags, NULL, arena);
if (closeit)
14 fclose(fp); /* After parsing , Close the open python Script files */
if (mod == NULL) {
PyArena_Free(arena);
return NULL;
}
ret = run_mod(mod, filename, globals, locals, flags, arena); /* perform python Script */
PyArena_Free(arena);
return ret;
}

from python Look at the execution process of the script , When python The command passes in a script file , Then analyze it first python The script content , Then close the open script file , Finally, execute python Script .

perl Source code analysis execution process

notes : With perl-5.16.3 The source code is the analysis blueprint

 #ifdef NO_ENV_ARRAY_IN_MAIN
extern char **environ;
int
main(int argc, char **argv) /* in miniperlmain.c */
#else
int
main(int argc, char **argv, char **env)
#endif
{
......
exitstatus = perl_parse(my_perl, xs_init, argc, argv, (char **)NULL); /* do perl Script parsing : S_parse_body function */
if (!exitstatus) {
perl_run(my_perl); /* perform perl Script */
}
......
} #define parse_body(a,b) S_parse_body(aTHX_ a,b)
/* in perl.c */
int
perl_parse(pTHXx_ XSINIT_t xsinit, int argc, char **argv, char **env)
{
......
switch (ret) {
case :
parse_body(env,xsinit); /* Really doing perl The function of script parsing is S_parse_body */
......
break;
......
}
 STATIC void *
S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
{
......
rsfp = open_script(scriptname, dosearch, &suidscript); /* open perl Script files */
if (!rsfp) {
rsfp = PerlIO_stdin();
lex_start_flags = LEX_DONT_CLOSE_RSFP;
} ......
lex_start(linestr_sv, rsfp, lex_start_flags); /* Get ready perl Analysis environment and execution environment , The actual function is Perl_lex_start */
if(linestr_sv)
SvREFCNT_dec(linestr_sv);
......
/* now parse the script */
SETERRNO(,SS_NORMAL);
/* yyparse Function analysis perl Script files , Then close the script : The actual call Perl_lex_next_chunk Function to close the script file */
if (yyparse(GRAMPROG) || PL_parser->error_count) {
if (PL_minus_c)
Perl_croak(aTHX_ "%s had compilation errors.\n", PL_origfilename);
else {
Perl_croak(aTHX_ "Execution of %s aborted due to compilation errors.\n",
PL_origfilename);
}
}
......
}

from perl Look at the execution process of the script , When perl The command passes in a script file , Then analyze it first perl The script content , Then close the open script file , Finally, execute perl Script .

from python and perl Look at the process of source code analysis , There is a parameter in the execution process of both scripts to control the closing mode of scripts . stay python Source code , yes PyRun_FileExFlags Functional closeit Parameters ,

When closeit by 0 yes ,python After script execution , Don't just close the open python Script files . stay perl Source code , yes Perl_lex_start Functional flags Parameters , When flags Parameters include LEX_DONT_CLOSE_RSFP when ,

perl After the script parsing is completed, do not directly close the opened perl Script files .

Source code modification

According to our analysis , Source control can be modified python and perl How scripts are closed . Source code modification method is as follows .

python Source code modification method :

 int
Py_Main(int argc, char **argv)
{
......
int closeit = , RunAnyFileExFlag = ; /* Define whether to close python Script variables */
......
if (sts==-) {
/* call pending calls like signal handlers (SIGINT) */
if (Py_MakePendingCalls() == -) {
fprintf(stderr, "call Py_MakePendingCalls return -1...\n");
PyErr_Print();
sts = ;
} else {
/* closeit decide whether closing python file */
closeit = ;
RunAnyFileExFlag = ;
sts = PyRun_AnyFileExFlags(
fp,
filename == NULL ? "<stdin>" : filename,
closeit /* filename != NULL */, &cf) != ; /* If it's an executed script file , It doesn't close python Script files */
}
}
......
if(RunAnyFileExFlag && !closeit){ /* stay python Close the ones that have been opened before the end python Script files */
fclose(fp);
}
#endif
Py_Finalize();
......
}

perl Source code modification method :

 STATIC void * S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
/* lex_start in , add to LEX_DONT_CLOSE_RSFP Mark */
lex_start(linestr_sv, rsfp, lex_start_flags | LEX_DONT_CLOSE_RSFP);
/* fprintf(stderr,"lex_start end......\n"); */
if(linestr_sv)
SvREFCNT_dec(linestr_sv); The authors note : stay perl After script execution , from PerlIO_destruct When the function finishes perl Closing action of script file !

Test results after modifying the source code

perl Script execution process :

 # strace /root/liangjs/hello.pl
execve("/root/liangjs/hello.pl", ["/root/liangjs/hello.pl"], [/* 34 vars */]) =
....
open("/root/liangjs/hello.pl", O_RDONLY) = ## Open test perl Script files
ioctl(, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffe347e36a0) = - ENOTTY (Inappropriate ioctl for device)
lseek(, , SEEK_CUR) =
fcntl(, F_SETFD, FD_CLOEXEC) =
......
read(, "#!/usr/bin/env perl\n\n$datestring"..., ) = ## Read perl Script file content and parse
read(, "", ) = ## Not closing perl Script files
......
open("/etc/localtime", O_RDONLY|O_CLOEXEC) = ## Get time information
....
open("/mnt/newlog3.txt", O_WRONLY|O_CREAT|O_APPEND, ) =
lseek(, , SEEK_END) =
ioctl(, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffe347e3540) = - ENOTTY (Inappropriate ioctl for device)
lseek(, , SEEK_CUR) =
fstat(, {st_mode=S_IFREG|, st_size=, ...}) =
fcntl(, F_SETFD, FD_CLOEXEC) =
brk() = 0xf88000
brk(0xfaa000) = 0xfaa000
write(, "Wed Feb 20 20:05:18 2019 hello w"..., ) = ## Write a log file /mnt/newlog3.txt
close() = ## Close log file /mnt/newlog3.txt
........
write(, "call PerlIO_destruct......\n", 27call PerlIO_destruct......
) =
close() = ## Close the already open perl Script files
exit_group() = ?
+++ exited with +++

python Script execution process :

 stat("/root/liangjs/py_hello.py", {st_mode=S_IFREG|, st_size=, ...}) =
open("/root/liangjs/py_hello.py", O_RDONLY) =
fstat(, {st_mode=S_IFREG|, st_size=, ...}) =
mmap(NULL, , PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -, ) = 0x7f8830aa9000
fstat(, {st_mode=S_IFREG|, st_size=, ...}) =
lseek(, , SEEK_SET) =
read(, "#!/usr/bin/env python\n\nimport os"..., ) =
read(, "t/newlog3.txt\", 0644)\n", ) =
close() = ## The first time python Close after script file !!!
munmap(0x7f8830aa9000, ) =
stat("/root/liangjs/py_hello.py", {st_mode=S_IFREG|, st_size=, ...}) =
write(, "second open python script file.."..., 34second open python script file...
) =
open("/root/liangjs/py_hello.py", O_RDONLY) =
fstat(, {st_mode=S_IFREG|, st_size=, ...}) =
write(, "call PyRun_AnyFileExFlags...\n", 29call PyRun_AnyFileExFlags...
) =
ioctl(, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd9da9be30) = - ENOTTY (Inappropriate ioctl for device)
brk() = 0x1a9e000
brk(0x1ac0000) = 0x1ac0000
fstat(, {st_mode=S_IFREG|, st_size=, ...}) =
mmap(NULL, , PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -, ) = 0x7f8830aa9000
read(, "#!/usr/bin/env python\n\nimport os"..., ) =
stat("/etc/sysconfig/64bit_strstr_via_64bit_strstr_sse2_unaligned", 0x7ffd9da9bb10) = - ENOENT (No such file or directory)
read(, "", ) = ## Open it for the second time python There is no closing action after the script file !!!
.....
write(, "close python file, RunAnyFileExF"..., 53close python file, RunAnyFileExFlag = , closeit =
) =
close() = ## Finally, close the open python Script files
munmap(0x7f8830aa9000, ) =
rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER, 0x7f8830743370}, {0x4fe640, [], SA_RESTORER, 0x7f8830743370}, ) =
exit_group() = ?
+++ exited with +++

modify python and perl After the source , From the above execution process , All at the end of the execution python and perl Close the script file after the script .

It shows that this modification is in line with our control perl and python The expected closing time of the script file !

Further work

The default action is still resolved perl and python After script , Close the script file directly ; You can add script execution parameters , Control whether the script file is closed after parsing .

Related issues

stay perl In the lower version , for example perl-5.10.0 edition ,yy_parser There is no... In the structure lex_flags member , So we need to control the closing of script file , You need to add appropriate members and control processes .

Perl-5.10.0 Version source code modification

parser.h file

 typedef struct yy_parser {
/* parser state */
struct yy_parser *old_parser; /* previous value of PL_parser */
......
char tokenbuf[];
/* 2018-11-14, with no close file */
U8 lex_flags;
} yy_parser;

toke.c file :

 void
Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, bool new_filter)
{
......
parser->copline = NOLINE;
parser->lex_state = LEX_NORMAL;
parser->expect = XSTATE;
parser->rsfp = rsfp;
parser->rsfp_filters = (new_filter || !oparser) ? newAV()
: (AV*)SvREFCNT_inc(oparser->rsfp_filters);
/* add 2018-11-14, for no closefile */
parser->lex_flags = LEX_DONT_CLOSE_RSFP; Newx(parser->lex_brackstack, , char);
Newx(parser->lex_casestack, , char);
*parser->lex_casestack = '\0';
......
}
 /* delete a parser object */
void
Perl_parser_free(pTHX_ const yy_parser *parser)
{
PL_curcop = parser->saved_curcop;
SvREFCNT_dec(parser->linestr); /* modi 2018-11-14, with no close file */
if ( parser->rsfp == PerlIO_stdin() || (parser->lex_flags & LEX_DONT_CLOSE_RSFP) )
PerlIO_clearerr(parser->rsfp);
else if (parser->rsfp && parser->old_parser
&& parser->rsfp != parser->old_parser->rsfp)
PerlIO_close(parser->rsfp);
SvREFCNT_dec(parser->rsfp_filters); Safefree(parser->stack);
Safefree(parser->lex_brackstack);
Safefree(parser->lex_casestack);
PL_parser = parser->old_parser;
Safefree(parser);
}
 STATIC char *
S_skipspace(pTHX_ register char *s)
{
...... if (PL_preprocess && !PL_in_eval)
(void)PerlProc_pclose(PL_rsfp);
else if ((PerlIO*)PL_rsfp == PerlIO_stdin() || (PL_parser->lex_flags & LEX_DONT_CLOSE_RSFP) )
/* modi 2018-11-14, with no close file */
PerlIO_clearerr(PL_rsfp);
else
(void)PerlIO_close(PL_rsfp);
PL_rsfp = NULL;
return s;
} /* not at end of file, so we only read another line */
/* make corresponding updates to old pointers, for yyerror() */
oldprevlen = PL_oldbufptr - PL_bufend
......
} }
 int
Perl_yylex(pTHX)
{
......
do {
bof = PL_rsfp ? TRUE : FALSE;
if ((s = filter_gets(PL_linestr, PL_rsfp, )) == NULL) {
fake_eof:
#ifdef PERL_MAD
PL_realtokenstart = -;
#endif
if (PL_rsfp) {
if (PL_preprocess && !PL_in_eval)
(void)PerlProc_pclose(PL_rsfp);
else if ((PerlIO *)PL_rsfp == PerlIO_stdin() || (PL_parser->lex_flags & LEX_DONT_CLOSE_RSFP) )
/* modi 2018-11-14, with no close */
PerlIO_clearerr(PL_rsfp);
else
(void)PerlIO_close(PL_rsfp);
PL_rsfp = NULL;
PL_doextract = FALSE;
}
...... }

PS: Your support is a great encouragement to bloggers , Thank you for your careful reading .
       
The copyright of this article belongs to the author , Welcome to reprint , However, this statement must be retained without the consent of the author , And in the article page obvious position gives the original link , Otherwise, the right to pursue legal responsibility is reserved .

【 original 】 control perl and python More related articles on the method of closing script files during script execution

  1. android Simulator (genymotion)+appium+python Questions and answers during the implementation of the framework

    1.case Chinese input is not included in the operation process ? answer : matters needing attention 1) The system code needs to be changed to utf-8, To solve the problem of Chinese input ,case Execute the entry file and add the code as follows : import sys reload(sys) sys. ...

  2. Linux The solution to the loss of kernel files during system startup

    stay /boot There are two important files in the directory , Namely : vmlinuz-3.10.0-123.el7.x86_64         Kernel files initamfs-3.10.0-123.el7.x86_64.img ...

  3. shell Script programming variables introduction and script execution process

    Introduction to script variables Variable type : Character . Numerical type . really . false : Determine the storage format and length of data in advance : Variables are stored in memory space : Compiler language , No additional processing logic , It's a strongly typed language : Scripting languages , There can be interpreter controls : therefore , It can be a weak type ...

  4. Linux Script execution redirection

    Linux Script execution redirection One .bash Debug script , And redirect the execution process to the specified file bash –x  shell.sh 2>&1 | tee shell.log

  5. SQL SERVER 2008: Internal query processor error : The query processor encountered an unexpected error during execution

       Today, a colleague suddenly told me , The one who used to run normally SQL sentence , The following error is reported suddenly during execution :         news 1222, Level 16, state 18, The first 1 That's ok         Lock request timeout period exceeded .        ...

  6. Deepin Next phpunit install , And the problems encountered in the implementation process

    Deepin Next phpunit install , And the problems encountered in the implementation process install phpunit step wget https://phar.phpunit.de/phpunit.phar chmod +x phpuni ...

  7. Selenium2 Study -018-WebUI Real examples of Automation -016- Login verification code problem in the process of automatic script writing

    Everyday Web In the process of website development , To improve login security or prevent users from scalping through scripts ( The most expensive iron sheet in the universe is in the bidding of motor vehicle license plate in Mordor city of China ), Many websites log in , Added captcha verification , And the implementation of captcha is more and more complex , It's a foot ...

  8. python Execute multiple... In sequence py file

    python Execute multiple... In sequence py file If I want to execute code In the catalog python Program , Suppose that there is 1.py,2.py,3.py,4.py Four files , But I want to execute 1.py,2.py,4.py, You can create ...

  9. Python Use Mysql Some mistakes in the process

    Python Use Mysql Some mistakes in the process ssh Log on to the remote server ssh ubuntu@xxx.xxx.xx.xx First of all :ubuntu Login in the terminal Mysql mysql -uroot -p Then enter the password, that is ...

Random recommendation

  1. Redis(li)

    One .Redis Basic introduction redis It's a key-value The storage system . and Memcached similar , It supports storage value There are more types , Include string( character string ).list( Linked list ).set( aggregate ).zset ...

  2. EXT Grid Expand all rows by default

    grid.getStore().load({ // Expand all rows by default . callback:function() { var expander = grid.plugins[0]; var count = ...

  3. Black horse programmer ——OC Language Foundation frame (2) NSArray NSSet NSDictionary\NSMutableDictionary

    Java train .Android train .iOS train ..Net train . Looking forward to communicating with you ! ( The following is a summary of the personal knowledge of the entrance video of black horse apple ) ( One )NSArray 1>NSArray : Immutable arrays ① Create method ...

  4. 【 String sort 】n The minimum or maximum multi bit integer is obtained by connecting the number of integers

    subject describe : Equipped with n A positive integer , Connect them in a row in turn , Make up a multi bit number , Now, what is the largest number of possible multi bits ? for example :n=3 when ,3 It's an integer 13,312,343 The maximum number of multiple bits in a join is :343-312-13. ...

  5. [POJ1050]To the Max( Maximum submatrix ,DP)

    Topic link :http://poj.org/problem?id=1050 I found that there was no solution to the problem , Now make it up , It's a classic idea . The idea is to enumerate all the consecutive rows , such as 1 2 3 4 12 23 34 45 ...

  6. Uva 10382 ( Interval coverage ) Watering Grass

    and Uva 10020 It's almost the same , But here we need to transform the circular area into a strip area that can be covered ( A little Pythagorean Theorem ) Learn someone else's code , Practice using STL Of vector Containers Here's a tip , With a tiny amount EPS To make up for ...

  7. SOCI、LiteSQL、POCO Database access class library comparison

    I'm doing video development recently , The video device is connected to the management server . Streaming media management server . The central server involves the operation of the database , At the same time, you need to be compatible with most versions of the database , Include mysql.sqlite.oracle. The company used to use ado ...

  8. B. Qualifying Contest

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  9. locust Parameters , Data explanation

    Parameters      explain -h, –help     view help -H HOST, –host=HOST     Specify the host to be tested , In the form of :http://10.21.32.33–web-host=WEB_HOST  ...

  10. P1052 Cross the river

    A good problem of dynamic programming State transition is simple ,dp[i] = dp[i-k] + st[i] ,k It's moving distance ,st[i] Judge i Is there a stone in the position , But it's too far away , Need to compress path . K∈[1,10],lcm[1,10] = ...