1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
From 8bab5dece7699774bb74417ef3d7913e802db2e1 Mon Sep 17 00:00:00 2001
From: Louis Bouchard <louis.bouchard@canonical.com>
Date: Thu, 17 Nov 2016 15:17:19 +0100
Subject: [PATCH] [archive] Handle error when adding /dev/null as a node
Adding /dev/null as a node will trigger EPERM. This can happen namely
when masking systemd units which symlinks to /dev/null. This fix will
avoid a stacktrace and will generate a INFO message about it.
Test for that situation is also included.
Signed-off-by: Louis Bouchard <louis.bouchard@canonical.com>
---
sos/archive.py | 10 +++++++++-
tests/archive_tests.py | 6 ++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/sos/archive.py b/sos/archive.py
index 4d9a469..463c23b 100644
--- a/sos/archive.py
+++ b/sos/archive.py
@@ -24,6 +24,7 @@ import shlex
import re
import codecs
import sys
+import errno
# required for compression callout (FIXME: move to policy?)
from subprocess import Popen, PIPE
@@ -209,7 +210,14 @@ class FileCacheArchive(Archive):
dest = self.dest_path(path)
self._check_path(dest)
if not os.path.exists(dest):
- os.mknod(dest, mode, device)
+ try:
+ os.mknod(dest, mode, device)
+ except OSError as e:
+ if e.errno == errno.EPERM:
+ msg = "Operation not permitted"
+ self.log_info("add_node: %s - mknod '%s'" % (msg, dest))
+ return
+ raise e
shutil.copystat(path, dest)
def _makedirs(self, path, mode=0o700):
diff --git a/tests/archive_tests.py b/tests/archive_tests.py
index dac02a0..febc96b 100644
--- a/tests/archive_tests.py
+++ b/tests/archive_tests.py
@@ -39,6 +39,12 @@ class TarFileArchiveTest(unittest.TestCase):
self.check_for_file('test/tests/ziptest')
+ def test_add_node_dev_null(self):
+ st = os.lstat('/dev/null')
+ dev_maj = os.major(st.st_rdev)
+ dev_min = os.minor(st.st_rdev)
+ self.tf.add_node('/dev/null', st.st_mode, os.makedev(dev_maj, dev_min))
+
# when the string comes from tail() output
def test_add_string_from_file(self):
self.copy_strings = []
--
2.10.2
|