From e1cc2687ef9208449080567207e1415336075d25 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 1 Jan 2015 10:43:01 +0100 Subject: [PATCH] spiceproxy: keep socket open on restart --- bin/spiceproxy | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/bin/spiceproxy b/bin/spiceproxy index 3a42e046..902880d3 100755 --- a/bin/spiceproxy +++ b/bin/spiceproxy @@ -61,17 +61,37 @@ sub init { my $lockfh = IO::File->new(">>${accept_lock_fn}") || die "unable to open lock file '${accept_lock_fn}' - $!\n"; - my $socket = IO::Socket::INET->new( - LocalAddr => undef, # all interfaces - LocalPort => 3128, - Listen => SOMAXCONN, - Proto => 'tcp', - ReuseAddr => 1) || - die "unable to create socket - $@\n"; + my ($socket, $sockfd); - # we often observe delays when using Nagle algorithm, - # so we disable that to maximize performance - setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1); + if (defined($sockfd = $ENV{PVE_DAEMON_SOCKET_3128}) && + $self->{env_restart_pve_daemon}) { + + die "unable to parse socket fd '$sockfd'\n" + if $sockfd !~ m/^(\d+)$/; + $sockfd = $1; # untaint + + $socket = IO::Socket::INET->new; + $socket->fdopen($sockfd, 'w') || + die "cannot fdopen file descriptor '$sockfd' - $!\n"; + + } else { + $socket = IO::Socket::INET->new( + LocalAddr => undef, # all interfaces + LocalPort => 3128, + Listen => SOMAXCONN, + Proto => 'tcp', + ReuseAddr => 1) || + die "unable to create socket - $@\n"; + + # we often observe delays when using Nagle algorithm, + # so we disable that to maximize performance + setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1); + + $ENV{PVE_DAEMON_SOCKET_3128} = $socket->fileno; + } + + # remove FD_CLOEXEC bit to reuse on exec + $socket->fcntl(Fcntl::F_SETFD(), 0); $self->{server_config} = { base_handler_class => 'PVE::API2',