@@ -112,11 +112,10 @@ Perl_setfd_cloexec_or_inhexec_by_sysfdness(pTHX_ int fd)
112
112
} while(0)
113
113
#if defined(HAS_FCNTL ) && defined(F_SETFD ) && defined(FD_CLOEXEC ) && \
114
114
defined(F_GETFD )
115
- enum { CLOEXEC_EXPERIMENT , CLOEXEC_AT_OPEN , CLOEXEC_AFTER_OPEN };
116
- # define DO_GENOPEN_EXPERIMENTING_CLOEXEC (TESTFD , GENOPEN_CLOEXEC , \
115
+ enum { CLOEXEC_EXPERIMENT = 0 , CLOEXEC_AT_OPEN , CLOEXEC_AFTER_OPEN };
116
+ # define DO_GENOPEN_EXPERIMENTING_CLOEXEC (strategy , TESTFD , GENOPEN_CLOEXEC , \
117
117
GENOPEN_NORMAL , GENSETFD_CLOEXEC ) \
118
118
do { \
119
- static int strategy = CLOEXEC_EXPERIMENT; \
120
119
switch (strategy) { \
121
120
case CLOEXEC_EXPERIMENT: default: { \
122
121
int res = (GENOPEN_CLOEXEC), eno; \
@@ -149,7 +148,7 @@ enum { CLOEXEC_EXPERIMENT, CLOEXEC_AT_OPEN, CLOEXEC_AFTER_OPEN };
149
148
} \
150
149
} while(0)
151
150
#else
152
- # define DO_GENOPEN_EXPERIMENTING_CLOEXEC (TESTFD , GENOPEN_CLOEXEC , \
151
+ # define DO_GENOPEN_EXPERIMENTING_CLOEXEC (strategy , TESTFD , GENOPEN_CLOEXEC , \
153
152
GENOPEN_NORMAL , GENSETFD_CLOEXEC ) \
154
153
DO_GENOPEN_THEN_CLOEXEC(GENOPEN_NORMAL, GENSETFD_CLOEXEC)
155
154
#endif
@@ -160,10 +159,13 @@ enum { CLOEXEC_EXPERIMENT, CLOEXEC_AT_OPEN, CLOEXEC_AFTER_OPEN };
160
159
DO_GENOPEN_THEN_CLOEXEC(fd = (ONEOPEN_NORMAL), \
161
160
setfd_cloexec(fd)); \
162
161
} while(0)
163
- #define DO_ONEOPEN_EXPERIMENTING_CLOEXEC (ONEOPEN_CLOEXEC , ONEOPEN_NORMAL ) \
162
+ #define DO_ONEOPEN_EXPERIMENTING_CLOEXEC (strategy , \
163
+ ONEOPEN_CLOEXEC , ONEOPEN_NORMAL ) \
164
164
do { \
165
165
int fd; \
166
- DO_GENOPEN_EXPERIMENTING_CLOEXEC(fd, fd = (ONEOPEN_CLOEXEC), \
166
+ DO_GENOPEN_EXPERIMENTING_CLOEXEC(strategy, \
167
+ fd, \
168
+ fd = (ONEOPEN_CLOEXEC), \
167
169
fd = (ONEOPEN_NORMAL), setfd_cloexec(fd)); \
168
170
} while(0)
169
171
@@ -174,9 +176,10 @@ enum { CLOEXEC_EXPERIMENT, CLOEXEC_AT_OPEN, CLOEXEC_AFTER_OPEN };
174
176
} while(0)
175
177
#define DO_PIPEOPEN_THEN_CLOEXEC (PIPEFD , PIPEOPEN_NORMAL ) \
176
178
DO_GENOPEN_THEN_CLOEXEC(PIPEOPEN_NORMAL, DO_PIPESETFD_CLOEXEC(PIPEFD))
177
- #define DO_PIPEOPEN_EXPERIMENTING_CLOEXEC (PIPEFD , PIPEOPEN_CLOEXEC , \
179
+ #define DO_PIPEOPEN_EXPERIMENTING_CLOEXEC (strategy , PIPEFD , PIPEOPEN_CLOEXEC , \
178
180
PIPEOPEN_NORMAL ) \
179
- DO_GENOPEN_EXPERIMENTING_CLOEXEC((PIPEFD)[0], PIPEOPEN_CLOEXEC, \
181
+ DO_GENOPEN_EXPERIMENTING_CLOEXEC(strategy, \
182
+ (PIPEFD)[0], PIPEOPEN_CLOEXEC, \
180
183
PIPEOPEN_NORMAL, DO_PIPESETFD_CLOEXEC(PIPEFD))
181
184
182
185
int
@@ -188,7 +191,9 @@ Perl_PerlLIO_dup_cloexec(pTHX_ int oldfd)
188
191
* to extend it, so for the time being this just isn't available on
189
192
* PERL_IMPLICIT_SYS builds.
190
193
*/
194
+ dVAR ;
191
195
DO_ONEOPEN_EXPERIMENTING_CLOEXEC (
196
+ PL_strategy_dup ,
192
197
fcntl (oldfd , F_DUPFD_CLOEXEC , 0 ),
193
198
PerlLIO_dup (oldfd ));
194
199
#else
@@ -205,7 +210,9 @@ Perl_PerlLIO_dup2_cloexec(pTHX_ int oldfd, int newfd)
205
210
* to extend it, so for the time being this just isn't available on
206
211
* PERL_IMPLICIT_SYS builds.
207
212
*/
213
+ dVAR ;
208
214
DO_ONEOPEN_EXPERIMENTING_CLOEXEC (
215
+ PL_strategy_dup2 ,
209
216
dup3 (oldfd , newfd , O_CLOEXEC ),
210
217
PerlLIO_dup2 (oldfd , newfd ));
211
218
#else
@@ -216,9 +223,11 @@ Perl_PerlLIO_dup2_cloexec(pTHX_ int oldfd, int newfd)
216
223
int
217
224
Perl_PerlLIO_open_cloexec (pTHX_ const char * file , int flag )
218
225
{
226
+ dVAR ;
219
227
PERL_ARGS_ASSERT_PERLLIO_OPEN_CLOEXEC ;
220
228
#if defined(O_CLOEXEC )
221
229
DO_ONEOPEN_EXPERIMENTING_CLOEXEC (
230
+ PL_strategy_open ,
222
231
PerlLIO_open (file , flag | O_CLOEXEC ),
223
232
PerlLIO_open (file , flag ));
224
233
#else
@@ -229,9 +238,11 @@ Perl_PerlLIO_open_cloexec(pTHX_ const char *file, int flag)
229
238
int
230
239
Perl_PerlLIO_open3_cloexec (pTHX_ const char * file , int flag , int perm )
231
240
{
241
+ dVAR ;
232
242
PERL_ARGS_ASSERT_PERLLIO_OPEN3_CLOEXEC ;
233
243
#if defined(O_CLOEXEC )
234
244
DO_ONEOPEN_EXPERIMENTING_CLOEXEC (
245
+ PL_strategy_open3 ,
235
246
PerlLIO_open3 (file , flag | O_CLOEXEC , perm ),
236
247
PerlLIO_open3 (file , flag , perm ));
237
248
#else
@@ -242,9 +253,11 @@ Perl_PerlLIO_open3_cloexec(pTHX_ const char *file, int flag, int perm)
242
253
int
243
254
Perl_my_mkstemp_cloexec (char * templte )
244
255
{
256
+ dVAR ;
245
257
PERL_ARGS_ASSERT_MY_MKSTEMP_CLOEXEC ;
246
258
#if defined(O_CLOEXEC )
247
259
DO_ONEOPEN_EXPERIMENTING_CLOEXEC (
260
+ PL_strategy_mkstemp ,
248
261
Perl_my_mkostemp (templte , O_CLOEXEC ),
249
262
Perl_my_mkstemp (templte ));
250
263
#else
@@ -256,14 +269,15 @@ Perl_my_mkstemp_cloexec(char *templte)
256
269
int
257
270
Perl_PerlProc_pipe_cloexec (pTHX_ int * pipefd )
258
271
{
272
+ dVAR ;
259
273
PERL_ARGS_ASSERT_PERLPROC_PIPE_CLOEXEC ;
260
274
/*
261
275
* struct IPerlProc doesn't cover pipe2(), and there's no clear way
262
276
* to extend it, so for the time being this just isn't available on
263
277
* PERL_IMPLICIT_SYS builds.
264
278
*/
265
279
# if !defined(PERL_IMPLICIT_SYS ) && defined(HAS_PIPE2 ) && defined(O_CLOEXEC )
266
- DO_PIPEOPEN_EXPERIMENTING_CLOEXEC (pipefd ,
280
+ DO_PIPEOPEN_EXPERIMENTING_CLOEXEC (PL_strategy_pipe , pipefd ,
267
281
pipe2 (pipefd , O_CLOEXEC ),
268
282
PerlProc_pipe (pipefd ));
269
283
# else
278
292
Perl_PerlSock_socket_cloexec (pTHX_ int domain , int type , int protocol )
279
293
{
280
294
# if defined(SOCK_CLOEXEC )
295
+ dVAR ;
281
296
DO_ONEOPEN_EXPERIMENTING_CLOEXEC (
297
+ PL_strategy_socket ,
282
298
PerlSock_socket (domain , type | SOCK_CLOEXEC , protocol ),
283
299
PerlSock_socket (domain , type , protocol ));
284
300
# else
@@ -297,7 +313,9 @@ Perl_PerlSock_accept_cloexec(pTHX_ int listenfd, struct sockaddr *addr,
297
313
* way to extend it, so for the time being this just isn't available
298
314
* on PERL_IMPLICIT_SYS builds.
299
315
*/
316
+ dVAR ;
300
317
DO_ONEOPEN_EXPERIMENTING_CLOEXEC (
318
+ PL_strategy_accept ,
301
319
accept4 (listenfd , addr , addrlen , SOCK_CLOEXEC ),
302
320
PerlSock_accept (listenfd , addr , addrlen ));
303
321
# else
314
332
Perl_PerlSock_socketpair_cloexec (pTHX_ int domain , int type , int protocol ,
315
333
int * pairfd )
316
334
{
335
+ dVAR ;
317
336
PERL_ARGS_ASSERT_PERLSOCK_SOCKETPAIR_CLOEXEC ;
318
337
# ifdef SOCK_CLOEXEC
319
- DO_PIPEOPEN_EXPERIMENTING_CLOEXEC (pairfd ,
338
+ DO_PIPEOPEN_EXPERIMENTING_CLOEXEC (PL_strategy_socketpair , pairfd ,
320
339
PerlSock_socketpair (domain , type | SOCK_CLOEXEC , protocol , pairfd ),
321
340
PerlSock_socketpair (domain , type , protocol , pairfd ));
322
341
# else
0 commit comments