summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZefram <zefram@fysh.org>2017-12-19 19:00:07 +0000
committerZefram <zefram@fysh.org>2017-12-22 16:30:12 +0000
commit1cdb2692fbfca71c0b0f3302f522f6dc1f460664 (patch)
treed8dc5d8753afa27d5b1e28737cf9aeb68642d3be
parentd333cbeb476c54aaf8f85ffdcfc187f23b4ea2ee (diff)
downloadperl-1cdb2692fbfca71c0b0f3302f522f6dc1f460664.tar.gz
Perl_my_mkstemp_cloexec() function
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.
-rw-r--r--doio.c17
-rw-r--r--embed.fnc5
-rw-r--r--embed.h4
-rw-r--r--proto.h9
4 files changed, 27 insertions, 8 deletions
diff --git a/doio.c b/doio.c
index 56615cdd90..d18e335a04 100644
--- a/doio.c
+++ b/doio.c
@@ -61,7 +61,7 @@
#include <signal.h>
void
-Perl_setfd_cloexec(pTHX_ int fd)
+Perl_setfd_cloexec(int fd)
{
assert(fd >= 0);
#if defined(HAS_FCNTL) && defined(F_SETFD) && defined(FD_CLOEXEC)
@@ -70,7 +70,7 @@ Perl_setfd_cloexec(pTHX_ int fd)
}
void
-Perl_setfd_inhexec(pTHX_ int fd)
+Perl_setfd_inhexec(int fd)
{
assert(fd >= 0);
#if defined(HAS_FCNTL) && defined(F_SETFD) && defined(FD_CLOEXEC)
@@ -221,6 +221,19 @@ Perl_PerlLIO_open3_cloexec(pTHX_ const char *file, int flag, int perm)
#endif
}
+int
+Perl_my_mkstemp_cloexec(char *templte)
+{
+ PERL_ARGS_ASSERT_MY_MKSTEMP_CLOEXEC;
+#if defined(O_CLOEXEC)
+ DO_ONEOPEN_EXPERIMENTING_CLOEXEC(
+ Perl_my_mkostemp(templte, O_CLOEXEC),
+ Perl_my_mkstemp(templte));
+#else
+ DO_ONEOPEN_THEN_CLOEXEC(Perl_my_mkstemp(templte));
+#endif
+}
+
#ifdef HAS_PIPE
int
Perl_PerlProc_pipe_cloexec(pTHX_ int *pipefd)
diff --git a/embed.fnc b/embed.fnc
index ac36719c45..581b6c8ae7 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -464,13 +464,14 @@ Apmb |bool |do_open |NN GV* gv|NN const char* name|I32 len|int as_raw \
Ap |bool |do_open9 |NN GV *gv|NN const char *name|I32 len|int as_raw \
|int rawmode|int rawperm|NULLOK PerlIO *supplied_fp \
|NN SV *svs|I32 num
-p |void |setfd_cloexec|int fd
-p |void |setfd_inhexec|int fd
+pn |void |setfd_cloexec|int fd
+pn |void |setfd_inhexec|int fd
p |void |setfd_inhexec_for_sysfd|int fd
pR |int |PerlLIO_dup_cloexec|int oldfd
pR |int |PerlLIO_dup2_cloexec|int oldfd|int newfd
pR |int |PerlLIO_open_cloexec|NN const char *file|int flag
pR |int |PerlLIO_open3_cloexec|NN const char *file|int flag|int perm
+pnoR |int |my_mkstemp_cloexec|NN char *templte
#ifdef HAS_PIPE
pR |int |PerlProc_pipe_cloexec|NN int *pipefd
#endif
diff --git a/embed.h b/embed.h
index 6441f389f7..bffd52957f 100644
--- a/embed.h
+++ b/embed.h
@@ -1382,8 +1382,8 @@
#define set_caret_X() Perl_set_caret_X(aTHX)
#define set_numeric_standard() Perl_set_numeric_standard(aTHX)
#define set_numeric_underlying() Perl_set_numeric_underlying(aTHX)
-#define setfd_cloexec(a) Perl_setfd_cloexec(aTHX_ a)
-#define setfd_inhexec(a) Perl_setfd_inhexec(aTHX_ a)
+#define setfd_cloexec Perl_setfd_cloexec
+#define setfd_inhexec Perl_setfd_inhexec
#define setfd_inhexec_for_sysfd(a) Perl_setfd_inhexec_for_sysfd(aTHX_ a)
#define sub_crush_depth(a) Perl_sub_crush_depth(aTHX_ a)
#define sv_2num(a) Perl_sv_2num(aTHX_ a)
diff --git a/proto.h b/proto.h
index 1ae6c12a9b..2c87e88bff 100644
--- a/proto.h
+++ b/proto.h
@@ -2094,6 +2094,11 @@ PERL_CALLCONV Pid_t Perl_my_fork(void);
PERL_CALLCONV I32 Perl_my_lstat(pTHX);
#endif
PERL_CALLCONV I32 Perl_my_lstat_flags(pTHX_ const U32 flags);
+PERL_CALLCONV int Perl_my_mkstemp_cloexec(char *templte)
+ __attribute__warn_unused_result__;
+#define PERL_ARGS_ASSERT_MY_MKSTEMP_CLOEXEC \
+ assert(templte)
+
PERL_CALLCONV PerlIO* Perl_my_popen_list(pTHX_ const char* mode, int n, SV ** args);
#define PERL_ARGS_ASSERT_MY_POPEN_LIST \
assert(mode); assert(args)
@@ -2928,8 +2933,8 @@ PERL_CALLCONV void Perl_set_numeric_underlying(pTHX);
PERL_CALLCONV void Perl_setdefout(pTHX_ GV* gv);
#define PERL_ARGS_ASSERT_SETDEFOUT \
assert(gv)
-PERL_CALLCONV void Perl_setfd_cloexec(pTHX_ int fd);
-PERL_CALLCONV void Perl_setfd_inhexec(pTHX_ int fd);
+PERL_CALLCONV void Perl_setfd_cloexec(int fd);
+PERL_CALLCONV void Perl_setfd_inhexec(int fd);
PERL_CALLCONV void Perl_setfd_inhexec_for_sysfd(pTHX_ int fd);
PERL_CALLCONV char* Perl_setlocale(int category, const char* locale);
PERL_CALLCONV HEK* Perl_share_hek(pTHX_ const char* str, SSize_t len, U32 hash);