From aa2ae64dff6d623c4635f108788df126285dbb9d Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 8 Nov 2006 17:43:31 +0000 Subject: 22983: exit could loop for ever --- Src/builtin.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Src/builtin.c') diff --git a/Src/builtin.c b/Src/builtin.c index adb0f6ee2..ff40c8b70 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -4391,6 +4391,10 @@ zexit(int val, int from_where) { static int in_exit; + /* Don't do anything recursively: see below */ + if (in_exit == -1) + return; + if (isset(MONITOR) && !stopmsg && from_where != 1) { scanjobs(); /* check if jobs need printing */ if (isset(CHECKJOBS)) @@ -4400,9 +4404,16 @@ zexit(int val, int from_where) return; } } + /* Positive in_exit means we have been here before */ if (from_where == 2 || (in_exit++ && from_where)) return; + /* + * We're now committed to exiting. Set in_exit to -1 to + * indicate we shouldn't do any recursive processing. + */ + in_exit = -1; + if (isset(MONITOR)) { /* send SIGHUP to any jobs left running */ killrunjobs(from_where == 1); -- cgit 1.4.1