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
This commit is contained in:
Dirk Müller
2026-06-14 21:05:11 +02:00
parent 1fbd9b56a3
commit 411808c680
+1 -1
View File
@@ -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. */