From 411808c680d0bc5b656ffb2b479c9d5e61d5bb01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dirk=20M=C3=BCller?= Date: Sun, 14 Jun 2026 21:05:11 +0200 Subject: [PATCH] Fix resetting fd counter to -1 Standard output corresponds to file descriptor `1` (`STDOUT_FILENO`). Since the closed file descriptor variable is set to `1` (which is not `-1`), any subsequent checks using `if (-1 != x)` will evaluate to true. If `close_if_open` is called again on the same variable, or if error cleanup code triggers redundant closures, it executes `close(1)`, closing the standard output descriptor of the process --- src/main/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/main.c b/src/main/main.c index 2456b87..a7b2e3b 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -419,7 +419,7 @@ static int pv__monitor(pvstate_t state, opts_t opts, pvformatoptions_s format_op /* Common idiom to close an fd, and set it to -1, if it's open. */ #define close_if_open(x) if (-1 != x) { \ (void) close(x); \ -x = 1; \ +x = -1; \ } /* Create a process to run the command. */