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 6416 invoked from network); 9 Jun 2021 18:16:37 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 9 Jun 2021 18:16:37 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1623262597; b=HpEVN6anXEegMA60LYbgykOU/So701HJIugPy38LxDw2rareVLnTYwDGkz79wC6h+o5sv96uS6 ukVVCqqhOx3gEFhTkOTD6jDkvr8GPDyGviGO/CpqiHN/vg4lQQ1Ik1r0FRNhTwJunSBE8Cicrx DHtrM7kom2GXHXHFst2ExBiBQp15BtowbYmvqWRB/oKKeuku7tXViaHT+Y5SPwBU+2YSID4Q8P jUrmFBRBsQvFwPpQ5r5diKbTGIFrrv+iS/NqzzWALsTraCG/VEW+gkKg8qFtxBepFGqpGVzcZk 39KMXPDt0a7Zte4ev1o8YVrSlZUeNP1p1UjcmkCDQ+IwBg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay9-d.mail.gandi.net) smtp.remote-ip=217.70.183.199; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1623262597; bh=kZzssRGYowFcCGI70jZXixeS8rbHYbkGgolNYeVMYCo=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature; b=KvTRQTC3mmRHR5tb9DsdJ+942VGAJbHXL8GxKkYqRy8T2a5kY6GrZwgtvTCrlSgSTSnQMuGsI7 S6DNBo4vrf4gcQGvyWJL9e6pHFhLfjDEkczLmyQbxoYigvzYma8vlFqM/9NhgBB+NoS+8XEMQe pWnOnK3lpiuTce4l1KGwOvtMmZ3ReD/Vdpj7LAeM8FUHqgDsVCf1zsfmyRfKac7i8i4IK/dajI XXXXGqbZipIVXiKnUoY70lg7yupQbxCcqgdwGqNF4RHhgQaaNq6sGVZhK/jNetuN7dWkKT91S+ 7S7SYNWNOTGds827S8naVfTU4CkvrrpmL6JO6kVbU8EXSA==; 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:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=fNj3mv3+blKfdyTsCaxfpjvT+zLOPEjWM5ZFxCP9i+A=; b=jopYRTI3O3nqnW+TSIyP7SCVkT O0ubVfONI8L3hkG31EJUGw71K0crjoC5FbCYl08+cCAwmBYLeGUTZWp/Rf3SuCFS0wYqyzU6NVN20 aknprf5TyhIU2t9LM9lpbnm3YsxfnD3IYic30sYf6rNGWLl5xiAgBC7ybx1RuIrjfWJuGelVQPPCw 0mGpKABp/0uGfq6p57VfZFY1HEah+0+yc556ktmY5HZP9a8X1Bd4q7ZcFm0Kjk2P9xe6Ix8/GSYXi h/185QDeuLYUPZ7wfj/rn2MrfVAPT9CjMs41eJn+sTvGpZb9ADmTe8ysXphuOPK8VFN5i2WxxABNl SP7E5dlw==; Received: from authenticated user by zero.zsh.org with local id 1lr2km-000AuY-Nv; Wed, 09 Jun 2021 18:16:36 +0000 Authentication-Results: zsh.org; iprev=pass (relay9-d.mail.gandi.net) smtp.remote-ip=217.70.183.199; dmarc=none header.from=chazelas.org; arc=none Received: from relay9-d.mail.gandi.net ([217.70.183.199]:57379) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1lr2kV-000Ac2-At; Wed, 09 Jun 2021 18:16:19 +0000 Received: (Authenticated sender: stephane@chazelas.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 93986FF802; Wed, 9 Jun 2021 18:16:18 +0000 (UTC) Date: Wed, 9 Jun 2021 19:16:17 +0100 From: Stephane Chazelas To: Bart Schaefer Cc: Zsh hackers list Subject: Re: [BUG] builtin echo doesn't check write error Message-ID: <20210609181617.k5jbq3z37lt7ry5s@chazelas.org> Mail-Followup-To: Bart Schaefer , Zsh hackers list References: <20210609140940.GA813383@zira.vinc17.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Seq: 49046 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: 2021-06-09 09:13:42 -0700, Bart Schaefer: [...] > My (possibly poor) recollection is that this was made this way in part > for ports to environments that don't have a /dev/null device While that sounds like a very plausible reason for the original behaviour whereby "print" would not report any write error, that doesn't really tie up with the current behaviour where the error is supressed only when print/echo's stdout is explicitly closed. Why would one write print foo >&- in the first place, other than to check whether print reports error or not (and in that regard, the behaviour is very misleading) >From looking at the history, it looks more like: 1990 (1.0) echo ignores write failures (by design or not). 1999 workers/9129 Peter writes the "print foo >&-" succeeds, no error test case, just documenting the actual behaviour of print ignoring errors (here using >&- as the easiest way to trigger a write error). 2002 workers/16503 Clint adds some error messages upon write errors. 2002 workers/16556 we realise it breaks the test case above, so Bart removes the error message on EBADF for that test case to pass again. The fact that there's still an error message in (print)>&- looks like an oversight. The error in that case is output by execcmd_exec after print has returned as it tries to fflush stdout again,, not bin_print (you'll notice the error message doesn't mention "print"). 2011 workers/29845 Peter notices the error is displayed in (exec >&-; print) and adds a test case for it, but I'm not sure he correctly identified why. It very much looks like an (multiple) accident of implementation. POSIX does say that printf/echo should return with a non-zero exit status upon error, and stderr be used for diagnostix errors as usual. It's not clear to me if implementations are at liberty to decide whether a write() error is considered an error or not. In any case, it would be useful from an error point of view to be able to detect when writing fails. -- Stephane