August 22, 2009

Add support for unix socket in gnu-netcat

Filed under: Uncategorized — Tags: , , , , , , , , , — xiwen @ 10:50 pm

virsh from the libvirt package uses netcat to communicate with a remote server (in fact the command is executed locally on the remote server):
command -p port [-l username] hostname netcat -U socket
from: libvirt> Remote support> Extra parameters

However, the server I’m testing with runs Arch Linux; virt-manager, libvirt and its dependencies were installed through AUR; In the list of dependencies the OpenBSD implementation of netcat wasn’t listed. I’m aware Debian has ported it. The special feature in this netcat re-write is support for UNIX socket. As libvirt uses UNIX socket to communicate, the gnu-netcat cannot be used; it doesn’t understand the -U flag. The error happens when you try to connect to a remote server through a SSH tunnel:
virsh -d 5 -c qemu+ssh://somehost/system list

If the netcat binary on the remote host doesn’t understand -U, it will fail.

A quick dirty fix, more like a workaround, is to use a wrapper. socat‘s speciality is socket. We can use it like this:

  • rename original netcat: mv /usr/bin/netcat /usr/bin/netcat.orig
  • create the wrapper /usr/bin/netcat with as content:
  • 	#!/bin/sh
    	if [ "$1" == "-U" ]; then socat - unix-client:$2
    	else netcat.orig $@
    	fi
  • chmod 755 /usr/bin/netcat

And you’re ready to rock :)

On the long run libvirt shouldn’t rely on the OpenBSD implementation of netcat. As there’s only a few Linux distributions out there that adopted this rewrite. Perhaps give the user the freedom to choose which socket-tool to use in the configuration file?


No related posts.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

43 queries. 0.346 seconds. Powered by WordPress. CopyLeft CINAQ v9.
Best served with Firefox and/or Safari!