Hi,

As demonstrated by the script below, ksh discards saved exit status of
a job if it is followed by a subshell execution.

#!/bin/ksh
err () { return $1; }

(
err 12
) &
pid=$!
aa=$(/bin/date)
wait $pid
echo "(ret = $?)"

I read through the code and found this loop (src/cmd/ksh93/sh/jobs.c)
ends up discarding all entries in the saved status list (bck.list) via
job_chksave() when a subshell tries to restore the old status list:

void job_subrestore(void* ptr)
{
...
        for(jp=bck.list; jp; jp=jpnext)
        {
                jpnext = jp->next;
                if(jp->pid==sh.spid)
                {
                        jp->next = bp->list;
                        bp->list = jp;
                        bp->count++;
                }
                else
                        job_chksave(jp->pid);
        }
...
}

The comparison with sh.spid is also moot since sh.spid is never
anything other than 0. Attached is a patch that simply replaces this
loop with code that does the restore by appending the old list to the
current bck.list. This passes regression tests in ksh-20110415 as well
as fixes the above reproducer.

-- 
Siddhesh Poyarekar
http://siddhesh.in

Attachment: ksh-fix-subrestore.patch
Description: Binary data

_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to