Bug 681925

Summary: subscription-manager masks SIGPIPE when running virt-what, resulting in errors in shell commands
Product: Red Hat Enterprise Linux 6 Reporter: Chris Duryee <cduryee>
Component: subscription-managerAssignee: Chris Duryee <cduryee>
Status: CLOSED ERRATA QA Contact: John Sefler <jsefler>
Severity: high Docs Contact:
Priority: high    
Version: 6.1CC: bkearney, francisco_javier.pena, meyering, mkhusid, rjones, syeghiay
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 680935 Environment:
Last Closed: 2011-05-19 13:39:58 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On:    
Bug Blocks: 568421    
Attachments:
Description Flags
test.sh
none
hwprobe.patch none

Description Chris Duryee 2011-03-03 15:46:19 UTC
+++ This bug was initially created as a clone of Bug #680935 +++

There is a user report of subscription-manager having difficulty during fact gathering on vmware 7.

> [root@ice ~]# subscription-manager register --username=foo
> --password=Password --force
> The system with UUID 76blah1d-d7c1-4f1d-blah-7a2blah32ff6 has been
> unregistered
> /usr/sbin/virt-what: line 87: echo: write error: Broken pipe

running virt-what directly works fine.

Comment 2 Chris Duryee 2011-03-08 16:22:27 UTC
Grep is returning before the echo is done sending data, causing the broken pipe for some users in certain cases.

virt-what uses "grep -q $FOO", but it should likely be using "grep $FOO 2>&1 /dev/null" instead.

From the grep man page:

Portable shell scripts should avoid both -q and -s  and  should redirect standard and error output to /dev/null instead.

Comment 4 Richard W.M. Jones 2011-03-08 16:36:04 UTC
(In reply to comment #2)
> Grep is returning before the echo is done sending data, causing the broken pipe
> for some users in certain cases.
> 
> virt-what uses "grep -q $FOO", but it should likely be using "grep $FOO 2>&1
> /dev/null" instead.
> 
> From the grep man page:
> 
> Portable shell scripts should avoid both -q and -s  and  should redirect
> standard and error output to /dev/null instead.

Interesting thanks.

This bug is flagged for 6.1 which would make it very
urgent.  Are these flags correct?  If this is something
that very few users would encounter then I'd prefer to bump
it to 6.2.

Comment 9 Chris Duryee 2011-03-08 16:54:16 UTC
Here's some more info about the bug incidence/severity:

To my knowledge, one developer ran into it on a vmware vm, and a user also
reported it during the entitlement beta (again, on vmware). I was unable to
reproduce it locally, but it appears that if someone does get the error, they
will get it consistently.

The error doesn't cause any break in functionality, since the grep already
finished up and returned the appropriate value.

Let me know if you need more info for 6.1 vs 6.2 triaging.

Comment 10 Richard W.M. Jones 2011-03-08 16:56:17 UTC
(In reply to comment #5)           
> oddly enough, it works fine if I call it by itself:
> [root@ice ~]# virt-what
> vmware
> [root@ice ~]#
> But it looks like when subscription manager calls it, it chokes.

Thought: Is subscription manager leaking the SIGPIPE ignore mask
across the fork?

Comment 12 Richard W.M. Jones 2011-03-09 10:45:28 UTC
Created attachment 483155 [details]
test.sh

I'm fairly sure this is down to a bug in subscription
manager itself, leaking an incorrect SIGPIPE mask to the
child process (ie virt-what).

As an example of what I mean, take a look at the attached
shell script.

If you run this shell script from a normal shell, it won't
print anything:

$ ./test.sh

But if you run this script with an incorrect SIGPIPE mask
you will see the same error in grep:

$ perl -e '$SIG{PIPE}="IGNORE"; system("./test.sh")'
./test.sh: line 12: echo: write error: Broken pipe

Is the source for subscription-manager available somewhere
that I can take a look?

Comment 13 Richard W.M. Jones 2011-03-09 11:14:44 UTC
Created attachment 483159 [details]
hwprobe.patch

Turns out this is a misfeature of Python itself, see:

http://bugs.python.org/issue1652

You could try the attached *untested* patch against subscription-manager.
It works by setting the signal handler back to the default around the
exec of virt-what.

Comment 14 Bryan Kearney 2011-03-09 13:29:13 UTC
Thanks Richard!

Comment 15 Chris Duryee 2011-03-09 21:13:37 UTC
Fixed in rhel6 0.95.5+ 997bf58a829fc13e5eb92d3515cd053f8d0244ae 

fixed in master 0.96.2+ b5adbdd

Note that it's difficult to replicate this issue inside of subscription-manager, we've been relying on test cases with mock code. It might be best to just do a no-break test for this, but just let me know on IRC if you want to try to set up a test.

Comment 21 errata-xmlrpc 2011-05-19 13:39:58 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHEA-2011-0611.html