From 2a25221eaf63f8dbe30bf56dc14dd32fc0a06fc2 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Mon, 27 Apr 2026 21:27:20 +0100 Subject: [PATCH] Suppress the error message about a signal interrupt in cursor mode in all but the first instance in a pipeline (#187). --- src/pv/cursor.c | 28 +++++++++++++++++++++++++++- src/pv/loop.c | 7 ++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/pv/cursor.c b/src/pv/cursor.c index 0a8ed91..f05b3a5 100644 --- a/src/pv/cursor.c +++ b/src/pv/cursor.c @@ -43,6 +43,13 @@ #endif +/* + * Flag to allow reporting of "interrupted by signal" errors - cleared in + * secondary instances in a pipeline, so that only one will report them. + */ +static bool pv__allow_signal_interrupt_reporting = true; + + /* * Create a per-euid, per-tty, lock file in ${TMPDIR:-${TMP:-/tmp}} for the * tty on the given file descriptor. @@ -360,6 +367,14 @@ static int pv_crs_ipcinit(pvcursorstate_t cursor, readonly_pvcontrol_t control, cursor->shared->tty_tostop_added = false; cursor->y_lastread = cursor->y_start; debug("%s", "we are the first to attach"); + } else { + /* + * Another process was first, so prevent the current + * instance from reporting "interrupted by signal" errors + * since the first one will do that. + */ + debug("%s", "not the first to attach - clearing pv__allow_signal_interrupt_reporting"); + pv__allow_signal_interrupt_reporting = false; } cursor->y_offset = cursor->pvcount - 1; @@ -440,7 +455,7 @@ void pv_crs_init(pvcursorstate_t cursor, readonly_pvcontrol_t control, pvtransie #ifdef ECHOCTL /* - * If the terminal ECHCTL attribute was already cleared by this + * If the terminal ECHOCTL attribute was already cleared by this * process, set the flag in shared memory to let the other instances * know. */ @@ -750,3 +765,14 @@ void pv_crs_fini(pvcursorstate_t cursor, readonly_pvcontrol_t control, pvtransie } } } + + +/* + * Report a signal interrupt, unless the flag allowing it has been cleared + * due to another instance already taking responsibility. + */ +void pv_report_signal_interrupt(void) +{ + if (pv__allow_signal_interrupt_reporting) + pv_error("%s", _("interrupted by signal")); +} diff --git a/src/pv/loop.c b/src/pv/loop.c index d1d91a9..c037568 100644 --- a/src/pv/loop.c +++ b/src/pv/loop.c @@ -31,6 +31,7 @@ int pv_remote_transferstate_fetch(pvstate_t, pid_t, /*@null@ */ off_t *, bool); void pv_end_display(void); +void pv_report_signal_interrupt(void); #if HAVE_SQRTL @@ -777,7 +778,7 @@ int pv_main_loop(pvstate_t state) if (1 == state->flags.trigger_exit) { state->status.exit_status |= PV_ERROREXIT_SIGNAL; - pv_error("%s", _("interrupted by signal")); + pv_report_signal_interrupt(); } return state->status.exit_status; @@ -1324,7 +1325,7 @@ int pv_watchfd_loop(pvstate_t state) */ if (1 == state->flags.trigger_exit) { state->status.exit_status |= PV_ERROREXIT_SIGNAL; - pv_error("%s", _("interrupted by signal")); + pv_report_signal_interrupt(); } /* Free all allocated sub-structures. */ @@ -1468,7 +1469,7 @@ int pv_query_loop(pvstate_t state, pid_t query) if (1 == state->flags.trigger_exit) { state->status.exit_status |= PV_ERROREXIT_SIGNAL; - pv_error("%s", _("interrupted by signal")); + pv_report_signal_interrupt(); } return state->status.exit_status;