Commit e322db1f authored by Vangelis Koukis's avatar Vangelis Koukis
Browse files

Add SIGTERM handling to vncauthproxy

Install a signal handler for fatal signals using gevent.signal().
This allows vncauthproxy to unlink its control socket and exit
gracefully when SIGTERM is received.
parent ce2cfc7b
......@@ -27,8 +27,11 @@ import gevent
import rfb
from gevent import socket
from signal import SIGTERM
from gevent import signal
from gevent.select import select
class VncAuthProxy(gevent.Greenlet):
"""
Simple class implementing a VNC Forwarder with MITM authentication as a
......@@ -309,6 +312,11 @@ class VncAuthProxy(gevent.Greenlet):
self._handshake()
def fatal_signal_handler(signame):
logging.info("Caught %s, will raise SystemExit" % signame)
raise SystemExit
if __name__ == '__main__':
from optparse import OptionParser
......@@ -350,10 +358,17 @@ if __name__ == '__main__':
logging.info("Initalized, waiting for control connections at %s" %
opts.ctrl_socket)
# Catch SIGTERM to ensure graceful shutdown,
# e.g., to make sure the control socket gets unlink()ed.
#
# Uses gevent.signal so the handler fires even during
# gevent.socket.accept()
gevent.signal(SIGTERM, fatal_signal_handler, "SIGTERM")
while True:
try:
client, addr = ctrl.accept()
except KeyboardInterrupt:
except (KeyboardInterrupt, SystemExit):
break
logging.info("New control connection")
......@@ -379,5 +394,7 @@ if __name__ == '__main__':
VncAuthProxy.spawn(sport, daddr, dport, password, opts.connect_timeout)
client.close()
logging.info("Unlinking control socket at %s" %
opts.ctrl_socket)
os.unlink(opts.ctrl_socket)
sys.exit(0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment