Revision 33c82017 vncauthproxy/vncauthproxy.py
b/vncauthproxy/vncauthproxy.py | ||
---|---|---|
27 | 27 |
import rfb |
28 | 28 |
|
29 | 29 |
from gevent import socket |
30 |
from signal import SIGTERM |
|
31 |
from gevent import signal |
|
30 | 32 |
from gevent.select import select |
31 | 33 |
|
34 |
|
|
32 | 35 |
class VncAuthProxy(gevent.Greenlet): |
33 | 36 |
""" |
34 | 37 |
Simple class implementing a VNC Forwarder with MITM authentication as a |
... | ... | |
309 | 312 |
self._handshake() |
310 | 313 |
|
311 | 314 |
|
315 |
def fatal_signal_handler(signame): |
|
316 |
logging.info("Caught %s, will raise SystemExit" % signame) |
|
317 |
raise SystemExit |
|
318 |
|
|
319 |
|
|
312 | 320 |
if __name__ == '__main__': |
313 | 321 |
from optparse import OptionParser |
314 | 322 |
|
... | ... | |
350 | 358 |
logging.info("Initalized, waiting for control connections at %s" % |
351 | 359 |
opts.ctrl_socket) |
352 | 360 |
|
361 |
# Catch SIGTERM to ensure graceful shutdown, |
|
362 |
# e.g., to make sure the control socket gets unlink()ed. |
|
363 |
# |
|
364 |
# Uses gevent.signal so the handler fires even during |
|
365 |
# gevent.socket.accept() |
|
366 |
gevent.signal(SIGTERM, fatal_signal_handler, "SIGTERM") |
|
367 |
|
|
353 | 368 |
while True: |
354 | 369 |
try: |
355 | 370 |
client, addr = ctrl.accept() |
356 |
except KeyboardInterrupt:
|
|
371 |
except (KeyboardInterrupt, SystemExit):
|
|
357 | 372 |
break |
358 | 373 |
|
359 | 374 |
logging.info("New control connection") |
... | ... | |
379 | 394 |
VncAuthProxy.spawn(sport, daddr, dport, password, opts.connect_timeout) |
380 | 395 |
client.close() |
381 | 396 |
|
397 |
logging.info("Unlinking control socket at %s" % |
|
398 |
opts.ctrl_socket) |
|
382 | 399 |
os.unlink(opts.ctrl_socket) |
383 | 400 |
sys.exit(0) |
Also available in: Unified diff