From 7f289c924bdc78bff9b5a96cf9e7c0ed943d64c6 Mon Sep 17 00:00:00 2001 From: Patrick Welche Date: Mon, 18 Jul 2011 17:58:01 +0100 Subject: [PATCH] Avoid failing arguments to statfs() test on systems which use statvfs. - move choice of statfs vs statvfs from gio/glocalfile.c to configure.ac - if statvfs is the choice, then don't check number of arguments to statfs() - use choice in gio/gunixmounts.c as well https://bugzilla.gnome.org/show_bug.cgi?id=617949 --- configure.ac | 30 +++++++++++++++++++++++++++++- gio/glocalfile.c | 22 ---------------------- gio/gunixmounts.c | 32 +++++++++++++++++++++++++++++--- 3 files changed, 58 insertions(+), 26 deletions(-) diff --git a/configure.ac b/configure.ac index 2ee3b79..7c25399 100644 --- a/configure.ac +++ b/configure.ac @@ -1000,11 +1000,39 @@ AC_MSG_RESULT(unsigned $glib_size_type) # Check for some functions AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf stpcpy strcasecmp strncasecmp poll getcwd vasprintf setenv unsetenv getc_unlocked readlink symlink fdwalk memmem) -AC_CHECK_FUNCS(chown lchmod lchown fchmod fchown link statvfs statfs utimes getgrgid getpwuid) +AC_CHECK_FUNCS(chown lchmod lchown fchmod fchown link utimes getgrgid getpwuid) AC_CHECK_FUNCS(getmntent_r setmntent endmntent hasmntopt getmntinfo) # Check for high-resolution sleep functions AC_CHECK_FUNCS(splice) +# To avoid finding a compatibility unusable statfs, which typically +# successfully compiles, but warns to use the newer statvfs interface: +AS_IF([test $ac_cv_header_sys_statvfs_h = yes], [AC_CHECK_FUNCS([statvfs])]) +AS_IF([test $ac_cv_header_sys_statfs_h = yes], [AC_CHECK_FUNCS([statfs])]) + +AC_MSG_CHECKING([whether to use statfs or statvfs]) +# Some systems have both statfs and statvfs, pick the most "native" for these +AS_IF([test x$ac_cv_func_statfs = xyes && test x$ac_cv_func_statvfs = yes], + [ + # on solaris and irix, statfs doesn't even have the f_bavail field + AS_IF([test $ac_cv_member_struct_statfs_f_bavail = yes], + [ac_cv_func_statfs=no], + # else, at least on linux, statfs is the actual syscall + [ac_cv_func_statvfs=no]) + ]) + +AS_IF([test x$ac_cv_func_statfs = xyes], + [ + AC_DEFINE([USE_STATFS], [1], [Define to use statfs()]) + AC_MSG_RESULT([statfs]) + ], + [test x$ac_cv_func_statvfs = xyes], + [ + AC_DEFINE([USE_STATVFS], [1], [Define to use statvfs()]) + AC_MSG_RESULT([statvfs]) + ], + [ AC_MSG_RESULT([neither])]) + AC_CHECK_HEADERS(crt_externs.h) AC_CHECK_FUNCS(_NSGetEnviron) diff --git a/gio/glocalfile.c b/gio/glocalfile.c index 84ba0e2..b246af3 100644 --- a/gio/glocalfile.c +++ b/gio/glocalfile.c @@ -50,28 +50,6 @@ #define O_BINARY 0 #endif -#if defined(HAVE_STATFS) && defined(HAVE_STATVFS) -/* Some systems have both statfs and statvfs, pick the - most "native" for these */ -# if !defined(HAVE_STRUCT_STATFS_F_BAVAIL) - /* on solaris and irix, statfs doesn't even have the - f_bavail field */ -# define USE_STATVFS -# else - /* at least on linux, statfs is the actual syscall */ -# define USE_STATFS -# endif - -#elif defined(HAVE_STATFS) - -# define USE_STATFS - -#elif defined(HAVE_STATVFS) - -# define USE_STATVFS - -#endif - #include "gfileattribute.h" #include "glocalfile.h" #include "glocalfileinfo.h" diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c index 08eb2a0..acbffb4 100644 --- a/gio/gunixmounts.c +++ b/gio/gunixmounts.c @@ -38,9 +38,6 @@ #ifdef HAVE_POLL_H #include #endif -#if HAVE_SYS_STATVFS_H -#include -#endif #include #include #include @@ -50,6 +47,25 @@ #include #include +#if HAVE_SYS_STATFS_H +#include +#endif +#if HAVE_SYS_STATVFS_H +#include +#endif +#if HAVE_SYS_VFS_H +#include +#elif HAVE_SYS_MOUNT_H +#if HAVE_SYS_PARAM_H +#include +#endif +#include +#endif + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + #include "gunixmounts.h" #include "gfile.h" #include "gfilemonitor.h" @@ -570,7 +586,13 @@ get_mtab_monitor_file (void) static GList * _g_get_unix_mounts (void) { +#if defined(USE_STATFS) struct statfs *mntent = NULL; +#elif defined(USE_STATVFS) + struct statvfs *mntent = NULL; +#else + #error statfs juggling failed +#endif int num_mounts, i; GUnixMountEntry *mount_entry; GList *return_list; @@ -588,7 +610,11 @@ _g_get_unix_mounts (void) mount_entry->mount_path = g_strdup (mntent[i].f_mntonname); mount_entry->device_path = g_strdup (mntent[i].f_mntfromname); mount_entry->filesystem_type = g_strdup (mntent[i].f_fstypename); +#if defined(USE_STATFS) if (mntent[i].f_flags & MNT_RDONLY) +#elif defined(USE_STATVFS) + if (mntent[i].f_flag & MNT_RDONLY) +#endif mount_entry->is_read_only = TRUE; mount_entry->is_system_internal = -- 2.7.4