Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zsh mysteriously suspending job with sudo
- X-seq: zsh-users 24708
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Ronan Pigott <rpigott314@xxxxxxxxx>
- Subject: Re: zsh mysteriously suspending job with sudo
- Date: Sun, 23 Feb 2020 14:03:37 +0000
- Cc: Zsh Users <zsh-users@xxxxxxx>
- In-reply-to: <CAG4d5Bg=vkj6PYYGVyNO3pWTh=RkT=2rTFdE_hPBj1xxz6YTSw__29611.299622205$1582420251$gmane$org@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mail-followup-to: Ronan Pigott <rpigott314@xxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAG4d5Bg=vkj6PYYGVyNO3pWTh=RkT=2rTFdE_hPBj1xxz6YTSw__29611.299622205$1582420251$gmane$org@mail.gmail.com>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author