From d8464eaa8000cf460b437cfd92f8e9a8b98a34aa Mon Sep 17 00:00:00 2001 From: Richard Cooper Date: Fri, 2 Oct 2020 17:50:07 +0100 Subject: [PATCH] util: Fix gem5img when used to manually unmount a disk image. When unmounting a disk image manually using the `gem5img umount mount_point` command, the operation can fail if the process is unable to stat any of the mounts in the mount table. On some systems this can occur even when running using sudo. Added an exception check so any mount points that fail to stat will not cause the whole script to terminate early. Change-Id: I69cd2494ad0e8c989e19ecd8af8a811905cd6c09 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/39897 Reviewed-by: Bobby R. Bruce Reviewed-by: Gabe Black Maintainer: Bobby R. Bruce Maintainer: Gabe Black Tested-by: kokoro --- util/gem5img.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/util/gem5img.py b/util/gem5img.py index 616dd7259..9523a7722 100755 --- a/util/gem5img.py +++ b/util/gem5img.py @@ -208,8 +208,11 @@ def mountPointToDev(mountPoint): mountTable = mountTable.splitlines() for line in mountTable: chunks = line.split() - if os.path.samefile(chunks[2], mountPoint): - return LoopbackDevice(chunks[0]) + try: + if os.path.samefile(chunks[2], mountPoint): + return LoopbackDevice(chunks[0]) + except OSError: + continue return None @@ -283,8 +286,8 @@ def mountComFunc(options, args): mountCom.func = mountComFunc # A command to unmount the first partition in the image. -umountCom = Command('umount', 'Unmount the first partition in the disk image.', - [('mount point', 'What mount point to unmount.')]) +umountCom = Command('umount', 'Unmount the disk image mounted at mount_point.', + [('mount_point', 'What mount point to unmount.')]) def umountComFunc(options, args): (mountPoint,) = args -- 2.30.2