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.
This commit is contained in:
2026-08-05 17:39:36 +03:00
parent 6c5c4b73e0
commit e05abf16b5
2 changed files with 4 additions and 4 deletions
+3 -3
View File
@@ -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
}