From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 23293 invoked from network); 13 May 2021 10:19:14 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 13 May 2021 10:19:14 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1620901154; b=stRXJptFan7bKS+OpPulDYqdKr7k+cOlIMCB3+g3mnXVnb1v9IMalR6p0FXT9fceiUpxWZqxjV GbvNcGP5uqozdSmSsFvCgRiwCxfAsO1jx8xTBSi0eFO580djAPwPcqnYiKKvlCBEidPn+LxbW4 VRkYNfVyo3Cv2ei21EQC1WJke+JPCkFw3tRSFXJfXhR+7RUAjBell5hWgnIchjfeksQZI+RCEF deDqspZNXiHnEFtiMY8P7t64RsjtHj4Cl7WBPNO+oR7OMjFQDYL7dxdQMgC/UjDEqARbFYtKfG hSWnUtGhGekEfYGKSeQshhnEo/eBrpu6fw+uvH8FI1f8Dw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (s1.jo-so.de) smtp.remote-ip=37.221.195.157; dmarc=none header.from=jo-so.de; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1620901154; bh=6Uflb4pPhmkgXTMR/n/e2kHZnPsTTEo7IdfnpaK7CBI=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:MIME-Version:Message-ID:Subject:To:From:Date: DKIM-Signature; b=dK/SaNG+N0gV6G1vFGNhajR1HdkJnsOllszs7TYl83OBl1QD6nGbKLMzVrUUsP4zsfG1id6NZB I1YHabJ9eg+qPyStcAie0EB9k5cFXhOB2k4tkkv/ehz4JjhTSBfW5GruXEh4rc+CQo5pB8+cSU mF7l45Ar8C+tbk5g3+Rhifrr/zbc9y7QwnnCxjfUwVweP3WR+TlTSfz/WSjIsA6csQISfC9WWw aEmmvu7hMk5hryv5N+yC5EQRH/E8/HsEf0M61KlgWQa3+86MwhYAc74B9jjrQ8dLvB0RCmHGEY csljEZTmR7oxy8lORBBsyc6bTD69ZsN5e4DGBRsZcQhu5Q==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:MIME-Version:Message-ID: Subject:To:From:Date:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=MT8lmUs9hq/HAGB5ixllQyoNijFkEMdTpocx46kRrEA=; b=NOLJBPz1Y2luqSNgtSmqMFslqE mQe0G/XlktbIVtW800mXzQilyYuSoFhwUoU093f4JxS15xRdktoZbbTBcbMi3mlJRUEcE5rJ9zldo 2zXFwR6uNJ48kcrbBg3MK0lpEUGW8sZzqqBcKVv5xFwhioRHuGFR+hAaBSKBYmde1Bb9tTC8XZuP9 Cr0ECuGKN1eV8TZg1EXePVuRH/xhvKxrVyKbiA18PDIeM0xGEZ+ASTxgwOVbx21Hu0Vmz/TYa1Ytm xebNxjwW+9dbrJAKkck6DLO5E3Hd3SohTJLsZfingm1yt+R91slMA7JvoIoN7Zgoe7taW8eI99qkn Dbj+lTJg==; Received: from authenticated user by zero.zsh.org with local id 1lh8Qx-000A1i-Rb; Thu, 13 May 2021 10:19:11 +0000 Authentication-Results: zsh.org; iprev=pass (s1.jo-so.de) smtp.remote-ip=37.221.195.157; dmarc=none header.from=jo-so.de; arc=none Received: from s1.jo-so.de ([37.221.195.157]:37633) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1lh8Ph-0009IE-Ae; Thu, 13 May 2021 10:17:54 +0000 Received: from mail-relay (helo=jo-so.de) by s1.jo-so.de with local-bsmtp (Exim 4.92) (envelope-from ) id 1lh8Pg-0002DE-D0 for zsh-users@zsh.org; Thu, 13 May 2021 12:17:52 +0200 Received: from joerg by zenbook.jo-so.de with local (Exim 4.94.2) (envelope-from ) id 1lh8Pf-0039QX-I9 for zsh-users@zsh.org; Thu, 13 May 2021 12:17:51 +0200 Date: Thu, 13 May 2021 12:17:51 +0200 From: =?utf-8?B?SsO2cmc=?= Sommer To: zsh-users@zsh.org Subject: Zsh spins in endless loop with SIGHUP + read in zshexit Message-ID: <20210513101751.j5vo2dbrd5uzwju4@jo-so.de> OpenPGP: id=7D2C9A23D1AEA375; url=https://jo-so.de/pgp-key.txt; preference=signencrypt MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2utkgj7yqlxlunwy" Content-Disposition: inline X-Seq: 26730 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: --2utkgj7yqlxlunwy Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Zsh spins in endless loop with SIGHUP + read in zshexit MIME-Version: 1.0 Hi, 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)"$(, ap=3D) at ../../../Src/Zle/zle_main.c:2142 #5 0x00005643fcbcbcb8 in zleentry (cmd=3D7) at ../../Src/init.c:1604 #6 0x00005643fcb9e9c8 in bin_read (name=3D, args=3D, ops=3D, func=3D) at ../../Src/builti= n.c:6408 #7 0x00005643fcba013d in execbuiltin (args=3D, assigns=3D, bn=3D) at ../../Src/builtin.c:507 #8 0x00005643fcbb0b02 in execcmd_exec (state=3Dstate@entry=3D0x7fff4013842= 0, eparams=3Deparams@entry=3D0x7fff401351a0, input=3Dinput@entry=3D0, outpu= t=3Doutput@entry=3D0,=20 how=3D, how@entry=3D18, last1=3D, last1@e= ntry=3D2, close_if_forked=3D-1) at ../../Src/exec.c:4090 #9 0x00005643fcbb105f in execpline2 (state=3Dstate@entry=3D0x7fff40138420,= pcode=3D, how=3Dhow@entry=3D18, input=3D0, output=3D0, last= 1=3Dlast1@entry=3D0) at ../../Src/exec.c:1927 #10 0x00005643fcbb1400 in execpline (state=3Dstate@entry=3D0x7fff40138420, = slcode=3D, how=3Dhow@entry=3D18, last1=3D0) at ../../Src/exe= c.c:1658 #11 0x00005643fcbb2d60 in execlist (state=3Dstate@entry=3D0x7fff40138420, d= ont_change_job=3Ddont_change_job@entry=3D1, exiting=3Dexiting@entry=3D0) at ../../Src/exec.c:1413 #12 0x00005643fcbd92bc in execif (state=3D0x7fff40138420, do_exec=3D0) at .= =2E/../Src/loop.c:555 #13 0x00005643fcbaf96c in execcmd_exec (state=3Dstate@entry=3D0x7fff4013842= 0, eparams=3Deparams@entry=3D0x7fff40136900, input=3Dinput@entry=3D0, outpu= t=3Doutput@entry=3D0,=20 how=3D, how@entry=3D18, last1=3D, last1@e= ntry=3D2, close_if_forked=3D-1) at ../../Src/exec.c:3910 #14 0x00005643fcbb105f in execpline2 (state=3Dstate@entry=3D0x7fff40138420,= pcode=3D, how=3Dhow@entry=3D18, input=3D0, output=3D0, last= 1=3Dlast1@entry=3D0) at ../../Src/exec.c:1927 #15 0x00005643fcbb1400 in execpline (state=3Dstate@entry=3D0x7fff40138420, = slcode=3D, how=3Dhow@entry=3D18, last1=3D0) at ../../Src/exe= c.c:1658 #16 0x00005643fcbb2d60 in execlist (state=3Dstate@entry=3D0x7fff40138420, d= ont_change_job=3Ddont_change_job@entry=3D1, exiting=3Dexiting@entry=3D0) at ../../Src/exec.c:1413 #17 0x00005643fcbd92f8 in execif (state=3D0x7fff40138420, do_exec=3D0) at .= =2E/../Src/loop.c:576 #18 0x00005643fcbaf96c in execcmd_exec (state=3Dstate@entry=3D0x7fff4013842= 0, eparams=3Deparams@entry=3D0x7fff40138060, input=3Dinput@entry=3D0, outpu= t=3Doutput@entry=3D0,=20 how=3D, how@entry=3D18, last1=3D, last1@e= ntry=3D2, close_if_forked=3D-1) at ../../Src/exec.c:3910 #19 0x00005643fcbb105f in execpline2 (state=3Dstate@entry=3D0x7fff40138420,= pcode=3D, how=3Dhow@entry=3D18, input=3D0, output=3D0, last= 1=3Dlast1@entry=3D0) at ../../Src/exec.c:1927 #20 0x00005643fcbb1400 in execpline (state=3Dstate@entry=3D0x7fff40138420, = slcode=3D, how=3Dhow@entry=3D18, last1=3D0) at ../../Src/exe= c.c:1658 #21 0x00005643fcbb2d60 in execlist (state=3Dstate@entry=3D0x7fff40138420, d= ont_change_job=3Ddont_change_job@entry=3D1, exiting=3Dexiting@entry=3D0) at ../../Src/exec.c:1413 #22 0x00005643fcbb3202 in execode (p=3Dp@entry=3D0x5643fd1b2270, dont_chang= e_job=3Ddont_change_job@entry=3D1, exiting=3Dexiting@entry=3D0,=20 context=3Dcontext@entry=3D0x5643fcc24b8d "shfunc") at ../../Src/exec.c:= 1192 #23 0x00005643fcbb40ab in runshfunc (prog=3D0x5643fd1b2270, wrap=3D0x0, nam= e=3D0x7fb6d8003170 "zshexit") at ../../Src/exec.c:5974 #24 0x00005643fcbb45d6 in doshfunc (shfunc=3D0x5643fd1ccea0, doshargs=3Ddos= hargs@entry=3D0x0, noreturnval=3Dnoreturnval@entry=3D1) at ../../Src/exec.c= :5824 #25 0x00005643fcc17a43 in callhookfunc (name=3D0x5643fcc23818 "zshexit", ln= klst=3D0x0, arrayp=3D1, retval=3D0x0) at ../../Src/utils.c:1530 #26 0x00005643fcba6095 in zexit (val=3D, from_where=3D) at ../../Src/builtin.c:5810 #27 0x00007fb6d7fcecb4 in getbyte (do_keytmout=3Ddo_keytmout@entry=3D0, tim= eout=3Dtimeout@entry=3D0x0, full=3Dfull@entry=3D1) at ../../../Src/Zle/zle_= main.c:904 #28 0x00007fb6d7fcdbc3 in getkeybuf (w=3D) at ../../../Src/Z= le/zle_keymap.c:1676 #29 getkeymapcmd (km=3D0x5643fd1900f0, funcp=3Dfuncp@entry=3D0x7fff40138c68= , strp=3Dstrp@entry=3D0x7fff40138c70) at ../../../Src/Zle/zle_keymap.c:1587 #30 0x00007fb6d7fcddae in getkeycmd () at ../../../Src/Zle/zle_keymap.c:1715 #31 0x00007fb6d7fcfed5 in zlecore () at ../../../Src/Zle/zle_main.c:1124 #32 0x00007fb6d7fd0dd0 in zleread (lp=3D, rp=3D, flags=3D, context=3D0, init=3D0x7fb6d7ff041d "zle-line-i= nit",=20 finish=3D0x7fb6d7ff040d "zle-line-finish") at ../../../Src/Zle/zle_main= =2Ec:1347 #33 0x00005643fcbcbcb8 in zleentry (cmd=3Dcmd@entry=3D1) at ../../Src/init.= c:1604 #34 0x00005643fcbcd209 in inputline () at ../../Src/input.c:295 #35 ingetc () at ../../Src/input.c:228 #36 0x00005643fcbcd37f in ingetc () at ../../Src/input.c:196 #37 0x00005643fcbc4e66 in ihgetc () at ../../Src/hist.c:407 #38 0x00005643fcbd6a9e in gettok () at ../../Src/lex.c:611 #39 zshlex () at ../../Src/lex.c:275 #40 0x00005643fcbd787e in zshlex () at ../../Src/lex.c:268 #41 0x00005643fcbf6776 in parse_event (endtok=3Dendtok@entry=3D37) at ../..= /Src/parse.c:581 #42 0x00005643fcbc8545 in loop (toplevel=3Dtoplevel@entry=3D1, justonce=3Dj= ustonce@entry=3D0) at ../../Src/init.c:147 #43 0x00005643fcbcc2c6 in zsh_main (argc=3D, argv=3D) at ../../Src/init.c:1758 #44 0x00007fb6d84da09b in __libc_start_main () from /lib/x86_64-linux-gnu/l= ibc.so.6 #45 0x00005643fcb90d4a in _start () ``` Looking into `getbyte` in zle_main.c there's this code: ```c r =3D raw_getbyte(do_keytmout, &cc, full); =E2=80=A6 if (r =3D=3D 0) { /* The test for IGNOREEOF was added to make zsh ignore ^Ds that were typed while commands are running. Unfortunately this caused trouble under at least one system (SunOS 4.1). Here shells that lost their xterm (e.g. if it was killed with -9) didn't fail to read from the terminal but instead happily continued to read EOFs, so that the above read returned with 0, and, with IGNOREEOF set, this caused an infinite loop. The simple way around this was to add the counter (icnt) so that this happens 20 times and than the shell gives up (yes, this is a bit dirty...). */ if ((zlereadflags & ZLRF_IGNOREEOF) && icnt++ < 20) continue; stopmsg =3D 1; zexit(1, ZEXIT_NORMAL); } ``` So, if `raw_getbyte` returns `0` `zexit` gets called again. I think this causes the loop. I didn't debug a hanging process. I've got the backtrace =66rom a core dump. Regards J=C3=B6rg --=20 Jeder macht, was er will =E2=80=93 Keiner macht was er soll =E2=80=93 Aber = alle machen mit! --2utkgj7yqlxlunwy Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iJMEAREIADsWIQS1pYxd0T/67YejVyF9LJoj0a6jdQUCYJz8zR0YaHR0cHM6Ly9q by1zby5kZS9wZ3Ata2V5LnR4dAAKCRB9LJoj0a6jdXVLAPwNX6Ecijtwi14bponf 9lFfg1g7pHbpN50k9ThnT+k8ngD9HnDySywerQr4PVYQfsxu2ZfaPmBLYzMly3qk EXPPSeY= =Br1p -----END PGP SIGNATURE----- --2utkgj7yqlxlunwy--