From 72e5078ce97db3151fe1c0c71e2bc7e0f0b52ec3 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Tue, 16 Jul 2024 22:41:31 +0100 Subject: [PATCH] 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. --- src/main/main.c | 13 ------------- src/pv/state.c | 13 +++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/main.c b/src/main/main.c index 838b704..693cac9 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -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 #include #include @@ -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); diff --git a/src/pv/state.c b/src/pv/state.c index 079ea99..472175e 100644 --- a/src/pv/state.c +++ b/src/pv/state.c @@ -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 #include #include #include #include +#include /* 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)