aboutsummaryrefslogtreecommitdiff
path: root/src/xz/private.h
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2023-01-26 18:29:17 +0200
committerLasse Collin <lasse.collin@tukaani.org>2023-01-27 19:37:47 +0200
commitff592c616eda274215b485cf1b8d34f060c9f3be (patch)
tree7c3141dc351c68803372e7bcae4a87e5d7dcb6a7 /src/xz/private.h
parentTranslations: Add Brazilian Portuguese translation of man pages. (diff)
downloadxz-ff592c616eda274215b485cf1b8d34f060c9f3be.tar.xz
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
Diffstat (limited to 'src/xz/private.h')
-rw-r--r--src/xz/private.h12
1 files changed, 12 insertions, 0 deletions
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"