Jiri 5079c0
From f7d7f594dcd5439bc05187361d55be720f07959e Mon Sep 17 00:00:00 2001
Jiri 5079c0
Message-Id: <f7d7f594dcd5439bc05187361d55be720f07959e.1334151133.git.jmoskovc@redhat.com>
Jiri 5079c0
From: Jiri Moskovcak <jmoskovc@redhat.com>
Jiri 5079c0
Date: Wed, 11 Apr 2012 15:31:34 +0200
Jiri 5079c0
Subject: [PATCH] pyhook: add timetout to sockets rhbz#808562
Jiri 5079c0
Jiri 5079c0
---
Jiri 5079c0
 src/hooks/abrt_exception_handler.py.in |   46 ++++++++++++++++++--------------
Jiri 5079c0
 1 file changed, 26 insertions(+), 20 deletions(-)
Jiri 5079c0
Jiri 5079c0
diff --git a/src/hooks/abrt_exception_handler.py.in b/src/hooks/abrt_exception_handler.py.in
Jiri 5079c0
index 9522a0f..cc00fc7 100644
Jiri 5079c0
--- a/src/hooks/abrt_exception_handler.py.in
Jiri 5079c0
+++ b/src/hooks/abrt_exception_handler.py.in
Jiri 5079c0
@@ -37,26 +37,32 @@ def write_dump(tb):
Jiri 5079c0
     try:
Jiri 5079c0
         import socket
Jiri 5079c0
         s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
Jiri 5079c0
-        s.connect(@VAR_RUN@ + "/abrt/abrt.socket")
Jiri 5079c0
-        s.sendall("PUT / HTTP/1.1\r\n\r\n")
Jiri 5079c0
-        s.sendall("PID=%s\0" % os.getpid())
Jiri 5079c0
-        s.sendall("EXECUTABLE=%s\0" % executable)
Jiri 5079c0
-        s.sendall("ANALYZER=Python\0")
Jiri 5079c0
-        s.sendall("BASENAME=pyhook\0")
Jiri 5079c0
-        # This handler puts a short(er) crash descr in 1st line of the backtrace.
Jiri 5079c0
-        # Example:
Jiri 5079c0
-        # CCMainWindow.py:1:<module>:ZeroDivisionError: integer division or modulo by zero
Jiri 5079c0
-        s.sendall("REASON=%s\0" % tb.splitlines()[0])
Jiri 5079c0
-        s.sendall("BACKTRACE=%s\0" % tb)
Jiri 5079c0
-        s.shutdown(socket.SHUT_WR)
Jiri 5079c0
-
Jiri 5079c0
-        # Read the response and log if there's anything wrong
Jiri 5079c0
-        response = ""
Jiri 5079c0
-        while True:
Jiri 5079c0
-            buf = s.recv(256)
Jiri 5079c0
-            if not buf:
Jiri 5079c0
-                break;
Jiri 5079c0
-            response += buf
Jiri 5079c0
+        s.settimeout(5)
Jiri 5079c0
+        try:
Jiri 5079c0
+            s.connect(@VAR_RUN@ + "/abrt/abrt.socket")
Jiri 5079c0
+            s.sendall("PUT / HTTP/1.1\r\n\r\n")
Jiri 5079c0
+            s.sendall("PID=%s\0" % os.getpid())
Jiri 5079c0
+            s.sendall("EXECUTABLE=%s\0" % executable)
Jiri 5079c0
+            s.sendall("ANALYZER=Python\0")
Jiri 5079c0
+            s.sendall("BASENAME=pyhook\0")
Jiri 5079c0
+            # This handler puts a short(er) crash descr in 1st line of the backtrace.
Jiri 5079c0
+            # Example:
Jiri 5079c0
+            # CCMainWindow.py:1:<module>:ZeroDivisionError: integer division or modulo by zero
Jiri 5079c0
+            s.sendall("REASON=%s\0" % tb.splitlines()[0])
Jiri 5079c0
+            s.sendall("BACKTRACE=%s\0" % tb)
Jiri 5079c0
+            s.shutdown(socket.SHUT_WR)
Jiri 5079c0
+
Jiri 5079c0
+
Jiri 5079c0
+            # Read the response and log if there's anything wrong
Jiri 5079c0
+            response = ""
Jiri 5079c0
+            while True:
Jiri 5079c0
+                buf = s.recv(256)
Jiri 5079c0
+                if not buf:
Jiri 5079c0
+                    break
Jiri 5079c0
+                response += buf
Jiri 5079c0
+        except socket.timeout, ex:
Jiri 5079c0
+            import syslog
Jiri 5079c0
+            syslog.syslog("communication with ABRT daemon failed: %s" % str(ex))
Jiri 5079c0
 
Jiri 5079c0
         s.close()
Jiri 5079c0
         parts = response.split()
Jiri 5079c0
-- 
Jiri 5079c0
1.7.10
Jiri 5079c0