From ff592c616eda274215b485cf1b8d34f060c9f3be Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Thu, 26 Jan 2023 18:29:17 +0200 Subject: xz: Add SIGTSTP handler for progress indicator time keeping. This way, if xz is stopped the elapsed time and estimated time remaining won't get confused by the amount of time spent in the stopped state. This raises SIGSTOP. It's not clear to me if this is the correct way. POSIX and glibc docs say that SIGTSTP shouldn't stop the process if it is orphaned but this commit doesn't attempt to handle that. Search for SIGTSTP in section 2.4.3: https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html --- src/xz/private.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/xz/private.h') diff --git a/src/xz/private.h b/src/xz/private.h index 6414bdb5..a20dbc57 100644 --- a/src/xz/private.h +++ b/src/xz/private.h @@ -49,6 +49,18 @@ # define ENABLE_SANDBOX 1 #endif +// Handling SIGTSTP keeps time-keeping for progress indicator correct +// if xz is stopped. It requires use of clock_gettime() as that is +// async-signal safe in POSIX. Require also SIGALRM support since +// on systems where SIGALRM isn't available, progress indicator code +// polls the time and the SIGTSTP handling adds slight overhead to +// that code. Most (all?) systems that have SIGTSTP also have SIGALRM +// so this requirement won't exclude many systems. +#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_MONOTONIC) \ + && defined(SIGTSTP) && defined(SIGALRM) +# define USE_SIGTSTP_HANDLER 1 +#endif + #include "main.h" #include "mytime.h" #include "coder.h" -- cgit v1.2.3