Blame SOURCES/0074-plugin-handle-ELOOP-in-_copy_dir.patch

0cd6dc
From 7776566e8325a55712adc16f76e5497ae41a3df6 Mon Sep 17 00:00:00 2001
0cd6dc
From: "Bryn M. Reeves" <bmr@redhat.com>
0cd6dc
Date: Mon, 26 Jan 2015 14:57:01 +0000
0cd6dc
Subject: [PATCH 74/93] [plugin] handle ELOOP in _copy_dir()
0cd6dc
0cd6dc
A problem with systemd's management of the binfmt_misc automount
0cd6dc
point in Atomic environments causes attempts to access this path to
0cd6dc
fail with ELOOP:
0cd6dc
0cd6dc
  >>> import os
0cd6dc
  >>> os.listdir("/host/proc/sys/fs/binfmt_misc/")
0cd6dc
  Traceback (most recent call last):
0cd6dc
    File "<stdin>", line 1, in <module>
0cd6dc
  OSError: [Errno 2] No such file or directory: '/host/proc/sys/fs/binfmt_misc/'
0cd6dc
0cd6dc
For reasons that are not yet clear this causes the entire sos
0cd6dc
process to immediately terminate.
0cd6dc
0cd6dc
For now avoid the problem by enclosing the problem os.listdir in
0cd6dc
a try/except block that explicitly handles the one errno value
0cd6dc
implicated here.
0cd6dc
0cd6dc
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
0cd6dc
---
0cd6dc
 sos/plugins/__init__.py | 16 ++++++++++++----
0cd6dc
 1 file changed, 12 insertions(+), 4 deletions(-)
0cd6dc
0cd6dc
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
0cd6dc
index 394973d..456bae0 100644
0cd6dc
--- a/sos/plugins/__init__.py
0cd6dc
+++ b/sos/plugins/__init__.py
0cd6dc
@@ -27,6 +27,7 @@ import stat
0cd6dc
 from time import time
0cd6dc
 import logging
0cd6dc
 import fnmatch
0cd6dc
+import errno
0cd6dc
 
0cd6dc
 # PYCOMPAT
0cd6dc
 import six
0cd6dc
@@ -297,10 +298,17 @@ class Plugin(object):
0cd6dc
                                   'pointsto': linkdest})
0cd6dc
 
0cd6dc
     def _copy_dir(self, srcpath):
0cd6dc
-        for afile in os.listdir(srcpath):
0cd6dc
-            self._log_debug("recursively adding '%s' from '%s'"
0cd6dc
-                            % (afile, srcpath))
0cd6dc
-            self._do_copy_path(os.path.join(srcpath, afile), dest=None)
0cd6dc
+        try:
0cd6dc
+            for afile in os.listdir(srcpath):
0cd6dc
+                self._log_debug("recursively adding '%s' from '%s'"
0cd6dc
+                                % (afile, srcpath))
0cd6dc
+                self._do_copy_path(os.path.join(srcpath, afile), dest=None)
0cd6dc
+        except OSError as e:
0cd6dc
+            if e.errno == errno.ELOOP:
0cd6dc
+                msg = "Too many levels of symbolic links copying"
0cd6dc
+                self._log_error("_copy_dir: %s '%s'" % (msg, srcpath))
0cd6dc
+                return
0cd6dc
+            raise e
0cd6dc
 
0cd6dc
     def _get_dest_for_srcpath(self, srcpath):
0cd6dc
         if self.use_sysroot():
0cd6dc
-- 
0cd6dc
1.9.3
0cd6dc