From db3614900602b51edd79ae8c1308b8665de9f913 Mon Sep 17 00:00:00 2001
From: Peter Stephenson
Date: Sat, 15 May 2021 13:59:17 -0700
Subject: [PATCH] users/26742: break out of surrounding shell loops when exit
is called from an exit hook
---
ChangeLog | 3 +++
Src/builtin.c | 5 ++++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 38f18a4b9..8e241fa6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2021-05-15 Bart Schaefer
+ * Peter Stephenson: users/26742: Src/builtin.c: break out of
+ surrounding shell loops when "exit" is called from an exit hook
+
* users/26736: Src/Zle/zle_main.c: avoid infinite loop in getbyte
when read -q is called from exit hook
diff --git a/Src/builtin.c b/Src/builtin.c
index b7ceefd55..a29eb49e4 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5828,8 +5828,11 @@ zexit(int val, enum zexit_t from_where)
* a later value always overrides an earlier.
*/
exit_val = val;
- if (shell_exiting == -1)
+ if (shell_exiting == -1) {
+ retflag = 1;
+ breaks = loops;
return;
+ }
if (isset(MONITOR) && !stopmsg && from_where != ZEXIT_SIGNAL) {
scanjobs(); /* check if jobs need printing */