From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11675 invoked by alias); 12 Jun 2018 11:33:07 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23472 Received: (qmail 10937 invoked by uid 1010); 12 Jun 2018 11:33:07 -0000 X-Qmail-Scanner-Diagnostics: from mailout1.w1.samsung.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(210.118.77.11):SA:0(-6.9/5.0):. Processed in 1.713244 secs); 12 Jun 2018 11:33:07 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS,SPF_PASS,T_DKIMWL_WL_HIGH,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180612113300euoutp01559f84aab525a066c4e28ded604a64a4~3ZmRzqlR90276002760euoutp01J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1528803180; bh=Bixc3tuMr+aF/2wH/Tyf0BWz/oK9g4P6XroeoAeuq/I=; h=Date:From:To:Subject:In-Reply-To:References:From; b=VAwCLiwAjwh5BZlkh7ge1vyszq1FFNuPpNBynYEXpHBGKKHtkWgc2SIXfbYcttd1R jew84zFiApJdeZ0Z1Rggq7Ch2IB+khOMUusehvaUhS7O5Y1Y952I27JqyhgGHuazqw 7N0dsE26yJu/0Xp96ebk2dkMvGRnRzK7LAPnRwx4= X-AuditID: cbfec7f5-f95739c0000028a9-ee-5b1faf6aa7e6 Date: Tue, 12 Jun 2018 12:32:55 +0100 From: Peter Stephenson To: Eric Freese , Zsh Users Subject: Re: Anyone familiar with auto-fu.zsh project? In-Reply-To: Organization: SCSC X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOIsWRmVeSWpSXmKPExsWy7djPc7pZ6+WjDW7eFrPoXPGW1WLHyZWM DkweO2fdZfdYdfADUwBTFJdNSmpOZllqkb5dAlfG9k3pBc3yFevXzmFvYFwp0cXIySEhYCJx csoJpi5GLg4hgRWMEk97frGAJIQEvjBKNM1Rh0h8ZpS4/OMqE0zH9P4LbBCJ5YwSP25fYoer +rDwJzOEc4ZR4vuv84wQzgVGia+LX7OC9LMIqEq0r7/GCGKzCRhKTN00G8wWEXCT+Hj6BzuI LSxgJrH1SRPYPk6BQInGB5+B9nFw8AsISVxotoU4w17i6J6TYCW8AoISJ2c+AbubWUBeYvvb OWBHSAj8Z5OY2ziPEaSXV6BM4tqfJIheF4nWy/3MELawxKvjW9ghbBmJ05N7WCB62xkl1kx6 zQ7h9DBKbDp6hxGiylqi7/ZFsKHMApoS63fpQ4QdJZbMe8AOEpYQ4JO48VYQ4h4+iUnbpjND hHklOtqEIKrVJHY0bWWcwKg8C8kHs5B8MAth/gJG5lWM4qmlxbnpqcXGeanlesWJucWleel6 yfm5mxiByeH0v+NfdzDu+5N0iFGAg1GJh9fAXD5aiDWxrLgy9xCjBAezkghvrg5QiDclsbIq tSg/vqg0J7X4EKM0B4uSOG+cRl2UkEB6YklqdmpqQWoRTJaJg1OqgfFOzP4F71njOJSYPe5c OG6uzHTLXvXMOaMXyjNtZjDv1VhitIOXj4ej6ducA196xZ6kZCjVrp4Sdd/TZoa7vvyJrVPL n6zsSzrhVCmTMWuWxmenkxti/N4+WRd3d2/9qbkupQ4fpuznc2I7wOOxxXOKzanI4lUPvJe7 czVXWZ/m36LF/6QjpUmJpTgj0VCLuag4EQC96bxrCgMAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprKIsWRmVeSWpSXmKPExsVy+t/xu7qZ6+WjDQ6dZ7XoXPGW1WLHyZWM DkweO2fdZfdYdfADUwBTlJ5NUX5pSapCRn5xia1StKGFkZ6hpYWekYmlnqGxeayVkamSvp1N SmpOZllqkb5dgl7G9k3pBc3yFevXzmFvYFwp0cXIySEhYCIxvf8CG4gtJLCUUWLHPVaIuIzE pysf2SFsYYk/17qAariAaj4ySuxduZoJwjnDKLH8/jtGCOcCo8TNxjMsIC0sAqoS7euvMYLY bAKGElM3zQazRQTcJD6e/gE2VljATGLrkyagSRwcvALOEjeX+YOEOQUCJRoffIbaNpVVYu/1 1ewgNfwCQhIXmm0hLrKXOLrnJBOIzSsgKHFy5hOwtcwCOhInVh1jhrDlJba/ncM8gVF4FpKy WUjKZiEpW8DIvIpRJLW0ODc9t9hIrzgxt7g0L10vOT93EyMwSrYd+7llB2PXu+BDjAIcjEo8 vBuq5aKFWBPLiitzDzFKcDArifDm6shHC/GmJFZWpRblxxeV5qQWH2I0BYbFRGYp0eR8YATn lcQbmhqaW1gamhubG5tZKInznjeojBISSE8sSc1OTS1ILYLpY+LglGpgVHadv3jGjQ1rf4mZ tpw4xqb8OEhgh1nouRsV7M/NveKkkpp25LWXBookc6l8ODT/ssquC3/ub4m4mb6xWC899Nmm zVFdHQahWz4FbCnNcbk2fUKj8SKWv/sVthd8Fr/0+03cu695H79ETS6dnHPRna3dvkL4/Yuw O38nvPWIfzkpT9Xh5nGhSUosxRmJhlrMRcWJAPopooGoAgAA Message-Id: <20180612113257eucas1p2342f735bcea27bb1009aee1b23c682f0~3ZmPbMrh61839118391eucas1p2G@eucas1p2.samsung.com> X-CMS-MailID: 20180612113257eucas1p2342f735bcea27bb1009aee1b23c682f0 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20180612015719epcas5p34a5f79f58e821488853b6a7eceba7ec8 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180612015719epcas5p34a5f79f58e821488853b6a7eceba7ec8 References: On Mon, 11 Jun 2018 19:55:32 -0600 Eric Freese wrote: > Do you know if there is any way to get the PID of the process spawned > for process substitution? It looks like `$!` doesn't hold it as it > does in bash. Hmm, this is obviously useful but I'd be loath simply to make $! do this as the fact there's an asynchronous process involved is a bit hidden and the mechanism is rather different from creating a background job, so that could be confusing. We could add it to the $sysparams hash provided by the zsh/system module? This already contains some PID information. (It's not strictly a system parameter but I don't think anyone's going to hold a gun to my head and tell me this hash can only return the result of immediate system calls.) pws diff --git a/Doc/Zsh/mod_system.yo b/Doc/Zsh/mod_system.yo index 7f2009b..a27bab4 100644 --- a/Doc/Zsh/mod_system.yo +++ b/Doc/Zsh/mod_system.yo @@ -255,6 +255,11 @@ Returns the process ID of the parent of the current process, even in subshells. Compare tt($PPID), which returns the process ID of the parent of the main shell process. ) +item(tt(procsubstpid))( +Returns the process ID of the last process started for process +substitution, i.e. the tt(LPAR())var(...)tt(RPAR()) expansions. +) enditem() ) enditem() diff --git a/Src/Modules/system.c b/Src/Modules/system.c index 9fd4d25..7a4f4ee 100644 --- a/Src/Modules/system.c +++ b/Src/Modules/system.c @@ -772,6 +772,8 @@ fillpmsysparams(Param pm, const char *name) num = (int)getpid(); } else if (!strcmp(name, "ppid")) { num = (int)getppid(); + } else if (!strcmp(name, "procsubstpid")) { + num = (int)procsubstpid; } else { pm->u.str = dupstring(""); pm->node.flags |= PM_UNSET; @@ -805,6 +807,8 @@ scanpmsysparams(UNUSED(HashTable ht), ScanFunc func, int flags) func(&spm.node, flags); fillpmsysparams(&spm, "ppid"); func(&spm.node, flags); + fillpmsysparams(&spm, "procsubstpid"); + func(&spm.node, flags); } static struct mathfunc mftab[] = { diff --git a/Src/exec.c b/Src/exec.c index 963b0a5..d445278 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -174,6 +174,11 @@ mod_export int zleactive; /**/ pid_t cmdoutpid; +/* pid of last process started by <(...), >(...) */ + +/**/ +mod_export pid_t procsubstpid; + /* exit status of process undergoing 'process substitution' */ /**/ @@ -4850,6 +4855,7 @@ getproc(char *cmd, char **eptr) return NULL; if (!out) addproc(pid, NULL, 1, &bgtime); + procsubstpid = pid; return pnam; } closem(FDT_UNUSED, 0); @@ -4887,6 +4893,7 @@ getproc(char *cmd, char **eptr) { addproc(pid, NULL, 1, &bgtime); } + procsubstpid = pid; return pnam; } entersubsh(ESUB_ASYNC|ESUB_PGRP); @@ -4937,6 +4944,7 @@ getpipe(char *cmd, int nullexec) } if (!nullexec) addproc(pid, NULL, 1, &bgtime); + procsubstpid = pid; return pipes[!out]; } entersubsh(ESUB_PGRP); @@ -6172,6 +6180,7 @@ execsave(void) es->cmdoutpid = cmdoutpid; es->cmdoutval = cmdoutval; es->use_cmdoutval = use_cmdoutval; + es->procsubstpid = procsubstpid; es->trap_return = trap_return; es->trap_state = trap_state; es->trapisfunc = trapisfunc; @@ -6207,6 +6216,7 @@ execrestore(void) cmdoutpid = en->cmdoutpid; cmdoutval = en->cmdoutval; use_cmdoutval = en->use_cmdoutval; + procsubstpid = en->procsubstpid; trap_return = en->trap_return; trap_state = en->trap_state; trapisfunc = en->trapisfunc; diff --git a/Src/zsh.h b/Src/zsh.h index 8535d48..8e7f20b 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -1095,6 +1095,7 @@ struct execstack { pid_t cmdoutpid; int cmdoutval; int use_cmdoutval; + pid_t procsubstpid; int trap_return; int trap_state; int trapisfunc;