From f3a4d92a5fa3c052182b6cccb305c7774d9a1184 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Thu, 28 Sep 2006 08:13:53 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=11210 --- checkin_notes | 6 +++++ lib/procinfo_mac.C | 55 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/checkin_notes b/checkin_notes index 865f13a336..3665f64086 100755 --- a/checkin_notes +++ b/checkin_notes @@ -10538,3 +10538,9 @@ Kevin 27 Sept 2006 sg_BoincSimpleGUI.cpp sg_DlgMessages.cpp sg_DlgPreferences.cpp + +Charlie 28 Sept 2006 + - Mac: Add safety features and fix bugs in procinfo_setup(). + + lib/ + procinfo_mac.C diff --git a/lib/procinfo_mac.C b/lib/procinfo_mac.C index 4dc7823710..d351cca55d 100644 --- a/lib/procinfo_mac.C +++ b/lib/procinfo_mac.C @@ -70,10 +70,12 @@ using std::vector; static int bidirectional_popen(char *path, int *fd); int procinfo_setup(vector& pi) { - char appstats_path[100]; static int fd[2] = {0, 0}; + static int failed_retries = 0; + + char appstats_path[100]; PROCINFO p; - int c, result, retry = 0; + int c, result, retry_count = 0; char buf[256]; struct statfs fs_info; #if SHOW_TIMING @@ -85,27 +87,40 @@ int procinfo_setup(vector& pi) { if (fd[0] == 0) { // Launch AppStats helper application with a bidirectional pipe RELAUNCH: + if (failed_retries > 4) // Give up after failures on 5 consecutive calls + return ERR_EXEC; // of procinfo_setup() + + if (retry_count > 1) { + ++failed_retries; + return ERR_EXEC; + } + sprintf(appstats_path, "%s/%s", SWITCHER_DIR, APP_STATS_FILE_NAME); result = bidirectional_popen(appstats_path, fd); #if SHOW_TIMING msg_printf(NULL, MSG_ERROR, "bidirectional_popen returned %d\n", result); #endif - if (result) return 0; - retry = 0; // Reset retry counter on success + if (result) { + ++retry_count; + goto RELAUNCH; + } + } + + c = write(fd[0], "\n", 1); // Request a set of process info from AppStats helper application + if (c < 0) { // AppStats application exited + ++retry_count; + goto RELAUNCH; } while (1) { - c = write(fd[0], "\n", 1); // Request a set of process info from AppStats helper application - if (c < 0) // AppStats application quit - if (++retry == 1) - goto RELAUNCH; - memset(&p, 0, sizeof(p)); for (unsigned int i=0; i& piv) { // the following is not useful because most OSs don't // move idle processes out of RAM, so physical memory is always full // + // If you wish to implement this in a future release, you must also + // enable the corresponding logic in app_stats_mac.C by defining + // GET_NON_BOINC_INFO to 1 + // void procinfo_other(PROCINFO& pi, vector& piv) { // AppStat returned total for all other processes as a single PROCINFO // struct with id field set to zero. @@ -186,6 +207,8 @@ static int bidirectional_popen(char *path, int *fd) { if ( (pid = fork()) < 0) { close(fd[0]); close(fd[1]); + fd[0] = 0; + fd[1] = 0; msg_printf(NULL, MSG_ERROR, "%s: fork error\n", appname); return ERR_FORK; }