[klibc] [klibc:update-dash] dash: [ERROR] Set exitstatus in onint

klibc-bot for Herbert Xu herbert at gondor.apana.org.au
Sat Mar 28 14:48:20 PDT 2020


Commit-ID:  9cd6cb0f37d13b7b2152560c07f4d168d1c561e1
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=9cd6cb0f37d13b7b2152560c07f4d168d1c561e1
Author:     Herbert Xu <herbert at gondor.apana.org.au>
AuthorDate: Thu, 2 Oct 2014 21:07:55 +0800
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Sat, 28 Mar 2020 21:42:54 +0000

[klibc] dash: [ERROR] Set exitstatus in onint

[ dash commit b4ce4120f87d89476b2d6ab31df43900d2f5ce89 ]

Currently the exit status when we receive SIGINT is set in evalcommand
which means that it doesn't always get set.  For example, if you press
CTRL-C at the prompt of an interactive dash, the exit status is not
set to 130 as it is in many other Bourne shells.

This patch fixes this by moving the setting of the exit status into
onint which also simplifies evalcommand.

Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

---
 usr/dash/error.c |  1 +
 usr/dash/eval.c  | 22 ++++++++--------------
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/usr/dash/error.c b/usr/dash/error.c
index 9d31989e..f9ea9198 100644
--- a/usr/dash/error.c
+++ b/usr/dash/error.c
@@ -105,6 +105,7 @@ onint(void) {
 		signal(SIGINT, SIG_DFL);
 		raise(SIGINT);
 	}
+	exitstatus = SIGINT + 128;
 	exraise(EXINT);
 	/* NOTREACHED */
 }
diff --git a/usr/dash/eval.c b/usr/dash/eval.c
index 578d8919..b3e971bf 100644
--- a/usr/dash/eval.c
+++ b/usr/dash/eval.c
@@ -853,21 +853,15 @@ bail:
 				listsetvar(varlist.list, VEXPORT);
 		}
 		if (evalbltin(cmdentry.u.cmd, argc, argv, flags)) {
-			int status;
-			int i;
-
-			i = exception;
-			if (i == EXEXIT)
-				goto raise;
-
-			status = (i == EXINT) ? SIGINT + 128 : 2;
-			exitstatus = status;
-
-			if (i == EXINT || spclbltin > 0) {
-raise:
-				longjmp(handler->loc, 1);
+			if (exception == EXERROR) {
+				exitstatus = 2;
+				if (spclbltin <= 0) {
+					FORCEINTON;
+					break;
+				}
 			}
-			FORCEINTON;
+raise:
+			longjmp(handler->loc, 1);
 		}
 		break;
 


More information about the klibc mailing list