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=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,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 c79bb789 for ; Sun, 23 Feb 2020 18:54:26 +0000 (UTC) Received: (qmail 27367 invoked by alias); 23 Feb 2020 18:54:17 -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: 24709 Received: (qmail 10852 invoked by uid 1010); 23 Feb 2020 18:54:17 -0000 X-Qmail-Scanner-Diagnostics: from mail-vs1-f45.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.2/25731. spamassassin: 3.4.2. Clear:RC:0(209.85.217.45):SA:0(-1.7/5.0):. Processed in 1.518738 secs); 23 Feb 2020 18:54:17 -0000 X-Envelope-From: rpigott314@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.217.45 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=uJSI65RcNGM2ZQev8ENaR12UFOCsdG7QkCZ98Esekf8=; b=ZaTmsQg0QRsxsyKwjua8eiQtSgLzI9wWUrx8UHx12YSSbKvPCSaf3v+csOZPscq12Y VklQzAUn2brju5ncMTfN0jDa4QANt3hzNF/zwjX+OuGiJpIs1lVYcy7lGDOvUy0+BwIw /kCLS/E7+VB655mXck4Bvg9fU1rz55jfbtkP8VVEOBEi2qWEMrtpWeGtl+yc7tO+NFoi dOg//0oqj998vHL+uO7z/MEg5gGPpgMvSnf+leyQ4JBnfh6jBsHnJcdGpQquKI0qNpgE qKZ871rEvFvZn9WSc5NVdHG2FltwP4siew0Xjnc7cJ7l83LdkFhH433KwVcBaOjkgAgK MN4A== X-Gm-Message-State: APjAAAWntFpET8qEkdqoxwKN0a1q0609QyB9L9rfdTkHZ0P5MzDM3/re Ybj7/QfqX8fF6mDNMxoq9euHn5inWGBTIB7KeA== X-Google-Smtp-Source: APXvYqyXxgWduatGlF8/bhGFQg8iDlFSXtgKxFZAMC2O6GlE0kSFaSBoZN6TyYUmW+HmQ3hGZ5nLUacEDqeVikQh4lE= X-Received: by 2002:a67:fd0d:: with SMTP id f13mr23832557vsr.125.1582484021028; Sun, 23 Feb 2020 10:53:41 -0800 (PST) MIME-Version: 1.0 References: <20200223140337.ol24h5ioisdulusw@chazelas.org> In-Reply-To: <20200223140337.ol24h5ioisdulusw@chazelas.org> From: Ronan Pigott Date: Sun, 23 Feb 2020 11:53:30 -0700 Message-ID: Subject: Re: zsh mysteriously suspending job with sudo To: stephane@chazelas.org, Zsh Users Content-Type: multipart/alternative; boundary="000000000000efabab059f42c574" --000000000000efabab059f42c574 Content-Type: text/plain; charset="UTF-8" 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 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 > --000000000000efabab059f42c574--