Move the MAKE_OUTPUT_NONBLOCKING code to state.c, as it can no longer work in main.c due to accessing internal structures; but still leave it switched off by default for now.

This commit is contained in:
Andrew Wood
2024-07-16 22:41:31 +01:00
parent a7c3f3dd35
commit 72e5078ce9
2 changed files with 13 additions and 13 deletions
-13
View File
@@ -11,9 +11,6 @@
#include "options.h"
#include "pv.h"
/* We do not set this because it breaks "dd" - see below. */
/* #undef MAKE_OUTPUT_NONBLOCKING */
#include <stdio.h>
#include <string.h>
#include <errno.h>
@@ -335,16 +332,6 @@ int main(int argc, char **argv)
opts->fineta, opts->rate, opts->average_rate,
opts->bytes, opts->bufpercent, opts->lastwritten, opts->name);
#ifdef MAKE_OUTPUT_NONBLOCKING
/*
* Try and make the output use non-blocking I/O.
*
* Note that this can cause problems with (broken) applications
* such as dd when used in a pipeline.
*/
fcntl(state->control.output_fd, F_SETFL, O_NONBLOCK | fcntl(state->control.output_fd, F_GETFL));
#endif /* MAKE_OUTPUT_NONBLOCKING */
/* Initialise the signal handling. */
pv_sig_init(state);
+13
View File
@@ -10,11 +10,15 @@
#include "pv.h"
#include "pv-internal.h"
/* We do not set this because it breaks "dd" - see below. */
/* #undef MAKE_OUTPUT_NONBLOCKING */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
/* alloc / realloc history buffer */
@@ -385,6 +389,15 @@ void pv_state_output_set(pvstate_t state, int fd, const char *name)
free(state->control.output_name);
state->control.output_fd = fd;
state->control.output_name = pv_strdup(name);
#ifdef MAKE_OUTPUT_NONBLOCKING
/*
* Try and make the output use non-blocking I/O.
*
* Note that this can cause problems with (broken) applications
* such as dd when used in a pipeline.
*/
fcntl(state->control.output_fd, F_SETFL, O_NONBLOCK | fcntl(state->control.output_fd, F_GETFL));
#endif /* MAKE_OUTPUT_NONBLOCKING */
}
void pv_state_average_rate_window_set(pvstate_t state, unsigned int val)