From 965d0e5ba37f3e88aa38230177ad1c66814bf927 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Mon, 31 May 2010 11:36:14 +0200
Subject: [PATCH] Fix {Ignore, RetryOn}Signals on socket.error

Some confusion arose handling EINTR on those functions: in python 2.6
socket.error is an IOError, and thus:
  - It's an EnvironmentError
  - It has an .errno member

In 2.4 and 2.5 it's not, and so its errno variable must be extracted
from the args tuple. This patch fixes both functions, and the unittests.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/utils.py                  | 12 ++++++++----
 test/ganeti.utils_unittest.py |  2 --
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/lib/utils.py b/lib/utils.py
index f2f00b56b..df14049d4 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -566,10 +566,12 @@ def RetryOnSignal(fn, *args, **kwargs):
   while True:
     try:
       return fn(*args, **kwargs)
-    except (EnvironmentError, socket.error), err:
+    except EnvironmentError, err:
       if err.errno != errno.EINTR:
         raise
-    except select.error, err:
+    except (socket.error, select.error), err:
+      # In python 2.6 and above select.error is an IOError, so it's handled
+      # above, in 2.5 and below it's not, and it's handled here.
       if not (err.args and err.args[0] == errno.EINTR):
         raise
 
@@ -3001,10 +3003,12 @@ def IgnoreSignals(fn, *args, **kwargs):
   """
   try:
     return fn(*args, **kwargs)
-  except (EnvironmentError, socket.error), err:
+  except EnvironmentError, err:
     if err.errno != errno.EINTR:
       raise
-  except select.error, err:
+  except (select.error, socket.error), err:
+    # In python 2.6 and above select.error is an IOError, so it's handled
+    # above, in 2.5 and below it's not, and it's handled here.
     if not (err.args and err.args[0] == errno.EINTR):
       raise
 
diff --git a/test/ganeti.utils_unittest.py b/test/ganeti.utils_unittest.py
index d72232ba4..b329ad721 100755
--- a/test/ganeti.utils_unittest.py
+++ b/test/ganeti.utils_unittest.py
@@ -2224,9 +2224,7 @@ class TestIgnoreSignals(unittest.TestCase):
 
   def testIgnoreSignals(self):
     sock_err_intr = socket.error(errno.EINTR, "Message")
-    sock_err_intr.errno = errno.EINTR
     sock_err_inval = socket.error(errno.EINVAL, "Message")
-    sock_err_inval.errno = errno.EINVAL
 
     env_err_intr = EnvironmentError(errno.EINTR, "Message")
     env_err_inval = EnvironmentError(errno.EINVAL, "Message")
-- 
GitLab