zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: "Jörg Sommer" <joerg@jo-so.de>, zsh-users@zsh.org
Subject: Re: Zsh spins in endless loop with SIGHUP + read in zshexit
Date: Thu, 13 May 2021 16:51:14 +0100 (BST)	[thread overview]
Message-ID: <1527863615.81691.1620921074419@mail2.virginmedia.com> (raw)
In-Reply-To: <20210513101751.j5vo2dbrd5uzwju4@jo-so.de>


> On 13 May 2021 at 11:17 Jörg Sommer <joerg@jo-so.de> wrote:
> I'm using `read` in `zshexit` and when my terminal crashes (e.g. XTerm gets
> killed or ssh connection dies) Zsh spins in an endless loop until I kill it
> with SIGKILL (SIGTERM doesn't work).
> 
> ```
> zshexit()
> {
>     if [[ ${#${(M)${(f)"$(</proc/self/mountinfo)"}#*/ / rw,}} == 1 ]]
>     then
>         if read -rq junk"?Root filesystem is still read-write. Remount ro? (y/N) "
>         then
>             echo
>             mount -o remount,ro / || sleep 4
>         else
>             echo
>         fi
>     fi
> }
> ```

Yes, that's a clear bug.  Bart's been mulling over some error handling oddities
down here, not sure if that's one of them.  This is a bit of a special case ---
how about this?  Possibly other calls to zexit() might need similar treatment.

(More zsh-workers this time round, as it turns out.)

Warning: I'm currently in webmailland, too, but the diff is originally from a
proper Linux set up.

pws

diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 0561c3b3b..e8d1260b1 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -905,7 +905,8 @@ getbyte(long do_keytmout, int *timeout, int full)
 		if ((zlereadflags & ZLRF_IGNOREEOF) && icnt++ < 20)
 		    continue;
 		stopmsg = 1;
-		zexit(1, ZEXIT_NORMAL);
+		if (zexit(1, ZEXIT_NORMAL))
+		    return lastchar = EOF;
 	    }
 	    icnt = 0;
 	    if (errno == EINTR) {
@@ -928,14 +929,15 @@ getbyte(long do_keytmout, int *timeout, int full)
 	    } else if (errno != 0) {
 		zerr("error on TTY read: %e", errno);
 		stopmsg = 1;
-		zexit(1, ZEXIT_NORMAL);
+		if (zexit(1, ZEXIT_NORMAL))
+		    return lastchar = EOF;
 	    }
 	}
 	if (cc == '\r')		/* undo the exchange of \n and \r determined by */
 	    cc = '\n';		/* zsetterm() */
 	else if (cc == '\n')
 	    cc = '\r';
-
+	
 	ret = STOUC(cc);
     }
     /*
diff --git a/Src/builtin.c b/Src/builtin.c
index b7ceefd55..aefd1436f 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5816,10 +5816,14 @@ _realexit(void)
  *   ZEXIT_DEFERRED if we can't actually exit yet (e.g., functions need
  *                  terminating) but should perform the usual interactive
  *                  tests.
+ *
+ * If this returns 1, we are already exiting the shell:  deeply
+ * embedded calls to this function should give up at that point
+ * and return an error indication.
  */
 
 /**/
-mod_export void
+mod_export int
 zexit(int val, enum zexit_t from_where)
 {
     /*
@@ -5829,7 +5833,7 @@ zexit(int val, enum zexit_t from_where)
      */
     exit_val = val;
     if (shell_exiting == -1)
-	return;
+	return 1;
 
     if (isset(MONITOR) && !stopmsg && from_where != ZEXIT_SIGNAL) {
 	scanjobs();    /* check if jobs need printing           */
@@ -5837,13 +5841,13 @@ zexit(int val, enum zexit_t from_where)
 	    checkjobs();   /* check if any jobs are running/stopped */
 	if (stopmsg) {
 	    stopmsg = 2;
-	    return;
+	    return 0;
 	}
     }
     /* Positive shell_exiting means we have been here before */
     if (from_where == ZEXIT_DEFERRED ||
 	(shell_exiting++ && from_where != ZEXIT_NORMAL))
-	return;
+	return 0;
 
     /*
      * We're now committed to exiting.  Set shell_exiting to -1 to
@@ -5893,6 +5897,8 @@ zexit(int val, enum zexit_t from_where)
 	_exit(exit_val);
     else
 	exit(exit_val);
+    /*NOTREACHED*/ /* I hope */
+    return 0;
 }
 
 /* . (dot), source */


  parent reply	other threads:[~2021-05-13 15:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-13 10:17 Jörg Sommer
2021-05-13 14:36 ` Daniel Shahaf
2021-07-18 19:11   ` Lawrence Velázquez
2021-07-27  3:14     ` Daniel Shahaf
2021-05-13 15:51 ` Peter Stephenson [this message]
2021-05-13 15:54 ` Bart Schaefer
2021-05-13 16:07   ` Peter Stephenson
2021-05-13 16:30     ` Bart Schaefer
2021-05-13 18:44       ` Peter Stephenson
2021-05-13 21:37         ` Bart Schaefer
2021-05-14  9:56           ` Peter Stephenson
2021-05-14 17:44             ` Peter Stephenson
2021-05-14 18:51             ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1527863615.81691.1620921074419@mail2.virginmedia.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=joerg@jo-so.de \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).