From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: (qmail 7885 invoked from network); 2 May 2020 18:03:54 -0000 Received-SPF: pass (primenet.com.au: domain of zsh.org designates 203.24.36.2 as permitted sender) receiver=inbox.vuxu.org; client-ip=203.24.36.2 envelope-from= Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 2 May 2020 18:03:54 -0000 Received: (qmail 4475 invoked by alias); 2 May 2020 18:03:40 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45760 Received: (qmail 14327 invoked by uid 1010); 2 May 2020 18:03:40 -0000 X-Qmail-Scanner-Diagnostics: from mail-lj1-f177.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.2/25793. spamassassin: 3.4.4. Clear:RC:0(209.85.208.177):SA:0(-2.0/5.0):. Processed in 1.793207 secs); 02 May 2020 18:03:40 -0000 X-Envelope-From: timothee.mazzucotelli@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.208.177 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=S8ouxZGUh7jG86eMQ5tO/cR6w7jx0+sgRv+0LNiBGp4=; b=DDrsYh883WbEZSSfg8PdFwan4ZNx4WKgVH2OnR+sDrQEbBaMfy72Qli1RDDDHusybR WX8/qfH4sW//N0YNCt4dw6/PctykfebNdteDHeyzphcy73sF6hEE7WcN/W5yJk1InQIt fLgEXfWBqVMyBgtw2Iia7q8QuM/FPxRsBzMdj9R2GslT9d72RAvLuAmeA3nstjKEvCS+ UR1qOEqemml95iiKjtvdxHzTbhkWrhKMtPBGADGBZkheE2UzyWkr2LW21Q2pEIzn7OGw l4mZgmif0B1bRSI/9ZUdyk9oET6JMFluqqDKNMy8nvebXsoh55z4B6Nph5iHidazJz1H htSg== X-Gm-Message-State: AGi0PuYIj/OJXEpzXkZMLd0JXRKy6zDeDojtvaFtI0ONZxCz4zNSW+ex Yl2iUrxLEoJXt8gWC2qmBb9l8kNiYspsZHa+AQA= X-Google-Smtp-Source: APiQypIidPjXmL/EQXg+qzn2WNUmRvTB4sA/SKkq/4+aLlzrE35ZQ+lvZb/lqEUvKEPYmffllYttAVviAKhyK0+m2CM= X-Received: by 2002:a2e:99cc:: with SMTP id l12mr5801691ljj.290.1588442582520; Sat, 02 May 2020 11:03:02 -0700 (PDT) MIME-Version: 1.0 References: <20190518075514.hbygmb5dl5wz23h5@chaz.gmail.com> <20190520103444.qyih7lvoigvf3rfx@chaz.gmail.com> <1563722540.4311.24.camel@samsung.com> <1565710707.5633.11.camel@samsung.com> <309829031.4459446.1587391766024@mail2.virginmedia.com> In-Reply-To: <309829031.4459446.1587391766024@mail2.virginmedia.com> From: =?UTF-8?Q?Timoth=C3=A9e_Mazzucotelli?= Date: Sat, 2 May 2020 20:02:51 +0200 Message-ID: Subject: Re: Feature request: ZSH_XTRACEFD variable To: Peter Stephenson Cc: zsh-workers@zsh.org Content-Type: multipart/alternative; boundary="000000000000e0989e05a4ae1b84" --000000000000e0989e05a4ae1b84 Content-Type: text/plain; charset="UTF-8" I wrote such a test and noticed that file descriptors were being closed each time ZSH_XTRACEFD was (re)assigned, even as a local variable. So I removed the code lines closing the previous file descriptor in xtracefdsetfn, and it seemed to work well. However it seems that leaving the scope of a function where ZSH_XTRACEFD was assigned as a local variable does not unset it, and therefore leaves the file descriptor opened. I thought leaving the scope of a function would implicitly "unset" all variables local to this scope, but it seems it's not the case. I'm not sure how to fix that. How to make sure the file descriptor of a local ZSH_XTRACEFD is closed when leaving the function scope? Or, how to make sure a local ZSH_XTRACEFD is unset when leaving the function scope? Or, how to call xtracefdunsetfn when leaving the function scope? I pasted below the test that should pass if the local file descriptor was properly closed. rm -f redir A() { local ZSH_XTRACEFD=5 B print 'Function A to file descriptor 5' unset ZSH_XTRACEFD print 'Function A to file descriptor 2' } B() { local ZSH_XTRACEFD=6 print 'Function B to file descriptor 6' } exec 4>redir4 5>redir5 6>redir6 ZSH_XTRACEFD=4 set -x print 'Main to file descriptor 4' A ZSH_XTRACEFD=5 ZSH_XTRACEFD=6 unset ZSH_XTRACEFD set +x cat redir4 print cat redir5 print cat redir6 0:Scoped ZSH_XTRACEFD correctly set and restored >Main to file descriptor 4 >Function B to file descriptor 6 >Function A to file descriptor 5 >Function A to file descriptor 2 >+(eval):16> print 'Main to file descriptor 4' >+(eval):17> A >+A:1> local ZSH_XTRACEFD=5 >+(eval):18> ZSH_XTRACEFD=5 >+(eval):19> ZSH_XTRACEFD=6 >+(eval):20> unset ZSH_XTRACEFD > >+A:2> B >+B:1> local ZSH_XTRACEFD=6 >+A:3> print 'Function A to file descriptor 5' >+A:4> unset ZSH_XTRACEFD > >+B:2> print 'Function B to file descriptor 6' ?+A:5> print 'Function A to file descriptor 2' ?(eval):18: file descriptor 5 is not valid ?(eval):19: file descriptor 6 is not valid ?+(eval):21> set +x --000000000000e0989e05a4ae1b84--