vzmigrate: bind to localhost only

When setting up openssh port forwarding to be used by ploop copy
with feedback, make ssh listen only on localhost rather than any IP.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vznnc: add

This little proggie is added to replace socat in vzmigrate.

Problems with socat are:
 - one more dependency
 - can't get executed program exit code

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzmigrate: replace socat and bash with vznnc

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzmigrate: fix port forwarding

As vznnc listens at localhost, ssh -L remote_host argument should also
be localhost.

While at it, s/localhost/127.0.0.1/ so that ssh no longer relies on
proper 'localhost' record in /etc/hosts.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vznnc: use getopt

Make vznnc more flexible it in arguments parsing by using getopt.
As syntax is changed now, modify vzmigrate accordingly.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vznnc: minor refactoring

Move cl_addr and cl_len declaration to connect block.

Initialize cl_addr right at declaration.

Mark yes variable as const.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vznnc: check error from listen()

Although it's unlikely that listen() will fail, check its return
value just to be on the safe side.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vznnc: add poll() to check if stdin is alive

This is an attempt to solve a problem of stale vznnc.

vzmigrate runs vznnc -l via ssh in background, like this:

	ssh -L localhost:$port:localhost:$port $DEST vznnc -l $port $CMD &
	ssh_pid=$!

and then proceeds to other stuff. If that other stuff fails,
vzmigrate needs to do a rollback, so it kill ssh:

	kill -TERM $ssh_pid

The problem is while ssh itself is killed, vznnc on the $DEST is still
there sitting on accept(), not knowing that it's all gone.

The way this patch solves this is doing poll() on listening fd as well
as stdin and stdout. If there is data on listening fd it means we can
proceed as usual, calling connect(). If there's an error on stdin or
stdout it means we need to exit.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzmigrate: fix vznnc usage

As ploop copy contains options, we need to guard them from vznnc's
own options by using -- separator.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vznnc(8): explain -- separator

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vznnc(8): provide usage example

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vznnc: check that -p is set

Port number is required argument, so check it's supplied.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzncc: add -f FD option

If a program to run allows to specify a file descriptor to read from
and write to (ploop copy already does), we can keep its stdin/stdout
intact with this option.

This should help to see debug output from ploop copy (alas, sending
side only for now as receiving side stdout is redirected to /dev/null
by vzmigrate).

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzmigrate: use vznnc -f

See previous commit for explanation.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzmigrate: suppress error from kill -0

kill -0 $pid is used to check if the $pid is still there,
and if not we error out with an appropriate message.
It doesn't make sense to show an error from kill:

	kill: (1235) - No such process

so let's suppress it.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>