bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* mountlist: Port better to Android
@ 2019-01-26 21:59 Bruno Haible
  2019-01-26 23:26 ` mountlist: Use Linux code on Android Bruno Haible
  0 siblings, 1 reply; 2+ messages in thread
From: Bruno Haible @ 2019-01-26 21:59 UTC (permalink / raw)
  To: bug-gnulib

The 'mountlist' module, on Android, relies on the getmntent(FILE*) function
and the MOUNTED macro.

The correct value of MOUNTED is "/proc/mounts", because /etc/mtab does not
exist.

- In Bionic releases after 2015-01-08:
  MOUNTED and _PATH_MOUNTED are defined as "/proc/mounts".
- In Bionic releases between 2014-01-09 and 2015-01-08:
  MOUNTED and _PATH_MOUNTED are defined as "/etc/mtab".
- In Bionic releases before 2014-01-09:
  MOUNTED is not defined. Only _PATH_MOUNTED is defined, as "/etc/mtab".

In particular, this leads to configure failing on Android 4.3:

  checking for getmntent... yes
  checking for one-argument getmntent function... no
  ...
  configure: error: could not determine how to read list of mounted file systems

This patch fixes both issues (the missing value of MOUNTED in older releases,
and the wrong one in newer releases).


2019-01-26  Bruno Haible  <bruno@clisp.org>

	mountlist: Port better to Android.
	* lib/mountlist.c (MOUNTED): Redefine on Android.
	* m4/ls-mntd-fs.m4 (gl_LIST_MOUNTED_FILE_SYSTEMS): Redefine MOUNTED on
	Android.

diff --git a/lib/mountlist.c b/lib/mountlist.c
index 0528d8a..937b3bb 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -66,7 +66,12 @@
                                    also (obsolete) 4.3BSD, SunOS */
 # include <mntent.h>
 # include <sys/types.h>
-# if !defined MOUNTED
+# if defined __ANDROID__        /* Android */
+   /* Bionic versions from between 2014-01-09 and 2015-01-08 define MOUNTED to
+      an incorrect value; older Bionic versions don't define it at all.  */
+#  undef MOUNTED
+#  define MOUNTED "/proc/mounts"
+# elif !defined MOUNTED
 #  if defined _PATH_MOUNTED     /* GNU libc  */
 #   define MOUNTED _PATH_MOUNTED
 #  endif
diff --git a/m4/ls-mntd-fs.m4 b/m4/ls-mntd-fs.m4
index 2de7b71..ba38439 100644
--- a/m4/ls-mntd-fs.m4
+++ b/m4/ls-mntd-fs.m4
@@ -1,4 +1,4 @@
-# serial 36
+# serial 37
 # How to list mounted file systems.
 
 # Copyright (C) 1998-2004, 2006, 2009-2019 Free Software Foundation, Inc.
@@ -99,11 +99,14 @@ $ac_includes_default
 #include <stdio.h>
 
 #include <mntent.h>
-#if !defined MOUNTED
-# if defined _PATH_MOUNTED      /* GNU libc  */
+#if defined __ANDROID__        /* Android */
+# undef MOUNTED
+# define MOUNTED "/proc/mounts"
+#elif !defined MOUNTED
+# if defined _PATH_MOUNTED     /* GNU libc  */
 #  define MOUNTED _PATH_MOUNTED
 # endif
-# if defined MNT_MNTTAB /* HP-UX.  */
+# if defined MNT_MNTTAB        /* HP-UX.  */
 #  define MOUNTED MNT_MNTTAB
 # endif
 #endif



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* mountlist: Use Linux code on Android
  2019-01-26 21:59 mountlist: Port better to Android Bruno Haible
@ 2019-01-26 23:26 ` Bruno Haible
  0 siblings, 0 replies; 2+ messages in thread
From: Bruno Haible @ 2019-01-26 23:26 UTC (permalink / raw)
  To: bug-gnulib

The Linux code that reads from /proc is also applicable on Android.

Notes:
- This compiler ("gcc -mandroid") defines the preprocessor symbol __ANDROID__
  but does NOT define __linux__.
- This version of Android does not have setmntent and endmntent, but these
  functions are easy to substitute.
- This version of Android also does not have getline, so this requires a
  dependency to the 'getline' module.


2019-01-26  Bruno Haible  <bruno@clisp.org>

	mountlist: Use Linux code on Android.
	* lib/mountlist.c (setmntent, endmntent): Define fallbacks.
	(unescape_tab, read_file_system_list): Enable Linux code on Android
	as well.
	* m4/ls-mntd-fs.m4 (gl_LIST_MOUNTED_FILE_SYSTEMS): Test for setmntent
	and endmntent.
	* modules/mountlist (Depends-on): Add 'getline'.

diff --git a/lib/mountlist.c b/lib/mountlist.c
index 937b3bb..9b54a2c 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -123,6 +123,15 @@
 # include <sys/mntent.h>
 #endif
 
+#ifdef MOUNTED_GETMNTENT1
+# if !HAVE_SETMNTENT            /* Android <= 4.4 */
+#  define setmntent(fp,mode) fopen (fp, mode)
+# endif
+# if !HAVE_ENDMNTENT            /* Android <= 4.4 */
+#  define endmntent(fp) fclose (fp)
+# endif
+#endif
+
 #ifndef HAVE_HASMNTOPT
 # define hasmntopt(mnt, opt) ((char *) 0)
 #endif
@@ -383,7 +392,7 @@ dev_from_mount_options (char const *mount_options)
 
 #endif
 
-#if defined MOUNTED_GETMNTENT1 && defined __linux__ /* GNU/Linux, Android */
+#if defined MOUNTED_GETMNTENT1 && (defined __linux__ || defined __ANDROID__) /* GNU/Linux, Android */
 
 /* Unescape the paths in mount tables.
    STR is updated in place.  */
@@ -429,7 +438,7 @@ read_file_system_list (bool need_fs_type)
   {
     FILE *fp;
 
-# ifdef __linux__
+# if defined __linux__ || defined __ANDROID__
     /* Try parsing mountinfo first, as that make device IDs available.
        Note we could use libmount routines to simplify this parsing a little
        (and that code is in previous versions of this function), however
@@ -522,7 +531,7 @@ read_file_system_list (bool need_fs_type)
           goto free_then_fail;
       }
     else /* fallback to /proc/self/mounts (/etc/mtab).  */
-# endif /* __linux __ */
+# endif /* __linux __ || __ANDROID__ */
       {
         struct mntent *mnt;
         char const *table = MOUNTED;
diff --git a/m4/ls-mntd-fs.m4 b/m4/ls-mntd-fs.m4
index ba38439..05474c2 100644
--- a/m4/ls-mntd-fs.m4
+++ b/m4/ls-mntd-fs.m4
@@ -1,4 +1,4 @@
-# serial 37
+# serial 38
 # How to list mounted file systems.
 
 # Copyright (C) 1998-2004, 2006, 2009-2019 Free Software Foundation, Inc.
@@ -123,7 +123,7 @@ $ac_includes_default
           [Define if there is a function named getmntent for reading the list
            of mounted file systems, and that function takes a single argument.
            (4.3BSD, SunOS, HP-UX, Irix)])
-        AC_CHECK_FUNCS([hasmntopt])
+        AC_CHECK_FUNCS([setmntent endmntent hasmntopt])
       fi
     fi
 
diff --git a/modules/mountlist b/modules/mountlist
index 1e7d22a..81ab2bf 100644
--- a/modules/mountlist
+++ b/modules/mountlist
@@ -9,6 +9,7 @@ m4/fstypename.m4
 m4/mountlist.m4
 
 Depends-on:
+getline
 stdbool
 stdint
 strstr-simple



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-26 23:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-26 21:59 mountlist: Port better to Android Bruno Haible
2019-01-26 23:26 ` mountlist: Use Linux code on Android Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).