]> Savannah Git Hosting - gnulib.git/commitdiff
mountlist: Improve support for Solaris in 64-bit mode.
authorBruno Haible <bruno@clisp.org>
Fri, 12 Oct 2018 09:12:53 +0000 (11:12 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 12 Oct 2018 09:12:53 +0000 (11:12 +0200)
Reported by David Wood <David.Wood@deshaw.com> in
<https://debbugs.gnu.org/cgi/bugreport.cgi?bug=6816>.

* m4/ls-mntd-fs.m4 (gl_LIST_MOUNTED_FILE_SYSTEMS): On Solaris 8 or
newer, define MOUNTED_GETEXTMNTENT instead of MOUNTED_GETMNTENT2.
* lib/mountlist.c: Add code for MOUNTED_GETEXTMNTENT case.

ChangeLog
lib/mountlist.c
m4/ls-mntd-fs.m4

index 7d4d487d681da0ab6cbabe184a8d2322eb57ac47..0879c077850133dcebc5080611806baa422026c5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2018-10-12  Bruno Haible  <bruno@clisp.org>
+
+       mountlist: Improve support for Solaris in 64-bit mode.
+       Reported by David Wood <David.Wood@deshaw.com> in
+       <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=6816>.
+       * m4/ls-mntd-fs.m4 (gl_LIST_MOUNTED_FILE_SYSTEMS): On Solaris 8 or
+       newer, define MOUNTED_GETEXTMNTENT instead of MOUNTED_GETMNTENT2.
+       * lib/mountlist.c: Add code for MOUNTED_GETEXTMNTENT case.
+
 2018-10-12  Bruno Haible  <bruno@clisp.org>
 
        mountlist: Add support for Minix.
index 970c61151023fd8becb0cefd03e1727d5b69886d..845c3487622a2523ec456d9dbfd344243c8c1b90 100644 (file)
 # include <mntent.h>
 #endif
 
-#ifdef MOUNTED_GETMNTENT2       /* Solaris, also (obsolete) SVR4 */
+#ifdef MOUNTED_GETEXTMNTENT     /* Solaris >= 8 */
+# include <sys/mnttab.h>
+#endif
+
+#ifdef MOUNTED_GETMNTENT2       /* Solaris < 8, also (obsolete) SVR4 */
 # include <sys/mnttab.h>
 #endif
 
@@ -918,10 +922,55 @@ read_file_system_list (bool need_fs_type)
   }
 #endif /* MOUNTED_GETMNTTBL */
 
-#ifdef MOUNTED_GETMNTENT2       /* Solaris, also (obsolete) SVR4 */
+#ifdef MOUNTED_GETEXTMNTENT     /* Solaris >= 8 */
+  {
+    struct extmnttab mnt;
+    const char *table = MNTTAB;
+    FILE *fp;
+    int ret;
+
+    /* No locking is needed, because the contents of /etc/mnttab is generated
+       by the kernel.  */
+
+    errno = 0;
+    fp = fopen (table, "r");
+    if (fp == NULL)
+      ret = errno;
+    else
+      {
+        while ((ret = getextmntent (fp, &mnt, 1)) == 0)
+          {
+            me = xmalloc (sizeof *me);
+            me->me_devname = xstrdup (mnt.mnt_special);
+            me->me_mountdir = xstrdup (mnt.mnt_mountp);
+            me->me_mntroot = NULL;
+            me->me_type = xstrdup (mnt.mnt_fstype);
+            me->me_type_malloced = 1;
+            me->me_dummy = MNT_IGNORE (&mnt) != 0;
+            me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
+            me->me_dev = makedev (mnt.mnt_major, mnt.mnt_minor);
+
+            /* Add to the linked list. */
+            *mtail = me;
+            mtail = &me->me_next;
+          }
+
+        ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1;
+        /* Here ret = -1 means success, ret >= 0 means failure.  */
+      }
+
+    if (0 <= ret)
+      {
+        errno = ret;
+        goto free_then_fail;
+      }
+  }
+#endif /* MOUNTED_GETMNTTBL */
+
+#ifdef MOUNTED_GETMNTENT2       /* Solaris < 8, also (obsolete) SVR4 */
   {
     struct mnttab mnt;
-    char *table = MNTTAB;
+    const char *table = MNTTAB;
     FILE *fp;
     int ret;
     int lockfd = -1;
@@ -979,6 +1028,7 @@ read_file_system_list (bool need_fs_type)
           }
 
         ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1;
+        /* Here ret = -1 means success, ret >= 0 means failure.  */
       }
 
     if (0 <= lockfd && close (lockfd) != 0)
index ff688f5ce3a226052fcc4c1971c4037569996bfa..643d0cefd69287c3ee77e6ef9d65c6ef5d2dbf43 100644 (file)
@@ -158,7 +158,23 @@ yes
     fi
 
     if test -z "$ac_list_mounted_fs"; then
-      # Solaris, also (obsolete) SVR4.
+      # Solaris >= 8.
+      AC_CACHE_CHECK([for getextmntent function],
+        [fu_cv_sys_mounted_getextmntent],
+        [AC_EGREP_HEADER([getextmntent], [sys/mnttab.h],
+           [fu_cv_sys_mounted_getextmntent=yes],
+           [fu_cv_sys_mounted_getextmntent=no])])
+      if test $fu_cv_sys_mounted_getextmntent = yes; then
+        ac_list_mounted_fs=found
+        AC_DEFINE([MOUNTED_GETEXTMNTENT], [1],
+          [Define if there is a function named getextmntent for reading the list
+           of mounted file systems.  (Solaris)])
+      fi
+    fi
+
+    if test -z "$ac_list_mounted_fs"; then
+      # Solaris < 8, also (obsolete) SVR4.
+      # Solaris >= 8 has the two-argument getmntent but is already handled above.
       AC_CACHE_CHECK([for two-argument getmntent function],
         [fu_cv_sys_mounted_getmntent2],
         [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],