From 3a530a4c345a175f140cfefb88be2d6b5ffd40dd Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 6 Feb 2013 22:06:52 -0800 Subject: [PATCH] - client: check return value of the function (statfs or statvfs) used to find disk space and usage. This may be failing for in-memory filesystems on Linux. --- client/gui_rpc_server_ops.cpp | 10 +++++++++- client/hostinfo_unix.cpp | 7 ++++++- client/hostinfo_win.cpp | 7 ++++++- lib/error_numbers.h | 1 + lib/filesys.cpp | 10 +++++++--- samples/condor/boinc_gahp.cpp | 8 ++++---- samples/condor/job_rpc.cpp | 8 ++++---- samples/condor/job_rpc.h | 8 ++++---- 8 files changed, 41 insertions(+), 18 deletions(-) diff --git a/client/gui_rpc_server_ops.cpp b/client/gui_rpc_server_ops.cpp index 7c62fca18d..60fb8c1e5d 100644 --- a/client/gui_rpc_server_ops.cpp +++ b/client/gui_rpc_server_ops.cpp @@ -137,7 +137,15 @@ static void handle_get_disk_usage(GUI_RPC_CONN& grc) { double size, boinc_non_project, d_allowed, boinc_total; grc.mfout.printf("\n"); - get_filesystem_info(gstate.host_info.d_total, gstate.host_info.d_free); + int retval = get_filesystem_info( + gstate.host_info.d_total, gstate.host_info.d_free + ); + if (retval) { + msg_printf(0, MSG_INTERNAL_ERROR, + "get_filesystem_info(): %s", boincerror(retval) + ); + } + dir_size(".", boinc_non_project, false); dir_size("locale", size, false); boinc_non_project += size; diff --git a/client/hostinfo_unix.cpp b/client/hostinfo_unix.cpp index ffdd8845d2..cadbc6f48e 100644 --- a/client/hostinfo_unix.cpp +++ b/client/hostinfo_unix.cpp @@ -1271,7 +1271,12 @@ int HOST_INFO::get_virtualbox_version() { // - only one level of #if // int HOST_INFO::get_host_info() { - get_filesystem_info(d_total, d_free); + int retval = get_filesystem_info(d_total, d_free); + if (retval) { + msg_printf(0, MSG_INTERNAL_ERROR, + "get_filesystem_info() failed: %s", boincerror(retval) + ); + } get_virtualbox_version(); ///////////// p_vendor, p_model, p_features ///////////////// diff --git a/client/hostinfo_win.cpp b/client/hostinfo_win.cpp index 5ac1c7bdbf..19a8042f94 100644 --- a/client/hostinfo_win.cpp +++ b/client/hostinfo_win.cpp @@ -1253,7 +1253,12 @@ int HOST_INFO::get_virtualbox_version() { // int HOST_INFO::get_host_info() { get_timezone(timezone); - get_filesystem_info(d_total, d_free); + int retval = get_filesystem_info(d_total, d_free); + if (retval) { + msg_printf(0, MSG_INTERNAL_ERROR, + "get_filesystem_info(): %s", boincerror(retval) + ); + } get_memory_info(m_nbytes, m_swap); get_os_information( os_name, sizeof(os_name), os_version, sizeof(os_version) diff --git a/lib/error_numbers.h b/lib/error_numbers.h index 54e378718d..a8041cbe9e 100644 --- a/lib/error_numbers.h +++ b/lib/error_numbers.h @@ -199,6 +199,7 @@ #define ERR_CRYPTO -231 #define ERR_ABORTED_ON_EXIT -232 #define ERR_PROC_PARSE -235 +#define ERR_STATFS -236 // PLEASE: add a text description of your error to // the text description function boincerror() in str_util.cpp. diff --git a/lib/filesys.cpp b/lib/filesys.cpp index 2c5d50eb8a..010ce353db 100644 --- a/lib/filesys.cpp +++ b/lib/filesys.cpp @@ -765,8 +765,6 @@ void relative_to_absolute(const char* relname, char* path) { } } -// get total and free space on current filesystem (in bytes) -// #if defined(_WIN32) && !(defined(WXDEBUG) || defined(WXNDEBUG)) int boinc_allocate_file(const char* path, double size) { int retval = 0; @@ -794,6 +792,8 @@ int boinc_allocate_file(const char* path, double size) { } #endif +// get total and free dpace on current filesystem (in bytes) +// #ifdef _WIN32 int get_filesystem_info(double &total_space, double &free_space, char*) { char cwd[MAXPATHLEN]; @@ -832,7 +832,11 @@ int get_filesystem_info(double &total_space, double &free_space, char* path) { #ifdef STATFS struct STATFS fs_info; - STATFS(path, &fs_info); + int retval = STATFS(path, &fs_info); + if (retval) { + perror("statvfs"); + return ERR_STATFS; + } #if HAVE_SYS_STATVFS_H total_space = (double)fs_info.f_frsize * (double)fs_info.f_blocks; free_space = (double)fs_info.f_frsize * (double)fs_info.f_bavail; diff --git a/samples/condor/boinc_gahp.cpp b/samples/condor/boinc_gahp.cpp index c248e61fe3..a63dfaa1e2 100644 --- a/samples/condor/boinc_gahp.cpp +++ b/samples/condor/boinc_gahp.cpp @@ -111,9 +111,9 @@ int process_input_files(SUBMIT_REQ& req) { retval = query_files( project_url, authenticator, - req.batch_id, - md5s, paths, + md5s, + req.batch_id, absent_files ); if (retval) return retval; @@ -129,9 +129,9 @@ int process_input_files(SUBMIT_REQ& req) { retval = upload_files( project_url, authenticator, - req.batch_id, + upload_paths, upload_md5s, - upload_paths + req.batch_id ); if (retval) return retval; return 0; diff --git a/samples/condor/job_rpc.cpp b/samples/condor/job_rpc.cpp index d478903068..74f99e69d1 100644 --- a/samples/condor/job_rpc.cpp +++ b/samples/condor/job_rpc.cpp @@ -111,9 +111,9 @@ static int do_http_post( int query_files( const char* project_url, const char* authenticator, - int batch_id, - vector &md5s, vector &paths, + vector &md5s, + int batch_id, vector &absent_files ) { string req_msg; @@ -157,9 +157,9 @@ int query_files( int upload_files ( const char* project_url, const char* authenticator, - int batch_id, + vector &paths, vector &md5s, - vector &paths + int batch_id ) { char buf[1024]; string req_msg = "\n"; diff --git a/samples/condor/job_rpc.h b/samples/condor/job_rpc.h index 9396ba5bb1..5644fe1792 100644 --- a/samples/condor/job_rpc.h +++ b/samples/condor/job_rpc.h @@ -73,18 +73,18 @@ struct FETCH_OUTPUT_REQ { extern int query_files( const char* project_url, const char* authenticator, - int batch_id, - vector &md5s, vector &paths, + vector &md5s, + int batch_id, vector &absent_files ); extern int upload_files ( const char* project_url, const char* authenticator, - int batch_id, + vector &paths, vector &md5s, - vector &paths + int batch_id ); extern int create_batch(