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: problem with 'ls | less' shell function
Date: Thu, 3 Nov 2022 16:10:24 -0700	[thread overview]
Message-ID: <CAH+w=7aHnvZ--v1fdpzvaTw7fZvqRVnPRN6HWU2gvXEYpGvsVg@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7bsNMzDS-Lc+zAO9CJUKjUAqvpjttwOXhO2y1h3P0BSLA@mail.gmail.com>

On Sat, Oct 22, 2022 at 4:43 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> So as far as zsh knows, the attachtty() was successful, but if the
> debugger is telling the truth, something is resetting the tty pgrp
> again without attachtty() being called.

A little further ... I instrumented jobs.c:makerunning() --

% dir() { ls -lrRt | less }
% dir
^Z
% fg
makerunning: PID 79731 job 1 jn->stat: 9427
makerunning: PID 79731 job 2 jn->stat: 370
[1]  + continued  ls -lrRt |
makerunning: PID 79731 job 1 jn->stat: 9425
makerunning: PID 79731 job 2 jn->stat: 368
zsh: suspended (tty output)  ls -lrRt |
zsh: suspended (tty output)  ls -lrRt |

With an anonymous function instead of a named one, this doesn't happen
and "fg" works:

% () { ls -lrRt | less }
^Z
% fg
makerunning: PID 79731 job 3 jn->stat: 82
[3]  - continued  ls -lrRt |
makerunning: PID 79731 job 3 jn->stat: 80

9427 is CHANGED|STOPPED|LOCKED|INUSE|SUPERJOB|CURSH|SUBLEADER
370 is STOPPED|LOCKED|NOPRINT|INUSE|SUBJOB
82 is STOPPED|LOCKED|INUSE

So we can remove at least one makerunning(), I think from bin_fg().
But I then instrumented update_job() where "continued..." is printed,
and:

% fg
[1]  + suspended  ls -lrRt |
makerunning: PID 687 job 1 jn->stat: 9427
makerunning: PID 687 job 2 jn->stat: 370
zsh: wait_for_processes after SIGCHLD
zsh: update_job signals.c L559
zsh: update_job signals.c L559
update_job: stopping gleader
zsh: suspended (tty output)  ls -lrRt |
zsh: suspended (tty output)  ls -lrRt |

Aha.  So there's a race condition of sorts, just one that we always
lose.  We send a SIGCONT to the process group for the forked job,
which wakes up both the subjob and the superjob, but when we get the
SIGCHLD for the subjob we decide that its superjob is running not
because we just restarted it, but because it is still waiting to be
stopped from the previous SIGTSTP.  I haven't worked out if this means
there's an order of signal delivery issue or just that we botched some
internal state.


  reply	other threads:[~2022-11-03 23:10 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 [this message]
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
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=7aHnvZ--v1fdpzvaTw7fZvqRVnPRN6HWU2gvXEYpGvsVg@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).