Bug 754702 - detection of netcat's -q option is not working (at least on debian)
Summary: detection of netcat's -q option is not working (at least on debian)
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Virtualization Tools
Classification: Community
Component: virt-manager
Version: unspecified
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Cole Robinson
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-11-17 12:44 UTC by Matthias Witte
Modified: 2012-10-15 22:25 UTC (History)
3 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2012-01-25 16:48:17 UTC
Embargoed:


Attachments (Terms of Use)
Patch (2.29 KB, patch)
2011-11-17 12:44 UTC, Matthias Witte
no flags Details | Diff
fix netcat '-q' option detection (1.55 KB, patch)
2011-11-28 18:07 UTC, Matthias Witte
no flags Details | Diff
Add __str__() methods to classes Tunnel and Tunnels (1.65 KB, patch)
2011-11-28 18:08 UTC, Matthias Witte
no flags Details | Diff

Description Matthias Witte 2011-11-17 12:44:46 UTC
Created attachment 534184 [details]
Patch

Description of problem:

The detection whether netcat needs the '-q' Option does not work at
least when connecting from a squeeze client to a lenny server.

If you reopen a vnc Connection to a guest this will fail.

virt-manager has to be exited before you can open a new vnc connection
to that guest.  

Version-Release number of selected component (if applicable):

virt-manager 0.9.0

How reproducible:

Every time.

Steps to Reproduce:
1. Run virt-manager with Option '--debug' and look at the debug output

Addtionally check the nc commands run on the server:

$ nc -C nc -O command
  
Actual results:

netcat is run without the '-q 0' Option 

Expected results:

netcat should be run with the '-q 0' Option

Additional info:

Running the shell code as it is in console.py on the command line you get:

$ ssh -l foo vmhost sh -c 'nc -q 2>&1 | grep -q "requires an argument"; if [ $? -eq 0 ] ; then CMD="nc -q 0"; else CMD="nc"; fi; echo $CMD; hostname'

produces

nc
vmhost

If changed to:

$ ssh -l maz orla.srv.sipgate.net 'if nc -q 2>&1 | grep -q "requires an argument"; then CMD="nc -q 0"; else CMD="nc"; fi; echo $CMD; hostname'

the availability of the '-q' Option is correctly detected.

Comment 1 Matthias Witte 2011-11-22 13:48:01 UTC
That is supposed to be 'ps -C nc -O command' and not 'nc -C nc -O command'.

Comment 2 Cole Robinson 2011-11-27 19:58:59 UTC
Hmm, what shell are you using?

Can you provide the output of

nc -q

nc -q 2>&1 | grep -q "requires an argument"; if [ $? -eq 0 ] ; then CMD="nc -q 0"; else CMD="nc"; fi; echo $CMD; hostname

if nc -q 2>&1 | grep -q "requires an argument"; then CMD="nc -q 0"; else CMD="nc"; fi; echo $CMD; hostname

on both the client and the server (directly logged in, not running over ssh please).

Comment 3 Matthias Witte 2011-11-28 12:05:11 UTC
(In reply to comment #2)
> Hmm, what shell are you using?
> 
> Can you provide the output of
> 
> nc -q
> 
> nc -q 2>&1 | grep -q "requires an argument"; if [ $? -eq 0 ] ; then CMD="nc -q
> 0"; else CMD="nc"; fi; echo $CMD; hostname
> 
> if nc -q 2>&1 | grep -q "requires an argument"; then CMD="nc -q 0"; else
> CMD="nc"; fi; echo $CMD; hostname
> 
> on both the client and the server (directly logged in, not running over ssh
> please).

(In reply to comment #2)
> Hmm, what shell are you using?
> 
> Can you provide the output of
> 
> nc -q
> 
> nc -q 2>&1 | grep -q "requires an argument"; if [ $? -eq 0 ] ; then CMD="nc -q
> 0"; else CMD="nc"; fi; echo $CMD; hostname
> 
> if nc -q 2>&1 | grep -q "requires an argument"; then CMD="nc -q 0"; else
> CMD="nc"; fi; echo $CMD; hostname
> 
> on both the client and the server (directly logged in, not running over ssh
> please).

Hi Cole!

Here's the information you requested:

Shell Versions
--------------

- Client: GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)
- Server: GNU bash, version 3.2.39(1)-release (x86_64-pc-linux-gnu)


netcat output
-------------

- Server:
  $ nc -q
  nc: option requires an argument -- q
  usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]
            [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]
            [-x proxy_address[:port]] [hostname] [port[s]]

- Client:
  $ nc -q 
  nc: option requires an argument -- 'q'
  usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]
            [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]
            [-x proxy_address[:port]] [hostname] [port[s]]


netcat detection code
---------------------

- As used in virt-manager 0.900 on the server

$ nc -q 2>&1 | grep -q "requires an argument"; if [ $? -eq 0 ] ; then CMD="nc -q
 0"; else CMD="nc"; fi; echo $CMD; hostname
nc -q 0
servername.ourdomain.de

- As used by libvirt on the server

$ if nc -q 2>&1 | grep -q "requires an argument"; then CMD="nc -q 0"; else CMD="nc"; fi; echo $CMD; hostname
nc -q 0
servername.ourdomain.de

- As used in virt-manager 0.900 on the client

$ nc -q 2>&1 | grep -q "requires an argument"; if [ $? -eq 0 ] ; then CMD="nc -q
0"; else CMD="nc"; fi; echo $CMD; hostname
nc -q 0
workstation.ourdomain.de

-As used in libvirt on the client

$ if nc -q 2>&1 | grep -q "requires an argument"; then CMD="nc -q 0"; else CMD="nc"; fi; echo $CMD; hostname
nc -q 0
workstation.ourdomain.de

- virt-manager (0.900) version run through ssh on the server

$ ssh servername.ourdomain.de 'nc -q 2>&1 | grep -q "requires an argument"; if [ $? -eq 0 ] ; then CMD="nc -q 0"; else CMD="nc"; fi; echo $CMD; hostname'
nc -q 0
servername.ourdomain.de


- libvirt version run through ssh on the server

$ ssh servername.ourdomain.de 'if nc -q 2>&1 | grep -q "requires an argument"; then CMD="nc -q 0"; else CMD="nc"; fi; echo $CMD; hostname'
nc -q 0
servername.ourdomain.de

Comment 4 Cole Robinson 2011-11-28 12:40:42 UTC
hmm well they all seem to give expected results. what if you prepend the commands with 'sh -c' which is closer to what virt-manager is doing. Does that change the results?

Comment 5 Matthias Witte 2011-11-28 12:55:52 UTC
(In reply to comment #4)
> hmm well they all seem to give expected results. what if you prepend the
> commands with 'sh -c' which is closer to what virt-manager is doing. Does that
> change the results?

If run with 'sh -c' the detection will fail and CMD is set to 'nc'.

I decided to use the libvirt detection code in our patch, because that's 
the way it is done in libvirt.

Comment 6 Cole Robinson 2011-11-28 16:44:28 UTC
Ah okay, didn't realize that is how libvirt is doing it.

Can you verify that grep "requires an argument" >/dev/null also works? We previously made that change since grep -q isn't available on solaris IIRC.

Also please submit the patch with only the nc change. The logging changes are useful as well but should be submitted separately. Thanks!

Comment 7 Matthias Witte 2011-11-28 17:17:07 UTC
The nc_cmd change alone won't fix the problem. I also had to
change _try_login() where self.tunnels is evaluated. I would appreciate
if you had a look at that and check whether it is the way it should be done.

If the -q option to grep is not available redirection to /dev/null
seems to be an alternative and works here:

$ ssh servername.ourdomain.de 'if nc -q 2>&1 | grep "requires an argument" >/dev/null; then CMD="nc -q 0"; else CMD="nc"; fi; echo $CMD; hostname'
nc -q 0
servername.ourdomain.de

I will split the patch and resubmit.

Comment 8 Matthias Witte 2011-11-28 18:07:20 UTC
Created attachment 537582 [details]
fix netcat '-q' option detection

    In 0.9.0 open() in class Tunnel does not detect that netcat should be run
    with '-q 0' on debian and ubuntu systems.
    
    This patch ...
    
    ... changes the shell detection method to one similiar used in
        libvirts src/rpc/virnetsocket.c
    ... avoids the '-q' option to grep which is not available on solaris
    ... does not return from _try_login if self.tunnels is evaluated as true

Comment 9 Matthias Witte 2011-11-28 18:08:59 UTC
Created attachment 537583 [details]
Add __str__() methods to classes Tunnel and Tunnels

    - Add __str__() methods to classes Tunnel and Tunnels
    - Adds a debugging line to _try_login()

Comment 10 Cole Robinson 2012-01-25 16:48:17 UTC
Hmm, matthias there was another issue that was causing vnc consoles to not connect that has been fixed upstream. Can you try this patch:

http://git.fedorahosted.org/git/?p=virt-manager.git;a=commit;h=becf776d6af3455f6c89396e3ccc330cd2c85434

I'm pretty sure the issue is fixed, so closing this as upstream. Please reopen if you are still seeing issues

(I still don't know why nc detection was failing, but if after applying this patch, even if VNC console reconnection works, can you ensure that there aren't any stale 'nc' processes left hanging around on the client or server machine, even after virt-manager exits?)


Note You need to log in before you can comment on or make changes to this bug.