Cleanup Unix domain socket file on exit
diff --git a/shadowsocks/manager.py b/shadowsocks/manager.py
index 62f187e61..ba072fa27 100644
--- a/shadowsocks/manager.py
+++ b/shadowsocks/manager.py
@@ -18,6 +18,8 @@
 from __future__ import absolute_import, division, print_function, \
     with_statement
 
+import os
+import atexit
 import errno
 import traceback
 import socket
@@ -35,6 +37,9 @@
 class Manager(object):
 
     def __init__(self, config):
+        atexit.register(self.cleanup)
+        self._is_unix = False
+        self._mngr_address = None
         self._config = config
         self._relays = {}  # (tcprelay, udprelay)
         self._loop = eventloop.EventLoop()
@@ -57,6 +62,8 @@ def __init__(self, config):
             else:
                 addr = manager_address
                 family = socket.AF_UNIX
+                self._is_unix = True
+                self._mngr_address = manager_address
             self._control_socket = socket.socket(family,
                                                  socket.SOCK_DGRAM)
             self._control_socket.bind(addr)
@@ -78,6 +85,13 @@ def __init__(self, config):
             a_config['password'] = password
             self.add_port(a_config)
 
+    def cleanup(self):
+        if self._is_unix:
+            try:
+                os.unlink(self._mngr_address)
+            except:
+                pass
+
     def add_port(self, config):
         port = int(config['server_port'])
         servers = self._relays.get(port, None)

Subj