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.
That is supposed to be 'ps -C nc -O command' and not 'nc -C nc -O command'.
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). (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
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?
(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.
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!
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.
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
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()
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?)