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 1668 invoked from network); 29 Mar 2022 13:32:26 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 29 Mar 2022 13:32:26 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1648560746; b=Nm7Z+4ZVeOMd7GaSmbHVb4Tnd6OGwCX7YrIoLx/KZhe1UsOQ1u36Y7mojSJ106ppNB7BUDXQ3b XCTbsNiPPIWEqw/deK2PY6/foHZFnHKUV9isRYbQz5hJiuQ9gKJQLO0VnFoGwLfMfbtE+RGxc7 68DNaolQ1zh2jGGwNNbCeVb23b8/O1xXRtIGywo2VsH4rh4dcsbjs67p3YqW1N2nvwHk2Z8Eci 2UWyEdg+pCtzC1dGBfVGIZzOOEuer+a8+KN1MmQHSXxbqAB4+TrqX7ZCERdB7Nqr5QgamCJ/yy RFnQMpgf8ifT+H93RM1X4yIuXbAUUYeUang2pwUvn4E3rA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (smtpq2.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.97; 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=1648560746; bh=3Ueby7yJT6VnmclkYWXbjOrJF2+u1M2dCI1cLmT9MaU=; 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:To:From:Date:DKIM-Signature: DKIM-Signature; b=Kxq3BU+DCGaIt6+yqg4h377YwJgs7g4+TLoo4d4PEzu3QVKoZCY/gYNkWGnqOnHQAARayKjBeq 1AXZ2wqAmhnlpUWLuZ6dajNz8icdHMHeQaG7ccb2PN/EAUCQMewO/R1a91G6107SYuin03/EGH SnwAVFWqJvMfM6UxoOqU82pDpBX/48jwqGD6X8qD20iuEojkxO1LkIxSHHyizncmhor2owXezQ 6G0CoiGWvDnS3/qq1porELM1D0A63zFdJ1lv+aFxTXYr23OQ38BrjL4eQ1YYk/kc9Mutso6gLa dzyBY6CUpimIqIrCQ2OE3Yxf03A9OCKDEYo5czPSLqhi0w==; 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:To:From: Date:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=UPKctJXg9S1R5KSiuQsLd2qVeOKT/4KdFP23lDdHjUo=; b=TleM0vzW/TlZQ7Rb8LmkdgapD3 fjQ3r3DH/su6ctpJ3mW+q6wQ6CatnbQ2w2XKHOp51whKui+juRi3Cgknx8mk9U9dRcZz4TnKGgsge fWMOdG7AVvESZaHcls8d3WJ8zlNhtWxyzTVs5V+keqoKxWl9xVR5C6nO5yo2mgEBkcRSppkVfD3Cf rIuZB8lHKlhwbjgl1UppW/42jkl0c3M4rPW+ufGPa3MiH4DAbA4lJABNlQ/iRETPevEqmfNYPMm+O wbNoYbIfOTQEVbZD8UKhEMA0G63sHPMXy91gM8Ani0W55r1OTOotIidMURG9cCddaYyR1AcieUpx0 +zb2pV1w==; Received: from authenticated user by zero.zsh.org with local id 1nZBxR-0008ac-BZ; Tue, 29 Mar 2022 13:32:25 +0000 Authentication-Results: zsh.org; iprev=pass (smtpq2.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.97; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=pass header.from=ntlworld.com; arc=none Received: from smtpq2.tb.ukmail.iss.as9143.net ([212.54.57.97]:45342) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1nZBwr-0008Fx-4k; Tue, 29 Mar 2022 13:31:49 +0000 Received: from [212.54.57.80] (helo=smtp1.tb.ukmail.iss.as9143.net) by smtpq2.tb.ukmail.iss.as9143.net with esmtp (Exim 4.90_1) (envelope-from ) id 1nZBwq-0001tx-Tv for zsh-workers@zsh.org; Tue, 29 Mar 2022 15:31:48 +0200 Received: from oxbe25.tb.ukmail.iss.as9143.net ([172.25.160.156]) by smtp1.tb.ukmail.iss.as9143.net with ESMTP id ZBwqnFN7GBAYNZBwqnOhD6; Tue, 29 Mar 2022 15:31:48 +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=IZSU5Ema c=1 sm=1 tr=0 ts=62430a44 cx=a_exe a=NA7IgXeTfPXpJV+SL5V8Rw==:117 a=wbvTLvLwOfMA:10 a=IkcTkHD0fZMA:10 a=7H6ixmLU1AQA:10 a=NLZqzBF-AAAA:8 a=NEOl5_khyq2D53JTlf8A:9 a=QEXdDO2ut3YA:10 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=1648560708; bh=3Ueby7yJT6VnmclkYWXbjOrJF2+u1M2dCI1cLmT9MaU=; h=Date:From:To:In-Reply-To:References:Subject; b=XyDlblgPzJAycR6nQKtN/9vA7Jll468rd6B9V7iMQH+SLqQud5NVp1hUzlR0OVL4y kTTdtKfFSPHRqnEo61sgsxGU4rFSXcRf01S5jGmTfSfz9tRwEl9kr5b4Mo+249rsgq RaeXR1haOoHB/BuME1hyCvh5zODjiqZaYo2mwl84kdvnDB299rWGdO+Bxfw6+Gqmu+ /Cw/VQx5ocImyuoHMAJn1V/VVSDG1u/6x93KhkdvkbPb2gYHHCKgBpGkwjVPSkXCeZ L5Fj9Y24XI53VErDRRUC49eqB5mqc8G2k6MJgGGWpmWP4f1wjQ5odVVnrqbKENg/Ga waYh97BzYFvkg== Date: Tue, 29 Mar 2022 14:31:48 +0100 (BST) From: Peter Stephenson To: Zsh hackers list Message-ID: <532466271.737219.1648560708634@mail2.virginmedia.com> In-Reply-To: <1639573778.726687.1648544928144@mail2.virginmedia.com> References: <1409134730.698961.1648457237653@mail2.virginmedia.com> <1613542531.711035.1648478945973@mail2.virginmedia.com> <1830314137.713553.1648484054367@mail2.virginmedia.com> <1e36a19a15237624412bc502ebfcf99034dfbb79.camel@ntlworld.com> <1639573778.726687.1648544928144@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: MS4xfESNmyyzzKECRZQ08/a0ConUIbfCYTelSr+VkErannTRsvIMu6us9RVJddtAlBQolwKsjPEN94hcbiRg7/73MlFVQynXypOpvmZVMsv9Cr/RMoDDXO+Q Ved6TMEsLe0uoCl+EcFVHNToH82tySx2Aq4NMEXhW2xkT3OpNVMmMCSAmpPDBWt3XQZ5sOmVmPtjJg5CbJc7Tt749DNnCwVyPyTbpDCB2WL+hOEX1uvk1T+N X-Seq: 49911 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 29 March 2022 at 10:08 Peter Stephenson wrote: > I'll add documentation and tests to the patch for the other half and remove > changes to job state querying. See if the documentation in the first hunk makes any sense. pws diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 5649e00d4..1d74f0c17 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1114,6 +1114,24 @@ The tt(-Z) option replaces the shell's argument and environment space with the given string, truncated if necessary to fit. This will normally be visible in tt(ps) (manref(ps)(1)) listings. This feature is typically used by daemons, to indicate their state. + +Full job control is only available in the top-level interactive shell, +not in commands run in the left hand side of pipelines or within +the tt(LPAR())var(...)tt(RPAR()) construct. However, a snapshot +of the job state at that point is taken, so it is still possible +to use the tt(jobs) builtin, or any parameter providing job information. +This gives information about the state of jobs at the point the subshell +was created. If background processes are created within the subshell, +then instead information about those processes is provided. + +For example, + +example(sleep 10 & # Job in background +LPAR() # Shell forks +jobs # Shows information about "sleep 10 &" +sleep 5 & # Process in background (no job control) +jobs # Shows information about "sleep 5 &" +RPAR()) ) findex(kill) cindex(killing jobs) diff --git a/Doc/Zsh/mod_parameter.yo b/Doc/Zsh/mod_parameter.yo index 2e3011e44..f3bcd7957 100644 --- a/Doc/Zsh/mod_parameter.yo +++ b/Doc/Zsh/mod_parameter.yo @@ -165,6 +165,8 @@ The keys of the associative arrays are usually valid job numbers, and these are the values output with, for example, tt(${(k)jobdirs}). Non-numeric job references may be used when looking up a value; for example, tt(${jobdirs[%+]}) refers to the current job. + +See the tt(jobs) builtin for how job information is provided in a subshell. ) vindex(jobtexts) item(tt(jobtexts))( @@ -173,6 +175,8 @@ that were used to start the jobs. Handling of the keys of the associative array is as described for tt(jobdirs) above. + +See the tt(jobs) builtin for how job information is provided in a subshell. ) vindex(jobstates) item(tt(jobstates))( @@ -189,6 +193,8 @@ the var(state) describes the state of that process. Handling of the keys of the associative array is as described for tt(jobdirs) above. + +See the tt(jobs) builtin for how job information is provided in a subshell. ) vindex(nameddirs) item(tt(nameddirs))( 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..a6f7a09b1 100644 --- a/Test/W03jobparameters.ztst +++ b/Test/W03jobparameters.ztst @@ -48,3 +48,31 @@ *>running:+:*=running *>running:+:*=running *>zsh:*SIGHUPed* + +# $jobstates refers to a job started in the main shell unless +# one has been started in the subshell. In the latter case, +# the subshell has no job control so the job is not marked as current. + zpty_start + zpty_input "MODULE_PATH=${(q)MODULE_PATH}" + zpty_input 'sleep 3 &' + zpty_input '(print main; print $jobstates; sleep 2& print sub; print $jobstates)' + zpty_input 'jobs -s' + zpty_stop +0:$jobstate shows one job started in main shell or one started in subshell +*>\[1] [0-9]## +>main +*>running:+:*=running +>sub +*>running::*=running +*>zsh:*SIGHUPed* + +# output from zpty removes empty lines + zpty_start + zpty_input "MODULE_PATH=${(q)MODULE_PATH}" + zpty_input '(print main; print $jobstates; sleep 2& print sub; print $jobstates)' + zpty_input 'jobs -s' + zpty_stop +0:$jobstate shows no job started in main shell but one started in subshell +>main +>sub +*>running::*=running