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.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HTML_MESSAGE,MAILING_LIST_MULTI,MIME_HEADER_CTYPE_ONLY, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 23631 invoked from network); 7 Dec 2022 19:04:24 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Dec 2022 19:04:24 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1670439864; b=FqYhF9x3fG81jYKlQt8XCMQSZ354HqCkw54Xp55jgmua76fsF+++yzroiJoK2KMtcA1j+MgtOz Rf6lAwW/Rs0BBR5lXB10NIAIL8mq+Zu0o+n4Iip09o1opSbxs818Sh4yPFtVlsYOPAhfVEC7Me 8rxvgmKjM2Mpf5GXOhPY6nXcy8cwchY/iyIacnDKWk2EyVpmeisaMlXLZb4mVwUMLjPnNaGWHt AJ4t339eOWJWyrtingK4vIb6L7gl16O5McTSmZ0O+4xGd2+d7689h0vlXwgoQn1FDlNbFuMKEj slFMlbzulfg4i81wc/K1AFyOA7nwL/v/Fao4TkmMnyQBSQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (smtp1.irit.fr) smtp.remote-ip=141.115.24.2; dmarc=none header.from=irit.fr; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1670439864; bh=BeLciNFmB+/Ox6S8jyIlkzvaT6k+XScLdlJSyjB6WGQ=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:To:Subject:From:Date:Message-ID:Content-Type:DKIM-Signature; b=Atb33LcxnLeqMpJ2zO6tyUvzNIummNaIQpgYwqdz4/mAr8petbjttp5sHXwnfJI1jzCPaa2WTI LS1PCmLZ0DSBucieeWJun96aCT1NeZrozufgJWzLRgGS92M8QlrDpmrlg/zoBgW3Ct9ySkSUdp 4Ahq0LWfMWZQGx/T1Hn/h7rAbo/kMR1Eh+whM/QvzerKU8b5854bIBgzP1ATwnlK0SfF+zVRzt Wp69/Ts0FOfKUnahFRABmv+Z1TH1jCl2aosB5yiJLtXrzg+GxGyjcwLkOxZCkEVg2X3R5EE6Lj TU3ajjQm/RLQwRKjH6a7cm+N0AYB+Kd4ClB52DSKdAlH+A==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:To:Subject:From:Date:Message-ID: Content-Type:Reply-To:Cc:MIME-Version: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=V99tH4CW0I9zBr/AoFINCLseHkfdNxK1BBrrBzifvvk=; b=JC2fy22HFVf5AqIYoTNFM+ZEcv lTRWq0+xyx3H6/w0XhRD5lKtK9fQ9wOv4OPb3eFaz0JPJ/StWCWMfnXLm+kefn6T3vIKcr4JlsUhS 6BNV7QGn61woEltM1QbImIIlzNwl9Vnm7bOk1zS1k0Vc8UfIquFFEUl+1Ln64eVJbkoOEIEGFZJnJ kVcNXmcOeFIcbcra906ADU4jSDoOjS73jolFnPqOMuuu144V0JJsb0CO9bwMBTZZNRcSel/t/2+ER E0wH926hW54hMIt7tP1s0IDaY7d/F1OivMPDXwAdGIfNmBBK0QUEucbqUD6Cso9gTrhXZHyF6ZFc+ NhtrEW5w==; Received: by zero.zsh.org with local id 1p2ziS-0008rl-8G; Wed, 07 Dec 2022 19:04:24 +0000 Authentication-Results: zsh.org; iprev=pass (smtp1.irit.fr) smtp.remote-ip=141.115.24.2; dmarc=none header.from=irit.fr; arc=none Received: from smtp1.irit.fr ([141.115.24.2]:41284) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1p2zgR-0008VA-Uq; Wed, 07 Dec 2022 19:02:20 +0000 Content-Type: multipart/mixed; boundary="------------PXgkZpO50n0t3gtJmkSl7yjF" Message-ID: <9e3026aa-39a1-dd50-4d29-a64724d4eaaf@irit.fr> Date: Wed, 7 Dec 2022 20:02:18 +0100 Content-Language: fr, en-US From: Millian Poquet Subject: [bug report] prompt can erase messages written on the terminal by background processes To: zsh-workers@zsh.org X-Validation-by: kb@spambri.de X-Seq: 51127 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: This is a multi-part message in MIME format. --------------PXgkZpO50n0t3gtJmkSl7yjF Content-Type: multipart/alternative; boundary="------------iX5U6d1S80VCpGARA00AdR0a" --------------iX5U6d1S80VCpGARA00AdR0a Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, I think that I found a zsh prompt display bug that can hide the messages printed by some processes on the terminal to end users. (Please tell me if I should report the bug elsewhere, I sent it to this mailing list because 1. I could not find an active zsh bug tracker and 2. both https://github.com/zsh-users/zsh's README and https://sourceforge.net/p/zsh/bugs/ told me to write the bug report here.) I am no zsh expert so please tell me if this behavior is expected and if a configuration option exists to prevent such message loss. *# Bug description* It seems that the way zsh displays its prompt enables the loss of messages written on the terminal in some cases. As the bug is visual, I recorded what has been printed on terminal session there: https://asciinema.org/a/543461 The attached MWE program `nowait.c` can be compiled with `gcc -std=c11 -D_POSIX_C_SOURCE=199309L -Wall -Wextra -O2 -o nowait nowait.c` and enables to reproduce the error. It has the following behavior. - The initial process writes a message on the terminal, then creates a subprocess (via libc `fork()`), then exits. - The subprocess sleeps for a given number of milliseconds (or does not sleep at all if `argv[1] == 0`), then writes another message on the terminal. The written message is terminated by a newline if and only if `argv[2] == 1`. If the subprocess writes on the terminal between the termination of the initial process and the writing of the prompt, the content of its message is erased by the prompt. If the message is newline-terminated this is not a big deal, but otherwise the whole message will be hidden from the end user of the terminal. I had the issue on the theme I use regularly (that uses `prompt_subst`), but I could also reproduce the issue from the default theme. To do so, I made the prompt message generation slow by setting `PROMPT="prompt $(sleep 2)"` and by enabling `prompt_subst`. *# Desired behavior* I think that messages displayed by processes on the terminal should not be hidden by the shell. IMHO keeping the printed messages before the prompt would be reasonable, but anything that prevents message loss would be an improvement (e.g., to copy the messages after erasing the prompt then writing the prompt if you think this is better). *# Execution environment* I could reproduce the problem on several environments. On my laptop (dell latitude 3420, x86-64, linux-5.15.72, NixOS 22.05, zsh-5.9) both on a tty and on the kitty-0.26.2 graphical terminal emulator. Zsh used my configuration there. On a [Grid'5000 econome machine](https://www.grid5000.fr/w/Nantes:Hardware#econome), x86-64, linux-5.10.0-19-amd64, Debian 5.10.149-2 (2022-10-21), zsh-5.9. This machine has an empty zsh configuration. I was connected on the machine remotely via ssh. Best regards, -- Millian Poquet, MCF (Associate Prof), Univ. Toulouse III FSI, Dpt. INFO ; IRIT, Sepia team https://mpoquet.github.io Room 469, IRIT2, cours Rose Dieng-Kuntz, Campus Univ. Toulouse III --------------iX5U6d1S80VCpGARA00AdR0a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Hi,

I think that I found a zsh prompt display bug that can hide the messages printed by some processes on the terminal to end users.
(Please tell me if I should report the bug elsewhere, I sent it to this mailing list because 1. I could not find an active zsh bug tracker and 2. both https://github.com/zsh-users/zsh's README and https://sourceforge.net/p/zsh/bugs/ told me to write the bug report here.)

I am no zsh expert so please tell me if this behavior is expected and if a configuration option exists to prevent such message loss.


# Bug description
It seems that the way zsh displays its prompt enables the loss of messages written on the terminal in some cases.
As the bug is visual, I recorded what has been printed on terminal session there: https://asciinema.org/a/543461

The attached MWE program `nowait.c` can be compiled with `gcc -std=c11 -D_POSIX_C_SOURCE=199309L -Wall -Wextra -O2 -o nowait nowait.c` and enables to reproduce the error. It has the following behavior.
- The initial process writes a message on the terminal, then creates a subprocess (via libc `fork()`), then exits.
- The subprocess sleeps for a given number of milliseconds (or does not sleep at all if `argv[1] == 0`), then writes another message on the terminal. The written message is terminated by a newline if and only if `argv[2] == 1`.

If the subprocess writes on the terminal between the termination of the initial process and the writing of the prompt, the content of its message is erased by the prompt.
If the message is newline-terminated this is not a big deal, but otherwise the whole message will be hidden from the end user of the terminal.

I had the issue on the theme I use regularly (that uses `prompt_subst`), but I could also reproduce the issue from the default theme.
To do so, I made the prompt message generation slow by setting `PROMPT="prompt $(sleep 2)"` and by enabling `prompt_subst`.

# Desired behavior
I think that messages displayed by processes on the terminal should not be hidden by the shell.

IMHO keeping the printed messages before the prompt would be reasonable, but anything that prevents message loss would be an improvement (e.g., to copy the messages after erasing the prompt then writing the prompt if you think this is better).

# Execution environment
I could reproduce the problem on several environments.

On my laptop (dell latitude 3420, x86-64, linux-5.15.72, NixOS 22.05, zsh-5.9) both on a tty and on the kitty-0.26.2 graphical terminal emulator. Zsh used my configuration there.

On a [Grid'5000 econome machine](https://www.grid5000.fr/w/Nantes:Hardware#econome), x86-64, linux-5.10.0-19-amd64, Debian 5.10.149-2 (2022-10-21), zsh-5.9. This machine has an empty zsh configuration. I was connected on the machine remotely via ssh.


Best regards,

-- 
Millian Poquet, MCF (Associate Prof), Univ. Toulouse III
FSI, Dpt. INFO ; IRIT, Sepia team
https://mpoquet.github.io
Room 469, IRIT2, cours Rose Dieng-Kuntz, Campus Univ. Toulouse III
--------------iX5U6d1S80VCpGARA00AdR0a-- --------------PXgkZpO50n0t3gtJmkSl7yjF Content-Type: text/x-csrc; charset=UTF-8; name="nowait.c" Content-Disposition: attachment; filename="nowait.c" Content-Transfer-Encoding: base64 I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHRpbWUu aD4KI2luY2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