• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision3935 (tree)
Time2018-12-09 00:25:58
Authormagicant

Log Message

Reset exitstatus in subshell (#38774)

If a subshell is executed in the EXIT trap, the subshell should not exit
with exitstatus' as if it were the parent shell. For the desired
result,
exitstatus' has to be reset in the subshell.

Change Summary

Incremental Difference

--- yash/trunk/NEWS (revision 3934)
+++ yash/trunk/NEWS (revision 3935)
@@ -20,6 +20,11 @@
2020 = The default value of $PS1 has been changed.
2121 * The line number is now correctly counted in arithmetic
2222 expansions that contain newlines.
23+ * Subshells in the EXIT trap were unexpectedly exiting with the
24+ exit status of the last command executed before the EXIT trap on
25+ the main shell.
26+ * A new EXIT trap that was set in a subshell in the EXIT trap was
27+ unexpectedly being ignored.
2328 * The variable name token in the for command and the word following
2429 a here-document redirection operator are now correctly parsed
2530 even when it resulted from an alias substitution whose value
--- yash/trunk/exec.c (revision 3934)
+++ yash/trunk/exec.c (revision 3935)
@@ -196,6 +196,8 @@
196196 int savelaststatus = -1; // -1 if not in a trap handler
197197 /* exit status of the last command substitution */
198198 static int lastcmdsubstatus;
199+/* exit status of the command that immediately preceded the EXIT trap. */
200+int exitstatus = -1; // -1 if not executing the EXIT trap
199201 /* the process ID of the last asynchronous list */
200202 pid_t lastasyncpid;
201203
@@ -1034,6 +1036,7 @@
10341036 clear_shellfds(sigtype & t_leave);
10351037 is_interactive_now = false;
10361038 suppresserrreturn = false;
1039+ exitstatus = -1;
10371040 }
10381041 return cpid;
10391042 }
--- yash/trunk/exec.h (revision 3934)
+++ yash/trunk/exec.h (revision 3935)
@@ -1,6 +1,6 @@
11 /* Yash: yet another shell */
22 /* exec.h: command execution */
3-/* (C) 2007-2016 magicant */
3+/* (C) 2007-2018 magicant */
44
55 /* This program is free software: you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
@@ -41,7 +41,7 @@
4141 #define Exit_ASSGNERR Exit_ERROR
4242 #define Exit_REDIRERR Exit_ERROR
4343
44-extern int laststatus, savelaststatus;
44+extern int laststatus, savelaststatus, exitstatus;
4545 extern pid_t lastasyncpid;
4646 extern _Bool special_builtin_executed;
4747 extern _Bool is_executing_auxiliary;
--- yash/trunk/sig.c (revision 3934)
+++ yash/trunk/sig.c (revision 3935)
@@ -782,11 +782,6 @@
782782
783783 wchar_t *command = trap_command[sigindex(0)];
784784 if (command != NULL) {
785-#ifndef NDEBUG
786- static bool exit_handled = false;
787- assert(!exit_handled);
788- exit_handled = true;
789-#endif
790785 savelaststatus = laststatus;
791786 command = xwcsdup(command);
792787 reset_execstate(true);
--- yash/trunk/yash.c (revision 3934)
+++ yash/trunk/yash.c (revision 3935)
@@ -1,6 +1,6 @@
11 /* Yash: yet another shell */
22 /* yash.c: basic functions of the shell */
3-/* (C) 2007-2016 magicant */
3+/* (C) 2007-2018 magicant */
44
55 /* This program is free software: you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
@@ -356,8 +356,6 @@
356356 * This function is reentrant and exits immediately if reentered. */
357357 void exit_shell_with_status(int status)
358358 {
359- static int exitstatus = -1;
360-
361359 if (status >= 0)
362360 laststatus = status;
363361 assert(laststatus >= 0);
Show on old repository browser