@@ -64,6 +64,7 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
64
64
char * str ;
65
65
Py_ssize_t len ;
66
66
char buf [1024 ];
67
+ int async_err = 0 ;
67
68
68
69
if (arg != NULL ) {
69
70
int parse_result ;
@@ -75,12 +76,13 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
75
76
return NULL ;
76
77
}
77
78
memcpy (buf , str , len );
78
- Py_BEGIN_ALLOW_THREADS
79
- ret = fcntl (fd , code , buf );
80
- Py_END_ALLOW_THREADS
79
+ do {
80
+ Py_BEGIN_ALLOW_THREADS
81
+ ret = fcntl (fd , code , buf );
82
+ Py_END_ALLOW_THREADS
83
+ } while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals ()));
81
84
if (ret < 0 ) {
82
- PyErr_SetFromErrno (PyExc_OSError );
83
- return NULL ;
85
+ return !async_err ? PyErr_SetFromErrno (PyExc_OSError ) : NULL ;
84
86
}
85
87
return PyBytes_FromStringAndSize (buf , len );
86
88
}
@@ -95,12 +97,13 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
95
97
}
96
98
}
97
99
98
- Py_BEGIN_ALLOW_THREADS
99
- ret = fcntl (fd , code , (int )int_arg );
100
- Py_END_ALLOW_THREADS
100
+ do {
101
+ Py_BEGIN_ALLOW_THREADS
102
+ ret = fcntl (fd , code , (int )int_arg );
103
+ Py_END_ALLOW_THREADS
104
+ } while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals ()));
101
105
if (ret < 0 ) {
102
- PyErr_SetFromErrno (PyExc_OSError );
103
- return NULL ;
106
+ return !async_err ? PyErr_SetFromErrno (PyExc_OSError ) : NULL ;
104
107
}
105
108
return PyLong_FromLong ((long )ret );
106
109
}
@@ -283,11 +286,14 @@ fcntl_flock_impl(PyObject *module, int fd, int code)
283
286
/*[clinic end generated code: output=84059e2b37d2fc64 input=b70a0a41ca22a8a0]*/
284
287
{
285
288
int ret ;
289
+ int async_err = 0 ;
286
290
287
291
#ifdef HAVE_FLOCK
288
- Py_BEGIN_ALLOW_THREADS
289
- ret = flock (fd , code );
290
- Py_END_ALLOW_THREADS
292
+ do {
293
+ Py_BEGIN_ALLOW_THREADS
294
+ ret = flock (fd , code );
295
+ Py_END_ALLOW_THREADS
296
+ } while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals ()));
291
297
#else
292
298
293
299
#ifndef LOCK_SH
@@ -310,14 +316,15 @@ fcntl_flock_impl(PyObject *module, int fd, int code)
310
316
return NULL ;
311
317
}
312
318
l .l_whence = l .l_start = l .l_len = 0 ;
313
- Py_BEGIN_ALLOW_THREADS
314
- ret = fcntl (fd , (code & LOCK_NB ) ? F_SETLK : F_SETLKW , & l );
315
- Py_END_ALLOW_THREADS
319
+ do {
320
+ Py_BEGIN_ALLOW_THREADS
321
+ ret = fcntl (fd , (code & LOCK_NB ) ? F_SETLK : F_SETLKW , & l );
322
+ Py_END_ALLOW_THREADS
323
+ } while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals ()));
316
324
}
317
325
#endif /* HAVE_FLOCK */
318
326
if (ret < 0 ) {
319
- PyErr_SetFromErrno (PyExc_OSError );
320
- return NULL ;
327
+ return !async_err ? PyErr_SetFromErrno (PyExc_OSError ) : NULL ;
321
328
}
322
329
Py_RETURN_NONE ;
323
330
}
@@ -363,6 +370,7 @@ fcntl_lockf_impl(PyObject *module, int fd, int code, PyObject *lenobj,
363
370
/*[clinic end generated code: output=4985e7a172e7461a input=3a5dc01b04371f1a]*/
364
371
{
365
372
int ret ;
373
+ int async_err = 0 ;
366
374
367
375
#ifndef LOCK_SH
368
376
#define LOCK_SH 1 /* shared lock */
@@ -407,13 +415,14 @@ fcntl_lockf_impl(PyObject *module, int fd, int code, PyObject *lenobj,
407
415
return NULL ;
408
416
}
409
417
l .l_whence = whence ;
410
- Py_BEGIN_ALLOW_THREADS
411
- ret = fcntl (fd , (code & LOCK_NB ) ? F_SETLK : F_SETLKW , & l );
412
- Py_END_ALLOW_THREADS
418
+ do {
419
+ Py_BEGIN_ALLOW_THREADS
420
+ ret = fcntl (fd , (code & LOCK_NB ) ? F_SETLK : F_SETLKW , & l );
421
+ Py_END_ALLOW_THREADS
422
+ } while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals ()));
413
423
}
414
424
if (ret < 0 ) {
415
- PyErr_SetFromErrno (PyExc_OSError );
416
- return NULL ;
425
+ return !async_err ? PyErr_SetFromErrno (PyExc_OSError ) : NULL ;
417
426
}
418
427
Py_RETURN_NONE ;
419
428
}
0 commit comments