Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] problem with 'ls | less' shell function



On Mon, Nov 7, 2022 at 9:03 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> I'm sure someone is going to explain to me why the following is wrong.

Nobody has, yet.  However, after thinking for a while about this:

> What happens with the patch below is that in the right side of the
> pipeline, after the new subshell is created upon ^Z, "fg" resumes the
> previous foreground job (the earlier job in the right-side brace
> construct) and the new subshell remains stopped until that job
> finishes, at which point it is resumed and proceeds with the next job
> in the braces.

... it occurred to me that it might be accomplishing a superset of
this from 50874:

+                   /*
+                    * If we're in shell jobs on the right side of a pipeline
+                    * we should treat it like a job in the current shell.
+                    */
+                   if (inforeground == 2)
+                       inforeground = 1;

... and indeed, if I remove that bit of 50874 I'm still able to do
^Z/fg and ^C in all the previously hanging or re-suspending examples.
I like that there doesn't seem to be as much of a magic bullet as that
seemed to be.

Patch attached.
diff --git a/Src/exec.c b/Src/exec.c
index 2422dae91..d4e681887 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1899,8 +1899,12 @@ execpline(Estate state, wordcode slcode, int how, int last1)
 			break;
 		    }
 		}
-		else if (subsh && jn->stat & STAT_STOPPED)
-		    thisjob = newjob;
+		else if (subsh && jn->stat & STAT_STOPPED) {
+		    if (thisjob == newjob)
+			makerunning(jn);
+		    else
+			thisjob = newjob;
+		}
 		else
 		    break;
 	    }
diff --git a/Src/jobs.c b/Src/jobs.c
index 76c762ee5..4863962b9 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -564,12 +564,6 @@ update_job(Job jn)
 		     * when the job is finally deleted.
 		     */
 		    jn->stat |= STAT_ATTACH;
-		    /*
-		     * If we're in shell jobs on the right side of a pipeline
-		     * we should treat it like a job in the current shell.
-		     */
-		    if (inforeground == 2)
-			inforeground = 1;
 		}
 		/* If we have `foo|while true; (( x++ )); done', and hit
 		 * ^C, we have to stop the loop, too. */


Messages sorted by: Reverse Date, Date, Thread, Author