Always read /proc/mounts when looking for mounted media (bnc#705893)
authorMichael Andres <ma@suse.de>
Mon, 25 Jul 2011 14:22:25 +0000 (16:22 +0200)
committerMichael Andres <ma@suse.de>
Mon, 25 Jul 2011 14:22:25 +0000 (16:22 +0200)
zypp/media/MediaManager.cc
zypp/media/Mount.cc
zypp/media/Mount.h

index 2097f96..0144ca1 100644 (file)
@@ -231,9 +231,7 @@ namespace zypp
       static inline MountEntries
       getMountEntries()
       {
-        // use "/etc/mtab" by default,
-        // fallback to "/proc/mounts"
-        return Mount::getEntries(/* "/etc/mtab" */);
+        return Mount::getEntries();
       }
 
     };
index 66da0df..3758420 100644 (file)
@@ -25,6 +25,8 @@
 #include "zypp/media/Mount.h"
 #include "zypp/media/MediaException.h"
 
+#include "zypp/PathInfo.h"
+
 #ifndef N_
 #define N_(STR) STR
 #endif
@@ -278,8 +280,15 @@ Mount::getEntries(const std::string &mtab)
 
   if( mtab.empty())
   {
-    mtabs.push_back("/etc/mtab");
     mtabs.push_back("/proc/mounts");
+    // Also read /etc/mtab if it is a file (on newer sytems
+    // mtab is a symlink to /proc/mounts). 
+    // Reason for this is the different representation of
+    // mounted loop devices:
+    //   /etc/mtab:    /tmp/SLES-11-SP2-MINI-ISO-x86_64-Beta2-DVD.iso on /mnt type iso9660 (ro,loop=/dev/loop0)
+    //   /proc/mounts: /dev/loop0 /mnt iso9660 ro,relatime 0 0
+    if ( PathInfo( "/etc/mtab", PathInfo::LSTAT ).isFile() )
+      mtabs.push_back("/etc/mtab");
   }
   else
   {
index 1c95dda..04ea0d4 100644 (file)
@@ -128,8 +128,9 @@ namespace zypp {
        *
        * @param mtab The name of the (mounted) file system description
        *             file to read from. This file should be one /etc/mtab,
-       *             /etc/fstab or /proc/mounts. Default is to try the
-       *             /etc/mtab and fail back to /proc/mounts.
+       *             /etc/fstab or /proc/mounts. Default is to read
+       *             /proc/mounts and /etc/mtab in case is not a symlink
+       *             to /proc/mounts.
        * @returns A vector with mount entries or empty vector if reading
        *          or parsing of the mtab file(s) failed.
        */