summaryrefslogtreecommitdiff
path: root/doio.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix a bunch of repeated-word typosDagfinn Ilmari Mannsåker2020-05-221-1/+1
| | | | | Mostly in comments and docs, but some in diagnostic messages and one case of 'or die die'.
* Remove spurious double spaces before open braces in core C codeDagfinn Ilmari Mannsåker2020-04-131-1/+1
|
* doio.c: Use inRANGE macroKarl Williamson2019-12-261-1/+1
|
* Add memCHRs() macro and use itKarl Williamson2019-12-181-1/+1
| | | | | | | This replaces strchr("list", c) calls throughout the core. They don't work properly when 'c' is a NUL, returning the position of the terminating NUL in "list" instead of failure. This could lead to segfaults or even security issues.
* (perl #134221) support append mode for open .. undefTony Cook2019-07-161-0/+15
|
* (perl #122112) a simpler fix for pclose() aborted by a signalTony Cook2019-05-301-1/+11
| | | | | | | | | | | | | | | | | | This change results in a zombie child process for the lifetime of the process, but I think that's the responsibility of the signal handler that aborted pclose(). We could add some magic to retry (and retry and retry) waiting on child process as we rewind (since there's no other way to remove the zombie), but the program has chosen implicitly to abort the wait() done by pclose() and it's best to honor that. If we do choose to retry the wait() we might be blocking an attempt by the process to terminate, whether by exit() or die(). If a program does need more flexible handling there's always pipe()/fork()/exec() and/or the various event-driven frameworks on CPAN.
* foo_cloexec() under PERL_GLOBAL_STRUCT_PRIVATEDavid Mitchell2019-02-191-10/+29
| | | | | | | | | | | | | | | | | | Fix the various Perl_PerlSock_dup2_cloexec() type functions so that t/porting/liberl.a passes under -DPERL_GLOBAL_STRUCT_PRIVATE builds. In these builds it is forbidden to have any static variables, but each of these functions (via convoluted macros) has a static var called 'strategy' which records, for each function, whether a run-time probe has been done to determine the best way of achieving close-exec functionality, and the result. Replace them all with 'global' vars: PL_strategy_dup2 etc. NB these vars aren't thread-safe but it doesn't really matter, as the worst that can happen is for a redundant probe or two to be done before a suitable "don't probe any more" value is written to the var and seen by all the threads.
* (perl #133659) make an in-place edit successful if the exit status is zeroTony Cook2018-11-261-20/+25
| | | | | | | | | | | | | | | | | | | during global destruction. This means that code like: perl -i -ne '...; last' will replace the input file with the in-place edit output of the file, but: perl -i -ne '...; die' or perl -i -ne '...; exit 1' won't.
* (perl #133659) move argvout cleanup to a new functionTony Cook2018-11-261-24/+38
|
* Also work around renameat() kernel bug on GNU/kFreeBSDJames Clarke2018-11-201-2/+2
|
* Use sv_catpvs where appropriate vs sv_catpvKarl Williamson2018-08-061-5/+5
| | | | | This moves calculations definitely to compile time; some optimizing compilers may already do this, but some may not.
* (perl #133314) always close the directory handle on clean upTony Cook2018-08-011-25/+31
| | | | | | | | Previously the directory handle was only closed if the rest of the magic free clean up is done, but in most success cases that code doesn't run, leaking the directory handle. So always close the directory if our AV is available.
* Revert "Revert "make PerlIO handle FD_CLOEXEC""Zefram2018-01-181-27/+23
| | | | | | This reverts commit 523d71b314dc75bd212794cc8392eab8267ea744, reinstating commit 2cdf406af42834c46ef407517daab0734f7066fc. Reversion is not the way to address the porting problem that motivated that reversion.
* Revert "make PerlIO handle FD_CLOEXEC"Abigail2018-01-181-23/+27
| | | | | | | | | | | | | | | | | | | | | This reverts commit 2cdf406af42834c46ef407517daab0734f7066fc. The reason for the revert is that with this commit, perl fails to compile on darwin (or at least, one some versions of it): ./miniperl -Ilib make_ext.pl lib/auto/DB_File/DB_File.bundle MAKE="/Applications/Xcode.app/Contents/Developer/usr/bin/make" LIBPERL_A=libperl.a LINKTYPE=dynamic Parsing config.in... Looks Good. dyld: lazy symbol binding failed: Symbol not found: _mkostemp Referenced from: /private/tmp/perl/cpan/DB_File/../../miniperl Expected in: flat namespace dyld: Symbol not found: _mkostemp Referenced from: /private/tmp/perl/cpan/DB_File/../../miniperl Expected in: flat namespace Unsuccessful Makefile.PL(cpan/DB_File): code=5 at make_ext.pl line 518. make: *** [lib/auto/DB_File/DB_File.bundle] Error 2
* make PerlIO handle FD_CLOEXECZefram2017-12-221-27/+23
| | | | | | Move handling of close-on-exec flag for PerlIO handles into PerlIO itself. Where PerlIO opens new file descriptors, have them opened in O_CLOEXEC mode where possible.
* Perl_my_mkstemp_cloexec() functionZefram2017-12-221-2/+15
| | | | | | Like the other "_cloexec" I/O functions, this guarantees to return a file descriptor with FD_CLOEXEC set, and will set the flag atomically if possible.
* factor out remaining fcntl F_SETFD callsZefram2017-12-221-5/+3
|
* set FD_CLOEXEC atomically in easy casesZefram2017-12-221-18/+39
| | | | | | | In many places where a file descriptor is being opened, open it with FD_CLOEXEC already set if possible. This commit covers the easy cases, where the file descriptor arises without the use of PerlIO, pp_open, or my_popen.
* *_cloexec() I/O functionsZefram2017-12-221-0/+214
| | | | | | | | | | | | | | | | | New functions PerlLIO_dup_cloexec(), PerlLIO_dup2_cloexec(), PerlLIO_open_cloexec(), PerlLIO_open3_cloexec(), PerlProc_pipe_cloexec(), PerlSock_socket_cloexec(), PerlSock_accept_cloexec(), and PerlSock_socketpair_cloexec() each do the same thing as their "_cloexec"-less counterpart, but return with the FD_CLOEXEC flag set on each new file descriptor. They set the flag atomically as part of the file descriptor creation syscall where possible, but will fall back to setting it separately from creation where necessary. In all cases, setting the flag atomically depends not only on the correct syscall interface being defined, but on it being actually implemented in the runtime kernel. Each function will experiment to see whether the atomic flag setting actually works, and is prepared for the flag to cause EINVAL or ENOSYS or to be ignored.
* semicolon-friendly diagnostic controlZefram2017-12-161-6/+6
| | | | | | New macros {GCC,CLANG}_DIAG_{IGNORE,RESTORE}_{DECL,STMT}, which take a following semicolon. It is necessary to use the _DECL or _STMT version as appropriate to the context. Fixes [perl #130726].
* make exec keep its argument list more reliablyZefram2017-12-141-40/+37
| | | | | | | | | | Bits of exec code were putting the constructed commands into globals PL_Argv and PL_Cmd, which could then be clobbered by reentrancy. These are only global in order to manage their freeing, but that's better managed by using the scope stack. So replace them with automatic variables, with ENTER/SAVEFREEPV/LEAVE to free the memory. Also copy the strings acquired from SVs, to avoid magic clobbering the buffers of SVs already read. Fixes [perl #129888].
* (perl #132506) finish the correction to dir_unchanged()Tony Cook2017-12-011-3/+4
| | | | and adjust the error message for renaming the work file
* Fix Windows build following commit 184f90dc41Steve Hay2017-11-301-1/+1
| | | | But t/run/switches.t test 131 still fails, with perl.exe crashing.
* (perl #132506) remove an unneeded argumentTony Cook2017-11-301-8/+8
|
* (perl #132506) deal with un-/partly implemented *at() functionsTony Cook2017-11-301-55/+100
| | | | | | | | | | | | NetBSD 6 provides renameat() etc in it's libc, but in the cases where we use them they fail with ENOSYS. So I've modified the in-place edit clean up code to attempt to fallback to the non-at versions of these functions, after checking that the current directory is sane. Once I was sure that worked, since the *at() functions don't work for my use case on NetBSD 6, I've disabled them in hints.
* Initialize variables.Jarkko Hietaniemi2017-11-291-0/+2
| | | | Coverity #169257, #169265, #169269.
* Set safer umask for mkstemp().Jarkko Hietaniemi2017-11-291-1/+5
| | | | Coverity #169258.
* set $! when statting a closed filehandleZefram2017-11-151-1/+9
| | | | | | | When a stat fails because it's on a closed or otherwise invalid filehandle, $! was often not being set, depending on the operation and the nature of the invalidity. Consistently set it to EBADF. Fixes [perl #108288].
* doio.c: Change strchr to memchrKarl Williamson2017-11-061-2/+2
| | | | | This allows things to work properly in the face of embedded NULs. See the branch merge message for more information.
* Rename strEQs to strBEGINs; remove strNEsKarl Williamson2017-11-061-2/+2
| | | | | | | | | | The original names are confusing. See thread beginning with http://nntp.perl.org/group/perl.perl5.porters/244335 The two macros are mapped into just that one, complementing the result for the few cases where strNEs was used.
* (perl #131895) fail stat on names with \0 embeddedTony Cook2017-11-021-5/+16
| | | | Also lstat() and the file test ops.
* Revert "vms/vmsish.h: move a function declaration from doio.c"Craig A. Berry2017-10-251-0/+5
| | | | | | | | | | | This reverts commit d4bd48023fe0ba950fface5aa859b6852aa29fc4. perlio.h depends on vmsish.h and comes in (via iperlsys.h) about a thousand lines later in perl.h. So we can't put a prototype that uses PerlIO in vmsish.h Maybe there is a way to get that prototype out of doio.c, but this isn't it.
* doio.c: simplify cpp conditionalsAaron Crane2017-10-211-21/+13
|
* vms/vmsish.h: move a function declaration from doio.cAaron Crane2017-10-211-5/+0
|
* [perl #131730] Fix exec PROGRAM LIST with empty LISTDagfinn Ilmari Mannsåker2017-10-181-5/+8
| | | | | | | | | | | | | | | | | This should call execvp() with an empty argv array (containing only the terminating NULL pointer), but was instead just returning false (and not setting $!). Executing a program with an empty argv array is valid ISO C: it merely requires argc to be nonnegative and argv[argc] to be NULL. POSIX states that that argv[0] "should point to a filename string that is associated with the process being started", but "should" only applies to applications claiming strict POSIX conformance. Perl does not, and certainly should not impose it on perl programs. This also requires handling the case where both PROGRAM and LIST are empty, to avoid calling execvp(NULL, …), which _is_ invalid. I've made it return ENOENT, which it the error POSIX specifies for execvp("", …).
* Make use of *at functions dependent upon HAS_LINKAT.James E Keenan2017-09-181-1/+2
| | | | | | As suggested by Zefram. For: RT #132087.
* (perl #127663) work around what appears to be a freebsd bugTony Cook2017-09-181-2/+26
| | | | | renameat() on FreeBSD 11 fails if the paths supplied are absolute paths.
* (perl #127663) fallback to looking for work file if st_ino unusableTony Cook2017-09-111-10/+32
|
* (perl #127663) reject a changed directory for relative in-place filenamesTony Cook2017-09-111-0/+36
| | | | | based in the inode/device numbers when we don't have the *at() functions.
* (perl #127663) test we fail if the work file can't be renamedTony Cook2017-09-111-0/+6
| | | | and ensure we (attempt to) clean up the work file
* (perl #127663) test we fail if the backup rename failsTony Cook2017-09-111-0/+5
| | | | and that we clean up the temp file
* (perl #127663) don't do inplace renaming etc in child processesTony Cook2017-09-111-17/+40
| | | | | | | | | | This avoids trying to rename the work file over the original multiple times, which could make the implicit (or explicit) close fail. This is an incompatibility with the pre-workfile version of in-place editing, since you could previously fork a child to do process a given file, but hopefully this is a rare case.
* (perl #127663) don't do inplace renaming etc in child threadsTony Cook2017-09-111-5/+20
| | | | This also avoids double closedir()ing the directory handle.
* (perl #127663) use *at() functions to handle perl code that chdirsTony Cook2017-09-111-2/+60
| | | | | | Unfortunately this means systems that don't have the *at() functions aren't protected from code that chdir()s in the middle of in-place editing a file.
* (perl #127663) discard any output if not closed properlyTony Cook2017-09-111-5/+14
| | | | | It can be closed by either iterating to the next file, or by an explicit close(ARGVOUT);
* (perl #127663) safer in-place editingTony Cook2017-09-111-83/+225
| | | | | | | | | | | | Previously in-place editing opened the file then immediately *replaced* the file, so if an error occurs while writing the output, such as running out of space, the content of the original file is lost. This changes in-place editing to write to a work file which is renamed over the original only once the output file is successfully closed. It also fixes an issue with setting setuid/setgid file modes for recursive in-place editing.
* Eliminate remaining uses of PL_statbufDagfinn Ilmari Mannsåker2017-06-011-23/+28
| | | | | | | | | | Give Perl_nextargv its own statbuf and pass a pointer to it into Perl_do_open_raw and thence S_openn_cleanup when needed. Also reduce the scope of the existing statbuf in Perl_nextargv to make it clear it's distinct from the one populated by do_open_raw. Fix perldelta entry for PL_statbuf removal
* Coverity #28930: unchecked return valueJarkko Hietaniemi2017-02-101-1/+5
| | | | | Strangely, this was apparently found already in 2014, but it now (rightfully) showed up. Coverity database tweak?
* Use cBOOL() instead of ? TRUE : FALSEDagfinn Ilmari Mannsåker2017-01-251-1/+1
| | | | Except under cpan/ and dist/
* Remove obsolete (PL_)statcache mentions in commentsDagfinn Ilmari Mannsåker2017-01-181-1/+1
| | | | cando() has not used PL_statcache since Perl 3 (commit a687059cbaf)