From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 1b4403e8 for ; Sun, 23 Feb 2020 14:04:30 +0000 (UTC) Received: (qmail 13337 invoked by alias); 23 Feb 2020 14:04:20 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 24708 Received: (qmail 20957 invoked by uid 1010); 23 Feb 2020 14:04:20 -0000 X-Qmail-Scanner-Diagnostics: from relay1-d.mail.gandi.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.2/25725. spamassassin: 3.4.2. Clear:RC:0(217.70.183.193):SA:0(-2.6/5.0):. Processed in 2.005844 secs); 23 Feb 2020 14:04:20 -0000 X-Envelope-From: stephane@chazelas.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _nblcust.gandi.net designates 217.70.183.193 as permitted sender) X-Originating-IP: 2.121.21.5 Date: Sun, 23 Feb 2020 14:03:37 +0000 From: Stephane Chazelas To: Ronan Pigott Cc: Zsh Users Subject: Re: zsh mysteriously suspending job with sudo Message-ID: <20200223140337.ol24h5ioisdulusw@chazelas.org> Mail-Followup-To: Ronan Pigott , Zsh Users References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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