1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-02 16:48:55 +00:00

Suppress SIGPIPE when writing to a pipe.

This commit is contained in:
Pāvels Nadtočajevs
2025-10-01 13:39:29 +03:00
parent d705613db3
commit 3245230a40

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 {