zsh-users
 help / color / mirror / code / Atom feed
* zsh mysteriously suspending job with sudo
@ 2020-02-23  1:09 Ronan Pigott
  0 siblings, 0 replies; 8+ messages in thread
From: Ronan Pigott @ 2020-02-23  1:09 UTC (permalink / raw)
  To: Zsh Users

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

Hello zsh users,

I've encountered an unusual bug using zsh and I finally have a reliable
reproduction so I'm looking for some insight. The issue is as follows:
===
$ 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 -
===

When I try to pipe a package list for pacman to read from stdin, the job is
mysteriously suspended by zsh when "pacman -Rns -" prompts [Y/n] for
confirmation to continue, before I have a chance to input anything. I have
not
input the SUSP character. The issue is also reproducible from a 'zsh -f' in
a
clean environment.

Trying to 'fg' the suspended job always results in the following error:
===
$ fg[1]  + done       pacman -Qttdq |
       continued  sudo pacman -Rns -
zsh: can't set tty pgrp: no such process
===

I can only reproduce in zsh, not bash. The issue also only occurs when sudo
*does not* prompt for a password, which is why I use a "sudo true" to
temporarily authorize my user before demonstrating the issue.

Bizarrely, the following examples all work as intended:
===
# with an extra file
$ pacman -Qttdq > packages.txt; cat packages.txt | sudo pacman -Rns -
[...]
:: Do you want to remove these packages? [Y/n]
# with an extra cat
$ pacman -Qttdq | cat - | sudo pacman -Rns -
[...]
:: Do you want to remove these packages? [Y/n]
# with process substitution
$ sudo pacman -Rns - < <(pacman -Qttdq)
[...]
:: Do you want to remove these packages? [Y/n]
===

To exonerate pacman, a user from #archlinux helped create a script that
exhibits
similar behavior:
===
$ cat read-and-prompt.sh#!/bin/sh --

exec 3<&1

while IFS= read -r input; do
    printf '%s\n' "$input" >&3
done

exec < /dev/tty
printf 'prompt: ' >&2
read -r _

exec "$@" <&3
$ for a in a b c; do print "$a"; sleep 1; done | sudo ./read-and-prompt.sh
cat
a
b
c
prompt:zsh: done                   for a in a b c; do; print "$a"; sleep 1;
done |
zsh: suspended (tty input)  sudo ./read-and-prompt.sh cat
===

They also report that they cannot reproduce using doas in place of sudo.

Considering the above, I believe my issue is a bug in either sudo or zsh,
hence
why I am asking here.

Why is zsh suspending this job? My understanding is that jobs are suspended
only
in response to a signal, but I do not know where it could be generated in
this
case.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-05-15  9:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAG4d5Bg=vkj6PYYGVyNO3pWTh=RkT=2rTFdE_hPBj1xxz6YTSw__29611.299622205$1582420251$gmane$org@mail.gmail.com>
2020-02-23 14:03 ` zsh mysteriously suspending job with sudo Stephane Chazelas
2020-02-23 18:53   ` Ronan Pigott
2020-02-23 23:57     ` Ronan Pigott
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

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).