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