@@ -989,6 +989,7 @@ typedef struct {
989
989
PyObject * struct_rusage ;
990
990
#endif
991
991
PyObject * st_mode ;
992
+ int dup3_works ;
992
993
} _posixstate ;
993
994
994
995
@@ -9407,11 +9408,6 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
9407
9408
/*[clinic end generated code: output=bc059d34a73404d1 input=c3cddda8922b038d]*/
9408
9409
{
9409
9410
int res = 0 ;
9410
- #if defined(HAVE_DUP3 ) && \
9411
- !(defined(HAVE_FCNTL_H ) && defined(F_DUP2FD_CLOEXEC ))
9412
- /* dup3() is available on Linux 2.6.27+ and glibc 2.9 */
9413
- static int dup3_works = -1 ;
9414
- #endif
9415
9411
9416
9412
if (fd < 0 || fd2 < 0 ) {
9417
9413
posix_error ();
@@ -9455,21 +9451,22 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
9455
9451
#else
9456
9452
9457
9453
#ifdef HAVE_DUP3
9458
- if (!inheritable && dup3_works != 0 ) {
9454
+ _posixstate * state = get_posix_state (module );
9455
+ if (!inheritable && state -> dup3_works != 0 ) {
9459
9456
Py_BEGIN_ALLOW_THREADS
9460
9457
res = dup3 (fd , fd2 , O_CLOEXEC );
9461
9458
Py_END_ALLOW_THREADS
9462
9459
if (res < 0 ) {
9463
- if (dup3_works == -1 )
9460
+ if (state -> dup3_works == -1 )
9464
9461
dup3_works = (errno != ENOSYS );
9465
- if (dup3_works ) {
9462
+ if (state -> dup3_works ) {
9466
9463
posix_error ();
9467
9464
return -1 ;
9468
9465
}
9469
9466
}
9470
9467
}
9471
9468
9472
- if (inheritable || dup3_works == 0 )
9469
+ if (inheritable || state -> dup3_works == 0 )
9473
9470
{
9474
9471
#endif
9475
9472
Py_BEGIN_ALLOW_THREADS
@@ -15872,6 +15869,16 @@ posixmodule_exec(PyObject *m)
15872
15869
{
15873
15870
_posixstate * state = get_posix_state (m );
15874
15871
15872
+ #if defined(HAVE_DUP3 ) && \
15873
+ !(defined(HAVE_FCNTL_H ) && defined(F_DUP2FD_CLOEXEC ))
15874
+ /* dup3() is available on Linux 2.6.27+ and glibc 2.9 */
15875
+ state -> dup3_works = -1 ;
15876
+ #elif !defined(HAVE_DUP3 )
15877
+ state -> dup3_works = -1 ;
15878
+ #else
15879
+ state -> dup3_works = 0 ;
15880
+ #endif
15881
+
15875
15882
#if defined(HAVE_PWRITEV )
15876
15883
if (HAVE_PWRITEV_RUNTIME ) {} else {
15877
15884
PyObject * dct = PyModule_GetDict (m );
0 commit comments