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:
+1
-1
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user