summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOBATA Akio <[email protected]>2019-04-15 18:02:32 +0900
committerSlávek Banko <[email protected]>2019-05-04 17:25:51 +0200
commit39a89fa0a214671ed696634862423a18ebfd90c9 (patch)
tree0529b86d42486b915f9e24d9581464d414d06776
parente2e56f4e616b111f263627abdc6293b598b31037 (diff)
downloadtdeutils-39a89fa0a214671ed696634862423a18ebfd90c9.tar.gz
tdeutils-39a89fa0a214671ed696634862423a18ebfd90c9.zip
Change and simplify `statvfs` conditions in FileSystemStats
`getfsstat` v.s. `getvfsstat` condition is different than `statfs` v.s. `statvfs`, so split each condition and simplify. For `get(v)fsstat` side, changed to check and use `getmntinfo`, because it is better than `get(v)fsstat` with fixed buffer size, and easier than improve it with dynamic buffer allocation. Signed-off-by: OBATA Akio <[email protected]> (cherry picked from commit d349995488a13687171a67efd981e986b3b703e5)
-rw-r--r--ConfigureChecks.cmake14
-rw-r--r--config.h.cmake6
-rw-r--r--ksim/monitors/filesystem/filesystemstats.cpp26
3 files changed, 34 insertions, 12 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 1b48407..148884c 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -155,6 +155,20 @@ if ( BUILD_KSIM )
check_include_file( "sys/loadavg.h" HAVE_SYS_LOADAVG_H )
check_function_exists( getloadavg HAVE_GETLOADAVG )
+ check_function_exists( statfs HAVE_STATFS )
+ check_function_exists( statvfs HAVE_STATVFS )
+ check_function_exists( getmntinfo HAVE_GETMNTINFO )
+ if( HAVE_GETMNTINFO )
+ check_cxx_source_compiles("
+ #include <sys/types.h>
+ #include <sys/statvfs.h>
+ int main(){
+ struct statvfs *mntbufp;
+ int flags;
+ return getmntinfo(&mntbufp, flags);
+ }"
+ GETMNTINFO_USES_STATVFS )
+ endif( HAVE_GETMNTINFO )
check_c_source_compiles(
"#include <linux/kernel.h>
diff --git a/config.h.cmake b/config.h.cmake
index 52adf87..6676c8b 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -91,6 +91,12 @@
#cmakedefine HAVE_GETLOADAVG
#endif // HAVE_GETLOADAVG
+#cmakedefine HAVE_STATFS
+#if !defined( HAVE_STATVFS )
+#cmakedefine HAVE_STATVFS
+#endif
+#cmakedefine HAVE_GETMNTINFO
+#cmakedefine GETMNTINFO_USES_STATVFS
// superkaramba
diff --git a/ksim/monitors/filesystem/filesystemstats.cpp b/ksim/monitors/filesystem/filesystemstats.cpp
index 1aa156d..f60ce58 100644
--- a/ksim/monitors/filesystem/filesystemstats.cpp
+++ b/ksim/monitors/filesystem/filesystemstats.cpp
@@ -30,7 +30,7 @@
#include <sys/types.h>
#include <sys/param.h>
-#if defined(HAVE_SYS_STATVFS_H) && !defined(__DragonFly__)
+#if defined(HAVE_SYS_STATVFS_H)
#include <sys/statvfs.h>
#elif defined( HAVE_SYS_STATFS_H )
#include <sys/statfs.h>
@@ -59,12 +59,10 @@
#include <stdio.h>
#include <unistd.h>
-#if defined(HAVE_STATVFS) && !defined(__DragonFly__)
+#if defined(HAVE_STATVFS)
typedef struct statvfs ksim_statfs;
-#define ksim_getfsstat getvfsstat
-#elif defined( HAVE_STATFS ) || defined( Q_OS_FREEBSD )
+#elif defined( HAVE_STATFS )
typedef struct statfs ksim_statfs;
-#define ksim_getfsstat getfsstat
#else
typedef struct // fall back for (possibly) non-supported systems
{
@@ -75,9 +73,9 @@ typedef struct // fall back for (possibly) non-supported systems
int fsystemStats( const char * file, ksim_statfs & stats )
{
-#if defined(HAVE_STATVFS) && !defined(__DragonFly__)
+#if defined(HAVE_STATVFS)
return statvfs( file, &stats );
-#elif defined( HAVE_STATFS ) || defined( Q_OS_FREEBSD )
+#elif defined( HAVE_STATFS )
return statfs( file, &stats );
#else // fall back for (possibly) non-supported systems
(void)file;
@@ -135,8 +133,8 @@ ksim_mntent * ksim_getmntent( FILE * file )
}
#define delete_mntent( x )
-#elif defined( HAVE_SYS_UCRED_H ) || defined( HAVE_SYS_MOUNT_H )
-#define USE_FSSTAT
+#elif defined( HAVE_GETMNTINFO )
+#define USE_MNTINFO
#else
#define USE_FAILSAFE
#endif
@@ -163,10 +161,14 @@ FilesystemStats::List FilesystemStats::readEntries()
endmntent( fp );
#endif
-#ifdef USE_FSSTAT
- ksim_statfs sfs[32];
+#ifdef USE_MNTINFO
+# ifdef GETMNTINFO_USES_STATVFS
+ struct statvfs *sfs;
+# else
+ struct statfs *sfs;
+# endif
int fs_count;
- if ( ( fs_count = ksim_getfsstat( sfs, sizeof( sfs ), 0 ) ) != -1 )
+ if ( ( fs_count = getmntinfo( &sfs, 0 ) ) != -1 )
{
for ( int i = 0; i < fs_count; i++ )
{