fix for connecting to unix sockets
Costa Tsaousis (ktsaou) committed
Nov 12, 2016 at 16:24 UTC
8ea9254b14ef7b803a535a7c1253b6840a169e7f
1 file changed
+13
-12
python.d/python_modules/base.py
+13
-12
@@ -574,32 +574,33 @@ class SocketService(SimpleService):
574
self.__socket_config = res
575
return True
576
577
- def _connect2unixsocket(self, path=None):
577
+ def _connect2unixsocket(self):
578
"""
579
Connect to a unix socket, given its filename
580
:return: boolean
581
"""
582
- if path is None:
582
+ if self.unix_socket is None:
583
self.error("cannot connect to unix socket 'None'")
584
return False
585
586
try:
587
- self.debug("attempting DGRAM unix socket '" + str(path) + "'")
587
+ self.debug("attempting DGRAM unix socket '" + str(self.unix_socket) + "'")
588
self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
589
- self._sock.connect(path)
590
- self.debug("connected DGRAM unix socket '" + str(path) + "'")
589
+ self._sock.connect(self.unix_socket)
590
+ self.debug("connected DGRAM unix socket '" + str(self.unix_socket) + "'")
591
return True
592
except socket.error as e:
593
- self.error("Failed to connect DGRAM unix socket '" + str(path) + "':", str(e))
593
+ self.debug("Failed to connect DGRAM unix socket '" + str(self.unix_socket) + "':", str(e))
594
595
try:
596
- self.debug("attempting STREAM unix socket '" + str(path) + "'")
596
+ self.debug("attempting STREAM unix socket '" + str(self.unix_socket) + "'")
597
self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
598
- self._sock.connect(path)
599
- self.debug("connected STREAM unix socket '" + str(path) + "'")
598
+ self._sock.connect(self.unix_socket)
599
+ self.debug("connected STREAM unix socket '" + str(self.unix_socket) + "'")
600
return True
601
except socket.error as e:
602
- self.error("Failed to connect STREAM unix socket '" + str(path) + "':", str(e))
602
+ self.debug("Failed to connect STREAM unix socket '" + str(self.unix_socket) + "':", str(e))
603
+ self.error("Failed to connect to unix socket '" + str(self.unix_socket) + "':", str(e))
604
self._sock = None
605
return False
606
@@ -611,7 +612,7 @@ class SocketService(SimpleService):
612
"""
613
try:
614
if self.unix_socket is not None:
614
- _connect2unixsocket(self.unix_socket)
615
+ self._connect2unixsocket()
616
617
else:
618
if self.__socket_config is not None:
@@ -675,7 +676,7 @@ class SocketService(SimpleService):
676
break
677
678
if buf is None or len(buf) == 0: # handle server disconnect
678
- if len(data) == 0:
679
+ if data == "":
680
self._socketerror("unexpectedly disconnected")
681
else:
682
self.debug("server closed the connection")