[PATCH] Only eject CDROM devices we're actually using (#949919)

Will Woods wwoods at redhat.com
Fri Oct 25 21:06:21 UTC 2013


Rather than ejecting *every optical drive* on the system, we should only
eject those devices that are actually being used by the installer.

So, check each cdrom device to see if it's mounted somewhere, and eject
it if so.
---
 anaconda            | 9 ++++-----
 pyanaconda/iutil.py | 7 +++++++
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/anaconda b/anaconda
index 968a3de..7dd5547 100755
--- a/anaconda
+++ b/anaconda
@@ -62,13 +62,12 @@ def exitHandler(rebootData, storage, exitCode=None):
     if not flags.imageInstall and not flags.livecdInstall \
        and not flags.dirInstall:
         from pykickstart.constants import KS_SHUTDOWN, KS_WAIT
-        from pyanaconda.iutil import dracut_eject
+        from pyanaconda.iutil import dracut_eject, get_mount_paths
 
         if flags.eject or rebootData.eject:
-            for drive in storage.devicetree.devices:
-                if drive.type != "cdrom":
-                    continue
-                dracut_eject(drive.path)
+            for cdrom in storage.devicetree.getDevicesByType("cdrom"):
+                if get_mount_paths(cdrom.path):
+                    dracut_eject(cdrom.path)
 
         if rebootData.action == KS_SHUTDOWN:
             subprocess.Popen(["systemctl", "--no-wall", "poweroff"])
diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
index ff7d32b..45614d2 100644
--- a/pyanaconda/iutil.py
+++ b/pyanaconda/iutil.py
@@ -758,3 +758,10 @@ def upcase_first_letter(text):
         return text.upper()
     else:
         return text[0].upper() + text[1:]
+
+def get_mount_paths(devnode):
+    '''given a device node, return a list of all active mountpoints.'''
+    devno = os.stat(devnode).st_rdev
+    majmin = "%d:%d" % (os.major(devno),os.minor(devno))
+    mountinfo = (line.split() for line in open("/proc/self/mountinfo"))
+    return [info[4] for info in mountinfo if info[2] == majmin]
-- 
1.8.3.1



More information about the anaconda-patches mailing list