Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [Bug] $jobstates does not work in $()
Peter Stephenson wrote on Tue, 01 Mar 2022 10:40 +00:00:
>> On 01 March 2022 at 00:46 Carl Agrell <caagr98@xxxxxxxxx> wrote:
>>
>>
>> It appears that zsh/parameter's $jobstates is always empty inside $(),
>> probably because it's a subshell of some sort. `jobs` still works
>> however, making it rather incongruous. Having access to $jobstates
>> would be useful for prompts for example, rather than having to parse
>> the output of `jobs`.
>>
>> To reproduce:
>> ❯ sleep 1000 &
>> [1] 210460
>> ❯ jobs
>> [1] + running sleep 1000
>> ❯ echo $jobstates
>> running:+:210460=running
>> ❯ echo $(jobs)
>> [1] + running sleep 1000
>> ❯ echo $(echo $jobstates)
>> (empty)
>
> Yes, we store the old job table for use with the builtin, but not with
> parameters, which is inconsistent.
>
> What is probably worse is that some parameters (not, as it happens,
> jobstates) call getjob(), which does have the logic to switch to the old
> table, but then make no attempt to switch to the right table for the
> remainder of the processing, which could result in undefined behaviour.
>
> This fixes it up with a function selectjobtab() used to query job states
> in the parameter functions as well as getjob().
>
Is this testable? Sorry, haven't got time to write a test myself right now.
Cheers,
Daniel
> --- a/Src/Modules/parameter.c
> +++ b/Src/Modules/parameter.c
> @@ -1244,19 +1244,19 @@ histwgetfn(UNUSED(Param pm))
> @@ -1269,22 +1269,25 @@ static HashNode
> @@ -1297,22 +1300,25 @@ static void
> @@ -1323,7 +1329,7 @@ scanpmjobtexts(UNUSED(HashTable ht), ScanFunc
> @@ -1335,14 +1341,14 @@ pmjobstate(int job)
> @@ -1371,21 +1377,24 @@ static HashNode
> @@ -1398,22 +1407,25 @@ static void
> @@ -1424,11 +1436,11 @@ scanpmjobstates(UNUSED(HashTable ht), ScanFunc
> @@ -1437,21 +1449,24 @@ static HashNode
> @@ -1464,22 +1479,25 @@ static void
> --- a/Src/jobs.c
> +++ b/Src/jobs.c
> @@ -98,10 +98,12 @@ mod_export int jobtabsize;
> @@ -1894,6 +1896,26 @@ setcurjob(void)
> @@ -1904,13 +1926,7 @@ getjob(const char *s, const char *prog)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author