Merge pull request #111114 from bruvzg/sigpipe_ign

Suppress SIGPIPE when writing to a pipe.
This commit is contained in:
Thaddeus Crews 2025-11-25 09:52:27 -06:00
commit 0da802cdd7
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC

View file

@ -41,6 +41,11 @@
#include <sys/types.h>
#include <unistd.h>
#include <cerrno>
#include <csignal>
#ifndef sighandler_t
typedef typeof(void(int)) *sighandler_t;
#endif
Error FileAccessUnixPipe::open_existing(int p_rfd, int p_wfd, bool p_blocking) {
// Open pipe using handles created by pipe(fd) call in the OS.execute_with_pipe.
@ -165,7 +170,11 @@ bool FileAccessUnixPipe::store_buffer(const uint8_t *p_src, uint64_t p_length) {
ERR_FAIL_COND_V_MSG(fd[1] < 0, false, "Pipe must be opened before use.");
ERR_FAIL_COND_V(!p_src && p_length > 0, false);
if (::write(fd[1], p_src, p_length) != (ssize_t)p_length) {
sighandler_t sig_pipe = signal(SIGPIPE, SIG_IGN);
ssize_t ret = ::write(fd[1], p_src, p_length);
signal(SIGPIPE, sig_pipe);
if (ret != (ssize_t)p_length) {
last_error = ERR_FILE_CANT_WRITE;
return false;
} else {