[sos-devel] [v2 PATCH] [plugin] fix recursive symlink handling

Kamalesh Babulal kamalesh at linux.vnet.ibm.com
Fri May 29 05:43:17 UTC 2015


symlink which points to itself, might exist in directories
mentioned in plugin(s) for collection/copying. With regular
symlink, we could create the link and copy the file but with
symlink pointing to itself, we end up in recursive loop. When
trying to follow the src, for creating link and copying it.

For example:
# ls -lstrh /etc/libvirt/qemu/networks/autostart/
total 0
0 lrwxrwxrwx. 1 root root 14 May 18 09:22 default.xml -> ../default.xml
0 lrwxrwxrwx. 1 root root  7 May 22 05:37 kop.xml -> kop.xml

Trying to copying such symlink, will ends up in following exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 1172, in collect
    plug.collect()
  File "/usr/lib/python2.7/site-packages/sos/plugins/__init__.py", line 630, in collect
    self._collect_copy_specs()
  File "/usr/lib/python2.7/site-packages/sos/plugins/__init__.py", line 600, in _collect_copy_specs
    self._do_copy_path(path)
  File "/usr/lib/python2.7/site-packages/sos/plugins/__init__.py", line 319, in _do_copy_path
    self._copy_symlink(srcpath)
  File "/usr/lib/python2.7/site-packages/sos/plugins/__init__.py", line 271, in _copy_symlink
    self._do_copy_path(absdest)
  File "/usr/lib/python2.7/site-packages/sos/plugins/__init__.py", line 319, in _do_copy_path
    self._copy_symlink(srcpath)
  File "/usr/lib/python2.7/site-packages/sos/plugins/__init__.py", line 261, in _copy_symlink
    self.archive.add_link(reldest, srcpath)
  File "/usr/lib/python2.7/site-packages/sos/archive.py", line 198, in add_link
    os.symlink(source, dest)
OSError: [Errno 17] File exists

Fix this recursive loop but just creating the link and skip copying
the symlink.

Signed-off-by: Kamalesh Babulal <kamalesh at linux.vnet.ibm.com>
Cc: Bryn M. Reeves <bmr at redhat.com>
---
v2:
  - Create the link and skip copying, if both src and dest are same.
  - Append the symlink to files, copied list.

v1:
   Initial version: Returns, if the source path does not exist.
 sos/plugins/__init__.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index 2a944ed..6cd3ddb 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -268,7 +268,12 @@ class Plugin(object):
         # to absolute paths to pass to _do_copy_path.
         self._log_debug("normalized link target '%s' as '%s'"
                         % (linkdest, absdest))
-        self._do_copy_path(absdest)
+
+        # skip recursive copying of symlink pointing to itself.
+        if (absdest != srcpath):
+            self._do_copy_path(absdest)
+        else:
+            self._log_debug("link '%s' is a self link, skipping..." % linkdest)
 
         self.copied_files.append({'srcpath': srcpath,
                                   'dstpath': srcpath,
-- 
2.1.2




More information about the sos-devel mailing list