Skip to content

Commit 0f29156

Browse files
nabijaczlewelibehlendorf
authored andcommitted
arc_summary3: just read /s/m/{mod}/version instead of spawning cat
Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Pavel Zakharov <[email protected]> Reviewed-by: Ryan Moeller <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #11859
1 parent 519aec8 commit 0f29156

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

cmd/arc_summary/arc_summary3

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,11 @@ elif sys.platform.startswith('linux'):
161161
# The original arc_summary called /sbin/modinfo/{spl,zfs} to get
162162
# the version information. We switch to /sys/module/{spl,zfs}/version
163163
# to make sure we get what is really loaded in the kernel
164-
command = ["cat", "/sys/module/{0}/version".format(request)]
165-
req = request.upper()
166-
167-
# The recommended way to do this is with subprocess.run(). However,
168-
# some installed versions of Python are < 3.5, so we offer them
169-
# the option of doing it the old way (for now)
170-
if 'run' in dir(subprocess):
171-
info = subprocess.run(command, stdout=subprocess.PIPE,
172-
universal_newlines=True)
173-
version = info.stdout.strip()
174-
else:
175-
info = subprocess.check_output(command, universal_newlines=True)
176-
version = info.strip()
177-
178-
return version
164+
try:
165+
with open("/sys/module/{}/version".format(request)) as f:
166+
return f.read().strip()
167+
except:
168+
return "(unknown)"
179169

180170
def get_descriptions(request):
181171
"""Get the descriptions of the Solaris Porting Layer (SPL) or the

0 commit comments

Comments
 (0)