|
|
50f7da |
From 6fc42802b87f95dba1d6bfda49ae158143e7799c Mon Sep 17 00:00:00 2001
|
|
|
50f7da |
From: Michal Srb <michal@redhat.com>
|
|
|
50f7da |
Date: Mon, 21 Aug 2017 16:29:23 +0200
|
|
|
50f7da |
Subject: [PATCH 1/2] [jars] Scan only /usr/{share,lib}/java by default
|
|
|
50f7da |
|
|
|
50f7da |
Other known locations can be added via:
|
|
|
50f7da |
-k jars.all_known_locations
|
|
|
50f7da |
|
|
|
50f7da |
Additional user-specified locations can be added via:
|
|
|
50f7da |
-k jars.append_locations=...
|
|
|
50f7da |
|
|
|
50f7da |
Signed-off-by: Michal Srb <michal@redhat.com>
|
|
|
50f7da |
---
|
|
|
50f7da |
sos/plugins/jars.py | 20 +++++++++++++++-----
|
|
|
50f7da |
1 file changed, 15 insertions(+), 5 deletions(-)
|
|
|
50f7da |
|
|
|
50f7da |
diff --git a/sos/plugins/jars.py b/sos/plugins/jars.py
|
|
|
50f7da |
index c6cba96..486ac05 100644
|
|
|
50f7da |
--- a/sos/plugins/jars.py
|
|
|
50f7da |
+++ b/sos/plugins/jars.py
|
|
|
50f7da |
@@ -31,7 +31,8 @@ class Jars(Plugin, RedHatPlugin):
|
|
|
50f7da |
profiles = ("java",)
|
|
|
50f7da |
option_list = [
|
|
|
50f7da |
("append_locations", "colon-separated list of additional JAR paths",
|
|
|
50f7da |
- "fast", "")
|
|
|
50f7da |
+ "fast", ""),
|
|
|
50f7da |
+ ("all_known_locations", "scan all known paths", "slow", False)
|
|
|
50f7da |
]
|
|
|
50f7da |
|
|
|
50f7da |
# There is no standard location for JAR files and scanning
|
|
|
50f7da |
@@ -39,7 +40,12 @@ class Jars(Plugin, RedHatPlugin):
|
|
|
50f7da |
# scan directories in which JARs can be typically found.
|
|
|
50f7da |
jar_locations = (
|
|
|
50f7da |
"/usr/share/java", # common location for JARs
|
|
|
50f7da |
- "/usr/lib/java", # common location for JARs containing native code
|
|
|
50f7da |
+ "/usr/lib/java" # common location for JARs containing native code
|
|
|
50f7da |
+ )
|
|
|
50f7da |
+
|
|
|
50f7da |
+ # Following paths can be optionally scanned as well. Note the scan can take
|
|
|
50f7da |
+ # *very* long time.
|
|
|
50f7da |
+ extra_jar_locations = (
|
|
|
50f7da |
"/opt", # location for RHSCL and 3rd party software
|
|
|
50f7da |
"/usr/local", # used by sysadmins when installing SW locally
|
|
|
50f7da |
"/var/lib" # Java services commonly explode WARs there
|
|
|
50f7da |
@@ -50,9 +56,13 @@ class Jars(Plugin, RedHatPlugin):
|
|
|
50f7da |
jar_paths = []
|
|
|
50f7da |
|
|
|
50f7da |
locations = list(Jars.jar_locations)
|
|
|
50f7da |
- extra_locations = self.get_option("append_locations")
|
|
|
50f7da |
- if extra_locations:
|
|
|
50f7da |
- locations += extra_locations.split(":")
|
|
|
50f7da |
+ if self.get_option("all_known_locations"):
|
|
|
50f7da |
+ locations += list(Jars.extra_jar_locations)
|
|
|
50f7da |
+
|
|
|
50f7da |
+ # append also user-defined locations, if any
|
|
|
50f7da |
+ user_locations = self.get_option("append_locations")
|
|
|
50f7da |
+ if user_locations:
|
|
|
50f7da |
+ locations += user_locations.split(":")
|
|
|
50f7da |
|
|
|
50f7da |
# find all JARs in given locations
|
|
|
50f7da |
for location in locations:
|
|
|
50f7da |
--
|
|
|
50f7da |
2.7.5
|
|
|
50f7da |
|
|
|
50f7da |
From d33c63a230092e94f966551968c51e8c5760742f Mon Sep 17 00:00:00 2001
|
|
|
50f7da |
From: Michal Srb <michal@redhat.com>
|
|
|
50f7da |
Date: Mon, 21 Aug 2017 18:11:04 +0200
|
|
|
50f7da |
Subject: [PATCH 2/2] [jars] Catch zipfile.BadZipfile exception
|
|
|
50f7da |
|
|
|
50f7da |
Bad ZIP files can raise zipfile.BadZipfile exception.
|
|
|
50f7da |
|
|
|
50f7da |
Fixes:
|
|
|
50f7da |
Traceback (most recent call last):
|
|
|
50f7da |
File "/home/msrb/projects/sos/sos/sosreport.py", line 1252, in setup
|
|
|
50f7da |
plug.setup()
|
|
|
50f7da |
File "/home/msrb/projects/sos/sos/plugins/jars.py", line 72, in setup
|
|
|
50f7da |
if Jars.is_jar(path):
|
|
|
50f7da |
File "/home/msrb/projects/sos/sos/plugins/jars.py", line 98, in is_jar
|
|
|
50f7da |
with zipfile.ZipFile(path) as f:
|
|
|
50f7da |
File "/usr/lib64/python2.7/zipfile.py", line 770, in __init__
|
|
|
50f7da |
self._RealGetContents()
|
|
|
50f7da |
File "/usr/lib64/python2.7/zipfile.py", line 842, in _RealGetContents
|
|
|
50f7da |
raise BadZipfile("Bad magic number for central directory")
|
|
|
50f7da |
BadZipfile: Bad magic number for central directory
|
|
|
50f7da |
|
|
|
50f7da |
Signed-off-by: Michal Srb <michal@redhat.com>
|
|
|
50f7da |
---
|
|
|
50f7da |
sos/plugins/jars.py | 2 +-
|
|
|
50f7da |
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
50f7da |
|
|
|
50f7da |
diff --git a/sos/plugins/jars.py b/sos/plugins/jars.py
|
|
|
50f7da |
index 486ac05..8c6b54f 100644
|
|
|
50f7da |
--- a/sos/plugins/jars.py
|
|
|
50f7da |
+++ b/sos/plugins/jars.py
|
|
|
50f7da |
@@ -98,7 +98,7 @@ class Jars(Plugin, RedHatPlugin):
|
|
|
50f7da |
with zipfile.ZipFile(path) as f:
|
|
|
50f7da |
if "META-INF/MANIFEST.MF" in f.namelist():
|
|
|
50f7da |
return True
|
|
|
50f7da |
- except IOError:
|
|
|
50f7da |
+ except (IOError, zipfile.BadZipfile):
|
|
|
50f7da |
pass
|
|
|
50f7da |
return False
|
|
|
50f7da |
|
|
|
50f7da |
--
|
|
|
50f7da |
2.7.5
|
|
|
50f7da |
|