wpaspy: Do not leave socket files behind if connection fails
authorJouni Malinen <j@w1.fi>
Tue, 31 Dec 2013 13:43:17 +0000 (15:43 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 31 Dec 2013 13:45:18 +0000 (15:45 +0200)
Ctrl::__init__ needs to handle socket.connect() exceptions and unlink
the client socket file on failures.

Signed-hostap: Jouni Malinen <j@w1.fi>

wpaspy/wpaspy.py

index 9836c2d..7c2314d 100644 (file)
@@ -22,7 +22,12 @@ class Ctrl:
         self.local = "/tmp/wpa_ctrl_" + str(os.getpid()) + '-' + str(counter)
         counter += 1
         self.s.bind(self.local)
-        self.s.connect(self.dest)
+        try:
+            self.s.connect(self.dest)
+        except Exception, e:
+            self.s.close()
+            os.unlink(self.local)
+            raise
         self.started = True
 
     def __del__(self):