zsh-users
 help / color / mirror / code / Atom feed
From: Ronan Pigott <rpigott314@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: zsh mysteriously suspending job with sudo
Date: Sun, 23 Feb 2020 16:57:39 -0700	[thread overview]
Message-ID: <CAG4d5BgKOghaqM5u7cz8iqTv0Nkjtd1_=maG+f1HpyWRVAPCPA@mail.gmail.com> (raw)
In-Reply-To: <CAG4d5BjCtWtecGqyh6sDivZ3w3bYSoMes3zFnHPwJFuTM62MmQ@mail.gmail.com>

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

Brilliant! Thank you Peter for the patch.

I have applied it to my zsh and pacman is working again.

On Sun, Feb 23, 2020 at 11:53 AM Ronan Pigott <rpigott314@gmail.com> wrote:

> Wow! Thank you Stephane for your analysis.
>
> So you think that a patch checking for ESRCH is not suitable?
>
> I tried poking around in Src/jobs.c in update_job where
> it sounds like this issue originates, but I'm not quite sure
> how the logic should be revised.
>
> Is there somewhere else where this bug should be reported?
>
> Thanks again for your help!
>
>
> On Sun, Feb 23, 2020 at 7:03 AM Stephane Chazelas <stephane@chazelas.org>
> wrote:
>
>> 2020-02-22 18:09:13 -0700, Ronan Pigott:
>> [...]
>> > $ sudo true
>> > [sudo] password for ronan:
>> > $ pacman -Qttdq | sudo pacman -Rns -
>> > [...]
>> > :: Do you want to remove these packages? [Y/n] zsh: done
>> >  pacman -Qttdq |
>> > zsh: suspended (tty output)  sudo pacman -Rns -
>> [...]
>>
>> Can be reproduced with:
>>
>> $ sleep 1 | sudo sh -c 'sleep 2; ps -jfHt "$(tty<&2)"; awk "{print \$8}"
>> /proc/self/stat /dev/tty'
>> UID        PID  PPID  PGID   SID  C STIME TTY          TIME CMD
>> chazelas 25430  8308 25430 25430  0 13:44 pts/1    00:00:00 /bin/zsh
>> root     26867 25430 26866 25430  0 13:46 pts/1    00:00:00   sudo sh -c
>> sleep 2; ps -jfHt "$(tty<&2)"; awk "{print \$8}" /proc/self/stat /dev/tty
>> root     26868 26867 26866 25430  0 13:46 pts/1    00:00:00     sh -c
>> sleep 2; ps -jfHt "$(tty<&2)"; awk "{print \$8}" /proc/self/stat /dev/tty
>> root     26871 26868 26866 25430  0 13:46 pts/1    00:00:00       ps
>> -jfHt /dev/pts/1
>> 25430
>> zsh: done                   sleep 1 |
>> zsh: suspended (tty input)  sudo sh -c
>>
>> As seen above, at the time "ps" is run (and awk later), the
>> foreground process group of the terminal is 25430 which is the
>> pgid of the main shell, not the pgid of the foreground job
>> (26866), which is why that job gets a SIGTTIN when awk tries to
>> read from the terminal (or SIGTTOU when pacman does an ioctl to
>> the terminal).
>>
>> From "strace", it seems it's because when "sleep 1" (the process
>> group leader) finishes, zsh does a kill(-26866,0), presumably to
>> check that the process group is still alive, but that fails with
>> EPERM as there are processes running as root in that group, and
>> then zsh changes the foreground process group back to the main
>> shell's.
>>
>> So it seems indeed to be a bug in zsh.
>>
>> I suppose an easy fix would be to check for an errno of ESRCH
>> when kill(-pgid,0) fails to make sure it's because the process
>> group is gone. But, here the shell should be able to know that
>> the job is not gone as sudo, a direct children of the shell has
>> not returned yet, so there's probably something wrong with the
>> logic in the first place.
>>
>> --
>> Stephane
>>
>

  reply	other threads:[~2020-02-23 23:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAG4d5Bg=vkj6PYYGVyNO3pWTh=RkT=2rTFdE_hPBj1xxz6YTSw__29611.299622205$1582420251$gmane$org@mail.gmail.com>
2020-02-23 14:03 ` Stephane Chazelas
2020-02-23 18:53   ` Ronan Pigott
2020-02-23 23:57     ` Ronan Pigott [this message]
2020-05-14 21:15       ` Ronan Pigott
2020-05-15  9:08         ` Peter Stephenson
2020-05-15  9:20           ` Ronan Pigott
2020-02-23 20:18   ` Peter Stephenson
2020-02-23  1:09 Ronan Pigott

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='CAG4d5BgKOghaqM5u7cz8iqTv0Nkjtd1_=maG+f1HpyWRVAPCPA@mail.gmail.com' \
    --to=rpigott314@gmail.com \
    --cc=zsh-users@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).