From 7167ea5a5e86e25241e5579866b17d45671cf6f7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 2 Apr 2010 14:06:28 +0200 Subject: hooklib: fix excessive rounding down in free space calculation (bz#575644) Signed-off-by: Denys Vlasenko --- src/Hooks/hooklib.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/Hooks/hooklib.cpp') diff --git a/src/Hooks/hooklib.cpp b/src/Hooks/hooklib.cpp index 06bde974..a722ef5f 100644 --- a/src/Hooks/hooklib.cpp +++ b/src/Hooks/hooklib.cpp @@ -83,12 +83,20 @@ void parse_conf(const char *additional_conf, unsigned *setting_MaxCrashReportsSi void check_free_space(unsigned setting_MaxCrashReportsSize) { - /* Check that at least MaxCrashReportsSize/4 MBs are free. */ struct statvfs vfs; - if (statvfs(DEBUG_DUMPS_DIR, &vfs) != 0 - || (vfs.f_bfree / (1024*1024 / 4)) * vfs.f_bsize < setting_MaxCrashReportsSize - ) { - error_msg_and_die("Low free disk space detected, aborting dump"); + if (statvfs(DEBUG_DUMPS_DIR, &vfs) != 0) + { + perror_msg_and_die("statvfs('%s')", DEBUG_DUMPS_DIR); + } + + /* Check that at least MaxCrashReportsSize/4 MBs are free */ + + /* fs_free_mb_x4 ~= vfs.f_bfree * vfs.f_bsize * 4, expressed in MBytes. + * Need to neither overflow nor round f_bfree down too much. */ + unsigned long fs_free_mb_x4 = ((unsigned long long)vfs.f_bfree / (1024/4)) * vfs.f_bsize / 1024; + if (fs_free_mb_x4 < setting_MaxCrashReportsSize) + { + error_msg_and_die("aborting dump: only %luMiB is available on %s\n", fs_free_mb_x4 / 4, DEBUG_DUMPS_DIR); } } -- cgit