commit: 87ee7f2a56d712246eb8d630e3282295ab92bbbe
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Jun 10 23:36:15 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Jun 11 08:32:22 2023 +0000
URL:
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=87ee7f2a
ecma48-cpr: Set up the signal handler before writing to the terminal
The idea being to narrow the window of time during which the terminal
is in its raw mode as much as is possible.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
ecma48-cpr.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/ecma48-cpr.c b/ecma48-cpr.c
index 4710b39..f397ab7 100644
--- a/ecma48-cpr.c
+++ b/ecma48-cpr.c
@@ -89,6 +89,17 @@ main(void) {
new_tty.c_cc[VMIN] = 1;
new_tty.c_cc[VTIME] = 1;
+ /*
+ * Prepare to catch our signals. We treat both an interrupt and a
+ * depleted timer as essentially the same thing: fatal errors.
+ */
+ struct sigaction act;
+ act.sa_handler = on_signal;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = 0;
+ sigaction(SIGALRM, &act, NULL);
+
+
/*
* Try to apply the new terminal settings.
*/
@@ -100,16 +111,6 @@ main(void) {
die("failed to flush the stream after writing the CPR
sequence");
}
- /*
- * Prepare to catch our signals. We treat both an interrupt and a
- * depleted timer as essentially the same thing: fatal errors.
- */
- struct sigaction act;
- act.sa_handler = on_signal;
- sigemptyset(&act.sa_mask);
- act.sa_flags = 0;
- sigaction(SIGALRM, &act, NULL);
-
/*
* A timeout is required, just in case read(2) proves unable to read an
* initial byte, otherwise causing the program to hang.