From 9a639b40b7aa54f953013a5a3a2f7244dca63fb9 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Fri, 4 Oct 2024 08:53:14 +0100 Subject: [PATCH] Use gmtime() instead of localtime() in debugging output to avoid lockups in signal handlers due to time zone lookups. --- docs/NEWS.md | 1 + src/main/debug.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/NEWS.md b/docs/NEWS.md index 5896c6c..dba4373 100644 --- a/docs/NEWS.md +++ b/docs/NEWS.md @@ -1,6 +1,7 @@ ### UNRELEASED * fix: complete set of German translations supplied by Hartmut Goebel ([#98](https://codeberg.org/a-j-wood/pv/pulls/98)) + * fix: write UTC timestamps in debugging mode to avoid lockups in signal handlers * cleanup: removed TODO.md, since it's just an outdated copy of the issue tracker * cleanup: re-ordered structure members to reduce padding * cleanup: improved readability of SIGTTOU handling code diff --git a/src/main/debug.c b/src/main/debug.c index ae7fd4c..13f0f56 100644 --- a/src/main/debug.c +++ b/src/main/debug.c @@ -63,8 +63,18 @@ void debugging_output(const char *function, const char *file, int line, const ch return; } + /* + * Note that here we use gmtime() rather than localtime(), otherwise + * we can get stuck in signal handlers - testing with "strace" + * showed many cases where "pv /dev/null" being + * paused and backgrounded would cause pv to be stuck in + * futex_wait() inside a pv_sig_alrm() inside a pv_sig_cont(). The + * backtrace mentioned many time zone conversion steps, and all of + * that goes away with gmtime(). + */ + (void) time(&t); - tm = localtime(&t); + tm = gmtime(&t); tbuf[0] = '\0'; if (0 == strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", tm)) { tbuf[0] = '\0';