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=-1.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 20631 invoked from network); 4 Sep 2020 19:49:22 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 4 Sep 2020 19:49:22 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1599248962; b=ZwkCc6EAKm79Fn3dg+jiJC26JPRdwnapePwGOiRBxQEnN2Cw2FmwyNj74jYms3vIzKrr5vIoMX k45cGCHO22bmZSaRblZBtCFSHegpiQmlwQjrQNBdLHvz9NhzrD+S5475lKg8hFP/zv4FYxN3IE iF5Gr6XkJcRX6JopKiFYlfkEDLTFxMm7YSp9peeuaTUN0XlSgFffDmzbDJOu4ubSo2i675FaE5 q+uYVcXvrfCYPtlrzOpc1UP7bMSDZH4QM5zyWTUeuxCWp8cuIVrqyhM9BTd5yvdkCBQ9BY/hl7 Cg9K/eLHbx89ZCEX+uewYtF8lQyTHFdKrWFb7EdjVfN0/g==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; dkim=pass header.d=daniel.shahaf.name header.s=fm1 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm3 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1599248962; bh=n8sE+xHeG1N9qhnd7FJUJlmuvqmvkl/6aT6k02+/vck=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=ZZQ/mF6+n0vBGNXIw9mVDfL/iAkAhTpK6HreQSqdpTAfgx5yO2vnJ/Rqj//4QALHYd86roP3kO 0QVJcZWTHK+OhbDZAEsgzOsxej18ffbTMFaXKssTw9BsZODDaJeW2GyKI5uQVzMzAuthq6U+6W PMuyGdI35Q+UczdO/GfTJiKd9Mx8ralz2wQ20Gc/2rmE9p0Ub8cbmZelGdPWpbCGucJ7i2dIFW IAOVpA4iKaoOYY1+cgFqi6Hyg0Y1hKdmBxh+d5Hub08afd1UuiWEpl3LKVe9Ld2wGk2n0woxEA quKYUGMuRAmg/e0ryV5FVKx6JdvQbXXYJD8Tyn9YtQjBmg==; 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-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To: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=Sr1z533qVO7CVK5RQZl/ynFtV5xqQAuKvFvnb0DATBA=; b=icdsyACJhszCYNduqb2WYFmDU0 9XZPa7Ze4Nkyz27iC8vxB4WHRKIT1zVPN18iXW7OMCpD57TaomZHc0kbi3wRCnyfX49KzcyiNW7Mc Lv61eOV6D/ZRvY2BTg5e77Q+8pQKbTk7OPMJPJHGdjgXSjOcvWrcpHSiYdSLijSPT4z0GIPieIhdo ewnrkumjPNBacbTvepdfhTXfUkfUNpuGjG/jUhPcsod8K40jZaWUVyt+M5zAAiXH7ctfo6L+8lqWi P0nqKvxRm9G4z4BjNjMVIgSWufllIObXL9hLvTAAjMpCkgo8tlDCUb3d34+7//bIiAYECGJlOfYEL xLRVKZTA==; Received: from authenticated user by zero.zsh.org with local id 1kEHi3-0001cn-OT; Fri, 04 Sep 2020 19:49:19 +0000 Authentication-Results: zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; dkim=pass header.d=daniel.shahaf.name header.s=fm1 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm3 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from out3-smtp.messagingengine.com ([66.111.4.27]:36573) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1kEHhm-0001TO-3u; Fri, 04 Sep 2020 19:49:03 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 7A7165C00B9; Fri, 4 Sep 2020 15:49:00 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 04 Sep 2020 15:49:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :in-reply-to:references:mime-version:content-type :content-transfer-encoding; s=fm1; bh=Sr1z533qVO7CVK5RQZl/ynFtV5 xqQAuKvFvnb0DATBA=; b=R6mXPLb1N44AvvqjrxXvxLZAAsI6nr0wFhrMAgXvtn o8aiZtfIgd6X+r7quGNJrFHoNSOirNDcaW4bb4lviXFtm8pWvU+hdBKKrGjpoeMZ AzVnerAxVILvYBHUM/fg+h9mbNGucsEDX25NEUmd/ZKRTy37ilAm38jBJMUuvlZo 95QbXx1nq/9z6qNF/S/HA0np9Qsy2PxCcyNI3TLMvek5FdNS+l342G4NL4XY3Z8z qhcyaU+DgAvPfDcOgytDSVL2FO0DSXQ7pl0B2uJJy3sVbAtdwcFUU+V4Znhu20bJ k/A4lZrKLr8hZFzQS7m9Bc93jKQ6A8IbTzvyRiougOSg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=Sr1z533qVO7CVK5RQZl/ynFtV5xqQAuKvFvnb0DAT BA=; b=ibV2OJzIiahbgXIdu5TBdjA7knPp8Nl9dCrj+2xLvFF567b+Y+o8xiCeQ g3KC+/1OoFH0mmd5P5JOjuyJODRWWmDeWL66nNqC9hMJbPdsmORfUFCymb+b7Hro quPAKunTic2MCp37HUa6uRNmkSsRZyHh8KQx6V6OtEh6KGRrI5aR3tn5TOlfFdfY xCekNx9nj/HIDDksygR0P742Zl0/OujuT4n5Vatsro3MT521ssSAj9DjrWu/NJMQ uxL4dFFYpCFLB5IjsmZyjfprLW8W6VMtDNyb3P3WPG6BqvLc2E5Q+mBwLrnoJbGw myRTC+MMxBYJDLF3B4IONH1ai8HXQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrudegfedgudegvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkjghfofggtgfgsehtqhdttdertdejnecuhfhrohhmpeffrghn ihgvlhcuufhhrghhrghfuceougdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgvqe enucggtffrrghtthgvrhhnpeevjefgvefhleevfeeuteffhfffieekueeifeeileeuteet feduteeutdetkedutdenucffohhmrghinhepghhithhhuhgsrdgtohhmpdhnthhlfihorh hlugdrtghomhenucfkphepjeelrddukedurddurddvtddvnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugdrshesuggrnhhivghlrdhshhgrhh grfhdrnhgrmhgv X-ME-Proxy: Received: from tarpaulin.shahaf.local2 (bzq-79-181-1-202.red.bezeqint.net [79.181.1.202]) by mail.messagingengine.com (Postfix) with ESMTPA id 8262B328005D; Fri, 4 Sep 2020 15:48:59 -0400 (EDT) Received: from tarpaulin.shahaf.local2 (localhost [IPv6:::1]) by tarpaulin.shahaf.local2 (Postfix) with ESMTP id 4BjpCF6W3tzfJ; Fri, 4 Sep 2020 19:48:57 +0000 (UTC) Date: Fri, 4 Sep 2020 19:48:56 +0000 From: Daniel Shahaf To: =?UTF-8?B?VGltb3Row6ll?= Mazzucotelli Cc: Bart Schaefer , Peter Stephenson , "zsh-workers@zsh.org" Subject: Re: Feature request: ZSH_XTRACEFD variable Message-ID: <20200904194856.0e115c95@tarpaulin.shahaf.local2> In-Reply-To: References: <309829031.4459446.1587391766024@mail2.virginmedia.com> <20200503000658.6fddb904@tarpaulin.shahaf.local2> <20200503210618.5c639014@tarpaulin.shahaf.local2> <505277422.148264.1588581302888@mail2.virginmedia.com> <20200505000331.59294412@tarpaulin.shahaf.local2> <600054363.204367.1588697277901@mail2.virginmedia.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Seq: 47358 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: Archived-At: Timoth=C3=A9e Mazzucotelli wrote on Thu, 03 Sep 2020 15:51 +0200: > Hello, I'm coming back to the ZSH_XTRACEFD feature again :) >=20 > About closing file descriptors or not: I don't understand what it means to > "leak a FILE". "FILE", in this context, is the opaque type defined by the C programming language. (See the return type of fopen(3), for example.) In implementations, a FILE typically wraps a "file descriptor" (fd), which is an int. The kernel caps the number of file descriptors the process may have open at any one time (see ulimit/unlimit). For this reason it's important to always close fd's when done using them. To "leak" a fd means to lose track of its integer value and the fact it needs to be closed. For example, the following function leaks a fd: . static void f(void) { open("/dev/null", O_WRONLY); return; } =20 Every call to f() leaks one fd. If f() were called in a loop, eventually it would not be possible to open more files: . [[[ % repeat $((1 + $(ulimit -n))) { eval "exec {fd$((++i))}>/dev/null" }=20 zsh: cannot moved fd 3: too many open files zsh: exit 1 =E2=8B=AE ]]] (That's rather dense, I'm afraid, so feel free to ask further. The number of iterations is large enough to ensure the error happens in the last iteration or earlier. The variable $i is autovivified and used to generate a different variable name in every iteration of the loop ($fd1, $fd2, =E2=80=A6, $fd1025) since I didn't know whether the square brackets array element variable name syntax could be used in that context.) If f() called fopen() rather than open(), it would leak not only a fd but also whatever other resources the FILE encapsulated (e.g., a small block of malloc()'d memory). HTH. I'll leave the ZSH_XTRACEFD-specific aspects for others. Cheers, Daniel P.S. The quoted error message is ungrammatical. > I'm not sure to understand the past comments either: we only use fdopen > when the value of ZSH_XTRACEFD is > 2. > For 0, 1 and 2, we re-use the existing file descriptors stdin, stdout and > stderr. >=20 > Anyway, I added the patch in an attachment. Also, here's the link to the > commit on my fork: > https://github.com/pawamoy/zsh/commit/b9b37333fcf02a463f6f742976b37b45ab0= 8742d >=20 > In this patch, I never close any file descriptor. >=20 > There's one last thing that looks weird to me: > single instructions like ZSH_XTRACEFD=3D5 are not properly logged in the > xtrace output. > It seems they are truncated up to the end of the variable assignment: > - with a=3D0 ZSH_XTRACEFD=3D5, nothing appear in the output either > - with ZXH_XTRACEFD=3D5 a=3D0, only a=3D0 appears in the output (but no > +(eval):18 prefix or similar) >=20 > Any idea about this? >=20 > Cheers, > Timoth=C3=A9e >=20 > On Wed, May 6, 2020 at 12:20 AM Bart Schaefer > wrote: >=20 > > (Peter, for some reason Gmail is classifying all email from > > ntlworld.com as spam, with the notation that it "can't guarantee that > > this message came from ntlworld.com") > > > > On Tue, May 5, 2020 at 9:48 AM Peter Stephenson > > wrote: =20 > > > > > > > > > The problem is if we fopen() the file descriptor to use stdio as outp= ut, =20 > > we can either =20 > > > leak the entire FILE, not opened by the user, or we can close the ent= ire =20 > > FILE. > > > > In that case we should be doing the fopen() on a dup() of the > > descriptor, and fclose()ing the FILE. > > > > If it is important that fileno(xtrerr) =3D=3D $ZSH_XTRACEFD, then we sh= ould > > 1) dup() the descriptor to save a copy > > 2) fopen() the original > > 3) after fclose(), dup2() the copy back to the original > > 4) close() the copy > > > > However, I'm not sure it's necessary to be that convoluted. > > =20