zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Jun T <takimoto-j@kba.biglobe.ne.jp>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH] problem with 'ls | less' shell function
Date: Tue, 8 Nov 2022 21:03:43 -0800	[thread overview]
Message-ID: <CAH+w=7bwS+-0yb2EKdPadAs+s5R5ny4AZZHTExMZoKE-mhrB-g@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7ZOndCpJzfX7+SBFtc6aXv6EJPJT46V_aV2HkwivWs44g@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1196 bytes --]

On Mon, Nov 7, 2022 at 9:03 PM Bart Schaefer <schaefer@brasslantern.com> 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.

[-- Attachment #2: pipejobs3.txt --]
[-- Type: text/plain, Size: 993 bytes --]

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. */

  reply	other threads:[~2022-11-09  5:04 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17  9:17 Thomas Klausner
2022-10-17 14:50 ` Mikael Magnusson
2022-10-17 15:36   ` Thomas Klausner
2022-10-19  8:26     ` zsugabubus
2022-10-19 10:04       ` Jun T
2022-10-19 13:36         ` Jun. T
2022-10-20  0:10       ` Bart Schaefer
2022-10-20 16:26         ` Peter Stephenson
2022-10-21  5:45       ` Jun T
2022-10-21  7:40         ` Jun T
2022-10-21 21:22           ` Bart Schaefer
2022-10-21 21:24             ` Bart Schaefer
2022-10-22 23:22               ` Bart Schaefer
2022-10-22 23:43                 ` Bart Schaefer
2022-11-03 23:10                   ` Bart Schaefer
2022-11-04  6:09                     ` [PATCH] " Bart Schaefer
2022-11-04 15:10                       ` [PATCH] " Jun T
2022-11-05  0:09                         ` Bart Schaefer
2022-11-06 19:12                           ` Bart Schaefer
2022-11-07  8:43                             ` Jun T
2022-11-07 19:33                               ` Bart Schaefer
2022-11-07 19:44                                 ` Roman Perepelitsa
2022-11-08  0:46                                   ` Bart Schaefer
2022-11-08  0:44                                 ` Bart Schaefer
2022-11-08  5:03                                   ` Bart Schaefer
2022-11-09  5:03                                     ` Bart Schaefer [this message]
2022-10-19  9:33 ` Jun T
2022-10-19 10:01   ` Jun T

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7bwS+-0yb2EKdPadAs+s5R5ny4AZZHTExMZoKE-mhrB-g@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=takimoto-j@kba.biglobe.ne.jp \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).