From e05abf16b5350e7ef2daf5d1a2fc283ca101e3c7 Mon Sep 17 00:00:00 2001 From: "andrey.bychkov" Date: Wed, 5 Aug 2026 17:38:07 +0300 Subject: [PATCH] fix(PIWaitEvent): use -1 as pipe_fd sentinel instead of 0 File descriptor 0 is stdin (a valid fd). Using 0 as the 'not-open' sentinel caused isCreate() to return false and destroy() to skip close() when pipe() happened to allocate fds {0, 1} (e.g. in daemons with closed stdio). POSIX convention: -1 = invalid fd. --- libs/main/core/piwaitevent_p.cpp | 6 +++--- libs/main/core/piwaitevent_p.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/main/core/piwaitevent_p.cpp b/libs/main/core/piwaitevent_p.cpp index 47983a5d..36ec80bc 100644 --- a/libs/main/core/piwaitevent_p.cpp +++ b/libs/main/core/piwaitevent_p.cpp @@ -65,9 +65,9 @@ void PIWaitEvent::destroy() { } #else for (int i = 0; i < 2; ++i) { - if (pipe_fd[i] != 0) { + if (pipe_fd[i] != -1) { ::close(pipe_fd[i]); - pipe_fd[i] = 0; + pipe_fd[i] = -1; } } #endif @@ -140,7 +140,7 @@ bool PIWaitEvent::isCreate() const { #ifdef WINDOWS return event; #else - return pipe_fd[ReadEnd] != 0; + return pipe_fd[ReadEnd] != -1; #endif } diff --git a/libs/main/core/piwaitevent_p.h b/libs/main/core/piwaitevent_p.h index 9814d449..1af19ac1 100644 --- a/libs/main/core/piwaitevent_p.h +++ b/libs/main/core/piwaitevent_p.h @@ -55,7 +55,7 @@ private: #ifdef WINDOWS void * event = nullptr; #else - int pipe_fd[2] = {0, 0}; + int pipe_fd[2] = {-1, -1}; fd_set fds[3]; enum { ReadEnd = 0,