diff --git a/Misc/NEWS.d/next/Core and Builtins/2017-06-26-14-41-42.bpo-30766.cejWuh.rst b/Misc/NEWS.d/next/Core and Builtins/2017-06-26-14-41-42.bpo-30766.cejWuh.rst new file mode 100644 index 00000000000000..ba82e6f8f082c7 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2017-06-26-14-41-42.bpo-30766.cejWuh.rst @@ -0,0 +1 @@ +Make CHECK_STATUS_PTHREAD signal-safe diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index b95840ce2d76ac..63e651a3e05787 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -142,9 +142,19 @@ typedef struct { pthread_mutex_t mut; } pthread_lock; +#define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str)) + #define CHECK_STATUS(name) if (status != 0) { perror(name); error = 1; } -#define CHECK_STATUS_PTHREAD(name) if (status != 0) { fprintf(stderr, \ - "%s: %s\n", name, strerror(status)); error = 1; } +/* CHECK_STATUS_PTHREAD is async-signal-safe */ +#define CHECK_STATUS_PTHREAD(name) \ + if (status != 0) { \ + int _stderr_fd = 2; \ + PUTS(_stderr_fd, name); \ + PUTS(_stderr_fd, ": failed with status "); \ + _Py_DumpDecimal(_stderr_fd, (unsigned long) status); \ + PUTS(_stderr_fd, "\n"); \ + error = 1; \ + } /* * Initialization.