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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 31914 invoked from network); 28 Mar 2022 16:14:33 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 28 Mar 2022 16:14:33 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1648484073; b=gA6EuY+GP/+0aajcG3WkQwh47lsOVl+uG2rrcZE9AingFveHxt4RPyd6ydldOBF+U34xLRxg+P CGuI0Q5gweBAW5oJJLX1VCUW9bYb0qdRm6heEzYh+ttLS37CFoQTPyGEfYgA/7WPZAVokRIDv1 qyob8KfWt84noth/45WbpHykZsoAc3v0P5rcMl6R+qYD0oJum5CfVz5n02KxGxOnEYII59sWDm pkYv1opVwpHJNRilHLF/UKCFAZg+g+ofl8Q7AEePmb9a6G66Qa7JumF98+baUFc8Hb0FiGTuM/ 2i0Ic9NbeLoQOy34UepK3YKxfZ12q9wiDObpLIs36S6NOA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (smtpq1.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.96; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=pass header.from=ntlworld.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1648484073; bh=nhHCv38Ef2DFBAZmr+9iCKTRF8wVi9xV+0a4Yk1FXUQ=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject: References:In-Reply-To:Message-ID:Cc:To:From:Date:DKIM-Signature: DKIM-Signature; b=ZFti1r8LQBDEbfSo5y2PLQj8DRkUp4fIRXE7WLzarjrlRjjYXZXuM1fc93Okcz35IJa1eLi2mZ M+xqfMH6LxasxyXxsZnlt6s4mUFqV4sF53d1v8sAuXAMCbeta7kqE81GIJHy3NYq4zeIcmOE8i rb/xOgPIoj6RgvFqsSY86rofhHyQyB0AVU2ozP0hxWY3atmRWtW10M/vejUVU7/OKBCaF83JcG ju60vDRUSvDVJelA365Ex4phChIxvG2+D6BAQyx7r+FXa+z25y/b3H23qfZLaIFx0EWsTkRLj7 Xtx4kjUU9FdEJ8+NfnsdxEBKJzMO1fxpKJ9Ezkke1oLa/Q==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:References:In-Reply-To:Message-ID:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=0L3mt8q4iqp245AWgDV8xuDyZ8rFIt9VwPQvSvPBl8A=; b=FJjlP44bTAFq+8HWTpA0PnwbNL oiFrCdsPOZgbKYaWZtYmr/xayUIkQwdD7Du8TLde8sTsRSF/FUYL58cZWs6xJkNGDpnS+TZnAHv2m 90oqYHxgVTVrA+Mo3/i7nxCFdFWJxb2xNfiMQs3P2dYFHx9RydrJlmKP/W7eEI0EWQ6GadId6qC0h UOeb5r84X6ym/+V5VO0qjiEK+5jrjz0VrWFeYFzCf9vbjkdEwiqg95z8/B17eKOYdr4Y0Sd/3pBB5 G0qRzeZQq3lLvI+Vc0vGf7h5sG8C2r/S/yx5A9oFv9C+VFtMw6cx8YJpjFln7xqfe8uEAfO41YfYw R2X1i9MA==; Received: from authenticated user by zero.zsh.org with local id 1nYs0m-000OEa-OO; Mon, 28 Mar 2022 16:14:32 +0000 Authentication-Results: zsh.org; iprev=pass (smtpq1.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.96; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=pass header.from=ntlworld.com; arc=none Received: from smtpq1.tb.ukmail.iss.as9143.net ([212.54.57.96]:45836) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1nYs0V-000NsJ-31; Mon, 28 Mar 2022 16:14:15 +0000 Received: from [212.54.57.82] (helo=smtp3.tb.ukmail.iss.as9143.net) by smtpq1.tb.ukmail.iss.as9143.net with esmtp (Exim 4.90_1) (envelope-from ) id 1nYs0U-0002cZ-RE for zsh-workers@zsh.org; Mon, 28 Mar 2022 18:14:14 +0200 Received: from oxbe25.tb.ukmail.iss.as9143.net ([172.25.160.156]) by smtp3.tb.ukmail.iss.as9143.net with ESMTP id Ys0Un2ywEl7D1Ys0UnPmX5; Mon, 28 Mar 2022 18:14:14 +0200 X-Env-Mailfrom: p.w.stephenson@ntlworld.com X-Env-Rcptto: zsh-workers@zsh.org X-SourceIP: 172.25.160.156 X-CNFS-Analysis: v=2.4 cv=Xo7phHJ9 c=1 sm=1 tr=0 ts=6241ded6 cx=a_exe a=NA7IgXeTfPXpJV+SL5V8Rw==:117 a=wbvTLvLwOfMA:10 a=IkcTkHD0fZMA:10 a=7H6ixmLU1AQA:10 a=q2GGsy2AAAAA:8 a=NLZqzBF-AAAA:8 a=FHDqjHIkvDOFfqdxqXAA:9 a=QEXdDO2ut3YA:10 a=z9dJwno5l634igLiVhy-:22 a=wW_WBVUImv98JQXhvVPZ:22 X-Authenticated-Sender: p.w.stephenson@ntlworld.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ntlworld.com; s=meg.feb2017; t=1648484054; bh=nhHCv38Ef2DFBAZmr+9iCKTRF8wVi9xV+0a4Yk1FXUQ=; h=Date:From:To:Cc:In-Reply-To:References:Subject; b=3A54SrWvKoabe+xFSjT5HX1bg5EkI+NasFcg+f52ft7bObkHODBR/ExKU3E0nLexh 94i5io0Uv9P+VLhbUoaEzA26m8UXJLFkqMRT0/c/1AjrqYs17f4iMYcNe5f2B0QIaR 0izN9OvNMmIDlkfNOhWOxMMfNvj43zVzTVF3kVpn7uXH0XCVdaViw7vRLKgYRLHlHV W/qWyk2Y0SDlPg6Cprwv21qf0zbQysPGmZ+Yv50S8BFfIRC6xTQgb9+9DbKV5NV10p FjYn7TKzsxmXglr67ldnDht5ZdxcrfIduhwjsfOXNseFCEDEsFClAndLfwpFVFiZT1 CMsZGYtniDrgQ== Date: Mon, 28 Mar 2022 17:14:14 +0100 (BST) From: Peter Stephenson To: Bart Schaefer Cc: Zsh hackers list Message-ID: <1830314137.713553.1648484054367@mail2.virginmedia.com> In-Reply-To: References: <1409134730.698961.1648457237653@mail2.virginmedia.com> <1613542531.711035.1648478945973@mail2.virginmedia.com> Subject: Re: Crash on jobstates since workers/49783 (commit 6a8aa2a) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Medium X-Mailer: Open-Xchange Mailer v7.8.4-Rev72 X-Originating-IP: 147.161.167.85 X-Originating-Client: open-xchange-appsuite X-CMAE-Envelope: MS4xfNO7AyKPsgRYh+yAdx4jZoAmncLfzgyGdQM+Dqx0rHh/YJF6kDHjzUXFgbNKxV2SHroTins+gGsfOEmE/0eEvRmBbojnFrXnj8MMzKXAQ0041DD+4LlR izVjYFo3eZU0H8yj19pnQzWPB2w6qcG3tZfxfSref+M7J6pccslu7mZeAZmFUCUyzGPGTyNVMDdsbir6Pind1avo42B/QX1Zrez8X3cRhZrNCoLJFueAQXMR eP+xZnRcFuo1jmE0UfdBSJ0jFtsJ5aPhEAz49bfBdzM= X-Seq: 49903 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: > On 28 March 2022 at 16:09 Bart Schaefer wrote: > On Mon, Mar 28, 2022 at 7:49 AM Peter Stephenson > wrote: > > > > Just thinking the pukka way to do this is actually zero the PN fields > > in the saved job structure when we enter the subshell (unless we decide > > to preserve them properly, which is more work but should be possible). > > Looking at the way zargs was using subshells and $jobstates, I think > it's important that there be some way to distinguish jobs that the > subshell can't manage. > > % % sleep 5 & ( sleep 2 & print -aC2 ${(kv)jobstates} ) > [1] 68859 > 1 running:+ > 3 running: So this is a different issue, not directly related to the immediate cause of the crash though under the same general heading. Here we're overloading the meaning of "jobs" so instead of meaning "a real live job started with job control", which only applies to the top level shell, we're using it to mean "something we just started at the current process level which may or may not be a job in the Unix sense but which we can do processy stuff with". I don't think we can back out of doing the former with job states, that's the one people notice --- "jobs | where_my_job_gone" being the classic case, but if we're going to handle that we should be consistent. But the other case is a perfectly valid one. We have two options here: either keep jobstates for top level jobs and introduce a separate one for the last thing started in the current shell, or decide on the fly that we're no longer interested in the parent shell. In the former case we're going to end up with some combination of inconsistency and incompatibility however we do it. We can make the latter work something like the following by noticing we've just put something into the background. That's about as far as I think we can get relying on shell magic, though we should probably document it if we do it. This includes the previous fix (in the original simple form) with the test fix. pws diff --git a/Doc/Zsh/mod_parameter.yo b/Doc/Zsh/mod_parameter.yo index 2e3011e44..28c19f797 100644 --- a/Doc/Zsh/mod_parameter.yo +++ b/Doc/Zsh/mod_parameter.yo @@ -189,6 +189,10 @@ the var(state) describes the state of that process. Handling of the keys of the associative array is as described for tt(jobdirs) above. + +This parameter is available in a subshell, but only shows overall job +information, not process information. The information is current at the +point the subshell forks from the parent shell. ) vindex(nameddirs) item(tt(nameddirs))( diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index dbb61e474..2692766eb 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -1348,6 +1348,15 @@ pmjobstate(Job jtab, int job) else ret = dyncat("running", cp); + if (jtab != jobtab) + { + /* + * This is a saved job table so doesn't have current + * process information --- bail out now. + */ + return ret; + } + for (pn = jtab[job].procs; pn; pn = pn->next) { if (pn->status == SP_RUNNING) diff --git a/Src/exec.c b/Src/exec.c index f67074846..19463e7c6 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1689,6 +1689,7 @@ execpline(Estate state, wordcode slcode, int how, int last1) execpline2(state, code, how, opipe[0], ipipe[1], last1); pline_level--; if (how & Z_ASYNC) { + clearoldjobtab(); lastwj = newjob; if (thisjob == list_pipe_job) diff --git a/Src/jobs.c b/Src/jobs.c index 18e43f03c..ef097dde8 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -1733,6 +1733,18 @@ clearjobtab(int monitor) thisjob = initjob(); } +/* In a subshell, decide we want our own job table after all. */ + +/**/ +mod_export void +clearoldjobtab(void) +{ + if (oldjobtab) + free(oldjobtab); + oldjobtab = NULL; + oldmaxjob = 0; +} + static int initnewjob(int i) { jobtab[i].stat = STAT_INUSE; @@ -2449,6 +2461,7 @@ bin_fg(char *name, char **argv, Options ops, int func) case BIN_BG: case BIN_WAIT: if (func == BIN_BG) { + clearoldjobtab(); jobtab[job].stat |= STAT_NOSTTY; jobtab[job].stat &= ~STAT_CURSH; } diff --git a/Test/W03jobparameters.ztst b/Test/W03jobparameters.ztst index af889c6d5..21de47395 100644 --- a/Test/W03jobparameters.ztst +++ b/Test/W03jobparameters.ztst @@ -46,5 +46,5 @@ 0:$jobstate for running job in main shell and subshell *>\[1] [0-9]## *>running:+:*=running -*>running:+:*=running +*>running:+ *>zsh:*SIGHUPed*