More's sigatexit handler needs to distinguish between normal exit and exit
due to receipt of a signal.

Change tty_sigreset to look at the signal number too, so that pressing 'q'
to exit top doesn't cause its exit status to be 128.
---
 lib/interestingtimes.c | 2 +-
 lib/xwrap.c            | 4 +++-
 toys/pending/more.c    | 5 +++++
 3 files changed, 9 insertions(+), 2 deletions(-)
From 7ac083f95f6c80457b3e49554eb140be15db0c90 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Thu, 21 Apr 2016 18:18:05 -0700
Subject: [PATCH] Fix more to not append an extra newline.

More's sigatexit handler needs to distinguish between normal exit and exit
due to receipt of a signal.

Change tty_sigreset to look at the signal number too, so that pressing 'q'
to exit top doesn't cause its exit status to be 128.
---
 lib/interestingtimes.c | 2 +-
 lib/xwrap.c            | 4 +++-
 toys/pending/more.c    | 5 +++++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/interestingtimes.c b/lib/interestingtimes.c
index 8337ce8..62670cb 100644
--- a/lib/interestingtimes.c
+++ b/lib/interestingtimes.c
@@ -239,5 +239,5 @@ void tty_reset(void)
 void tty_sigreset(int i)
 {
   tty_reset();
-  _exit(128+i);
+  _exit(i ? 128+i : 0);
 }
diff --git a/lib/xwrap.c b/lib/xwrap.c
index 0b1ab8e..36a601c 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -47,7 +47,9 @@ void xexit(void)
   // Call toys.xexit functions in reverse order added.
   while (toys.xexit) {
     // This is typecasting xexit->arg to a function pointer,then calling it.
-    ((void (*)(void))(toys.xexit->arg))();
+    // Using the invalid signal number 0 lets the signal handlers distinguish
+    // an actual signal from a regular exit.
+    ((void (*)(int))(toys.xexit->arg))(0);
 
     free(llist_pop(&toys.xexit));
   }
diff --git a/toys/pending/more.c b/toys/pending/more.c
index 59b5c61..7923ee4 100644
--- a/toys/pending/more.c
+++ b/toys/pending/more.c
@@ -25,7 +25,12 @@ GLOBALS(
 
 static void signal_handler(int sig)
 {
+  // Reset the terminal whether we were signalled or exited normally.
   tcsetattr(TT.cin_fd, TCSANOW, &TT.inf);
+
+  if (sig == 0) _exit(0);
+
+  // We were actually signalled, so move to a new line and re-raise the signal.
   xputc('\n');
   signal(sig, SIG_DFL);
   raise(sig);
-- 
2.8.0.rc3.226.g39d4020

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to