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)