aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Moravec <pmoravec@redhat.com>2018-08-22 10:35:58 +0200
committerBryn M. Reeves <bmr@redhat.com>2018-08-23 15:18:33 +0100
commitd5b1d349b868e66a4001c23dae7afa05daaca907 (patch)
treef049f8579646c3a6db49e91c55679eb35476db01
parent86e6843a61758fc17b13286c0c928efb97d15227 (diff)
downloadsos-d5b1d349b868e66a4001c23dae7afa05daaca907.tar.gz
[archive] Dont copystat /sys and /proc paths
Stop copying extended attributes of files under /sys and /proc that can raise SELinux denials on that attempt. Resolves: #1399 Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
-rw-r--r--sos/archive.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/sos/archive.py b/sos/archive.py
index fdf6f9a8..5d99170f 100644
--- a/sos/archive.py
+++ b/sos/archive.py
@@ -251,16 +251,17 @@ class FileCacheArchive(Archive):
pass
else:
self.log_info("caught '%s' copying '%s'" % (e, src))
- try:
- shutil.copystat(src, dest)
- except OSError:
- # SELinux xattrs in /proc and /sys throw this
- pass
+ # copy file attributes, skip SELinux xattrs for /sys and /proc
try:
stat = os.stat(src)
+ if src.startswith("/sys/") or src.startswith("/proc/"):
+ shutil.copymode(src, dest)
+ os.utime(dest, ns=(stat.st_atime_ns, stat.st_mtime_ns))
+ else:
+ shutil.copystat(src, dest)
os.chown(dest, stat.st_uid, stat.st_gid)
except Exception as e:
- self.log_debug("caught '%s' setting ownership of '%s'"
+ self.log_debug("caught '%s' setting attributes of '%s'"
% (e, dest))
file_name = "'%s'" % src
else: