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 7305 invoked from network); 24 Jun 2021 08:48:01 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Jun 2021 08:48:01 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1624524481; b=Epj7if91bOoROdj+VrKhA6X8ow1ayDtqq3YXPcAKWsOr+ocEvZmo1wgKVxw1JKTe2Bc22T/iVC HbKsl7wEnm3hpocC1vH+YuE9OoC/fNL2XN5K3hgxEusSD4Uzcv2TCzUVg6aVvlSnCHEVZEwK2b 7hLrHq/J4JQnYPlF6Pg7lKLqNLw0vdaxUQto6YsDie5cdtaPjMgysp8gKNJhubHf13vmqhqGTt AnWrMTfPb03bi5KBvXhEKqXCx5R9sF2ZW4fPvHjQbWH0K5CaIdNEr/SOSTND07uVMlOv8TJF7C io3tySbPQd28mwARfACyEwVp6zam0FtGcpnTxBQLpdTo4w==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (joooj.vinc17.net) smtp.remote-ip=155.133.131.76; dmarc=none header.from=vinc17.net; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1624524481; bh=CDReeFZy6r8C44lnqgdX6M1EO80OPO33Vgg/gdwBE/s=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature; b=b8upAcGgOuN/R1v0OCELXvfnQbIlm1SP9zXm/NUDe8fvEeKCtoQfXlhnj3wSavgvCIVzN2/16W VeIBqIKXVnAco1fgGLPtmhUSxJG8OkdMNyXq3kdiAaOm1mu9UqHYvk9sR5qz53JQlQj00sJg3w Rylar0HjdS1ORU6XMc+cQyEuys+5KYtiwdKcoYIfEbhAFUIitR6jLcwVG4ROGTudXbEsY7hvcR roRfez4YaagunifvKP9LrWRJeRq+bjYaWf24Ba8ZWIWx4VK+OtpqPRqM4ARze5huogRfH0KRdV XTMCMvhZ3sVX1ytusf5a1AtvCoy1sx4GMj6OabiTItKdEA==; 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-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=V/iWzjowAgbb1b0sW1iZDYNMY45hutHl6o/gn6cc6EM=; b=TiGXahf/Gi4UrDcMbKApVjXNv7 cB9lbblDqssJYMVf5ZXNtzneALwfDbpku11bJpp3ITn4G5YkaBPLkzBb5l0CExMhRZjhkKZhgTayo qE3VcipThN6jVAv6XI9xg717YIADShTEieJsuwz4Ek4WUbrD3AWdQLAfnB20l9KjJgXIs9BPvVSot RYx2vn3J6TZ6tPN49IwlApjYdZRDeDhFvgZSSCvNhHpxJE7Kxj+1XMJhPsf0lPx0I/DAUGGH6RrxI FCXuukWqUPWfrxmZbt+5aYzX54JX6uenYMuB8Oi7e63t9PgD+vrm7BdsNQV7h6a2PEXPebIiip7J8 ReM4zCOQ==; Received: from authenticated user by zero.zsh.org with local id 1lwL1l-00015G-FV; Thu, 24 Jun 2021 08:48:01 +0000 Authentication-Results: zsh.org; iprev=pass (joooj.vinc17.net) smtp.remote-ip=155.133.131.76; dmarc=none header.from=vinc17.net; arc=none Received: from joooj.vinc17.net ([155.133.131.76]:37002) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1lwL1Q-0000me-Hy; Thu, 24 Jun 2021 08:47:41 +0000 Received: from smtp-zira.vinc17.net (128.119.75.86.rev.sfr.net [86.75.119.128]) by joooj.vinc17.net (Postfix) with ESMTPSA id D4DE446; Thu, 24 Jun 2021 10:47:39 +0200 (CEST) Received: by zira.vinc17.org (Postfix, from userid 1000) id 8B139C237F5; Thu, 24 Jun 2021 10:47:39 +0200 (CEST) Date: Thu, 24 Jun 2021 10:47:39 +0200 From: Vincent Lefevre To: zsh-workers@zsh.org Cc: Bart Schaefer Subject: Re: [BUG] builtin echo doesn't check write error Message-ID: <20210624084739.GB170692@zira.vinc17.org> Mail-Followup-To: zsh-workers@zsh.org, Bart Schaefer References: <20210609140940.GA813383@zira.vinc17.org> <20210609181617.k5jbq3z37lt7ry5s@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210609181617.k5jbq3z37lt7ry5s@chazelas.org> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/2.1+10 (5cc548e1) vl-138565 (2021-06-20) X-Seq: 49109 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: Since this message from Stephane got truncated in the archives before a line starting with "From " https://www.zsh.org/mla/workers/2021/msg01272.html I'm including it entirely below, quoted to avoid this issue. I've just posted a message https://www.zsh.org/mla/workers/2021/msg01334.html archived messages with "From " get truncated about this truncation issue. Note also about the bug in echo/print/etc., this actually seems to affect *all* builtins. For instance: zira% (exec >&-; echo) zsh: write error: bad file descriptor zira% (exec >&-; echo >&-) zira% (exec >&-; print) zsh: write error: bad file descriptor zira% (exec >&-; print >&-) zira% (exec >&-; printf "\n") zsh: write error: bad file descriptor zira% (exec >&-; printf "\n" >&-) zira% (exec >&-; pwd) zsh: write error: bad file descriptor zira% (exec >&-; pwd >&-) zira% (exec >&-; history) zsh: write error: bad file descriptor zira% (exec >&-; history >&-) zira% On 2021-06-09 19:16:17 +0100, Stephane Chazelas wrote: > 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. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)