curjob in sub-shells?

dana <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <[email protected]>
i was writing some job tests and i noticed this:

  % zsh -fc '( sleep 3 &; disown; jobs ); :'
  zsh:disown:1: no current job
  [2]    running    sleep 3

this is because disown without an argument operates on curjob, and
spawnjob() doesn't update curjob in sub-shells. (for the same reason,
you can't use `kill %%` etc. but `disown %2` or `kill %2` would work)

i tried changing that and it seemed mostly ok, but it caused a test in
W03 to fail. it has this comment:

  # $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.

i don't understand. what would be the negative consequences of marking
the job as current in a sub-shell?

fwiw: dash, bash, and ksh93 all show the job as current. disown and
`kill %%` work as expected in bash, with or without monitor. `kill %%`
works in ksh93; i'm not sure if disown does because ksh93 disown doesn't
actually remove jobs from the job table. neither works in dash

below is the change i made

dana


diff --git a/Src/jobs.c b/Src/jobs.c
index 2ce5f8254..10ce965a3 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -1896,21 +1896,19 @@ spawnjob(void)
     Process pn;
 
     DPUTS(thisjob == -1, "No valid job in spawnjob.");
-    /* if we are not in a subshell */
-    if (!subsh) {
-	if (curjob == -1 || !(jobtab[curjob].stat & STAT_STOPPED)) {
-	    curjob = thisjob;
-	    setprevjob();
-	} else if (prevjob == -1 || !(jobtab[prevjob].stat & STAT_STOPPED))
-	    prevjob = thisjob;
-	if (jobbing && jobtab[thisjob].procs) {
-	    FILE *fout = shout ? shout : stdout;
-	    fprintf(fout, "[%d]", thisjob);
-	    for (pn = jobtab[thisjob].procs; pn; pn = pn->next)
-		fprintf(fout, " %ld", (long) pn->pid);
-	    fprintf(fout, "\n");
-	    fflush(fout);
-	}
+    if (curjob == -1 || !(jobtab[curjob].stat & STAT_STOPPED)) {
+	curjob = thisjob;
+	setprevjob();
+    } else if (prevjob == -1 || !(jobtab[prevjob].stat & STAT_STOPPED))
+	prevjob = thisjob;
+
+    if (!subsh && jobbing && jobtab[thisjob].procs) {
+	FILE *fout = shout ? shout : stdout;
+	fprintf(fout, "[%d]", thisjob);
+	for (pn = jobtab[thisjob].procs; pn; pn = pn->next)
+	    fprintf(fout, " %ld", (long) pn->pid);
+	fprintf(fout, "\n");
+	fflush(fout);
     }
     if (!hasprocs(thisjob))
 	deletejob(jobtab + thisjob, 0);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.