Is `dpkg --contents` unable to handle SIGPIPE?

l0b*_*0b0 6 shell dpkg

I noticed a weird antipattern in some CI scripts I've taken over, which basically boils down to this code checking whether a particular file is present in a package:

dpkg --contents some.deb > contents.txt
grep --quiet foo contents.txt
Run Code Online (Sandbox Code Playgroud)

I tried the obvious refactor of dpkg --contents some.deb | grep --quiet foo, but I keep getting this error:

dpkg-deb: error: tar subprocess was killed by signal (Broken pipe)

From some more investigation, this is definitely a timing issue. If I use a regex which matches early in the input stream I get the error, but if I use a regex which specifically matches a late line it succeeds.

The most obvious conclusion is that dpkg (or possibly tar) does something wrong with SIGPIPE. Is this a known issue?

Platform:

# lsb_release --all
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.6 LTS
Release:    18.04
Codename:   bionic
# dpkg --version
Debian 'dpkg' package management program version 1.19.0.5 (amd64).
This is free software; see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.
# tar --version
tar (GNU tar) 1.29
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.
Run Code Online (Sandbox Code Playgroud)

Ste*_*itt 6

dpkg用于tar列出包内容。当tarcan\xe2\x80\x99t 处理完整的存档时,表示发生错误,并且 \xe2\x80\x99dpkg是报告的内容。这两个命令都认为无法完成任务是一个错误,并采取相应的行动。

\n

您可以通过确保grep在退出之前读取其所有输入来避免这种情况:

\n
| grep foo > /dev/null\n
Run Code Online (Sandbox Code Playgroud)\n

(而不是-q,一旦匹配就退出)。

\n