From c03dcee177187c073a6fb0b48acda2c4ea2e0ff4 Mon Sep 17 00:00:00 2001 From: Jake Hunsaker Date: Fri, 6 Mar 2020 11:52:14 -0500 Subject: [Plugin] Do not write empty files to archive on command failure If a command is not found on the system, sos traditionally will handle that failed call by simply not writing any output to the archive. However, if the command was given a suggested_filename or a root_symlink parameter in the `add_cmd_output()` call, we would end up writing an empty file to the archive. Now, we will re-check the status of the command attempt after the chroot check (and possible re-run) is done, and if the command "still" is not found, exit immediately to avoid the empty writes. Related: #1975 Signed-off-by: Jake Hunsaker --- sos/plugins/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 7f1b5ea2..76a85541 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -1256,6 +1256,10 @@ class Plugin(object): poller=self.check_timeout ) self._log_debug("could not run '%s': command not found" % cmd) + # Exit here if the command was not found in the chroot check above + # as otherwise we will create a blank file in the archive + if result['status'] in [126, 127]: + return result self._log_debug("collected output of '%s' in %s (changes=%s)" % (cmd.split()[0], time() - start, changes)) -- cgit