diff --git a/api/boinc_api.h b/api/boinc_api.h index f7c02d638d..ccb7b6ad87 100755 --- a/api/boinc_api.h +++ b/api/boinc_api.h @@ -85,7 +85,7 @@ extern void boinc_ops_cumulative(double fp, double integer); extern int boinc_receive_trickle_down(char* buf, int len); #ifdef __APPLE__ -extern int setMacPList(char *filename); +extern int setMacPList(void); extern int setMacIcon(char *filename, char *iconData, long iconSize); #endif diff --git a/api/mac_icon.C b/api/mac_icon.C index 1f089f8455..9f7a112129 100644 --- a/api/mac_icon.C +++ b/api/mac_icon.C @@ -110,17 +110,74 @@ int setMacRsrcForFile(char *filename, char *rsrcData, long rsrcSize, } +static char * PersistentFGets(char *buf, size_t buflen, FILE *f) { + char *p = buf; + size_t len = buflen; + size_t datalen = 0; + + *buf = '\0'; + while (datalen < (buflen - 1)) { + fgets(p, len, f); + if (feof(f)) break; + if (ferror(f) && (errno != EINTR)) break; + if (strchr(buf, '\n')) break; + datalen = strlen(buf); + p = buf + datalen; + len -= datalen; + } + return (buf[0] ? buf : NULL); +} + + +void getPathToThisApp(char* pathBuf, size_t bufSize) { + FILE *f; + char buf[64], *c; + pid_t myPID = getpid(); + int i; + + *pathBuf = 0; // in case of failure + + // Before launching this project application, the BOINC client set the + // current directory to the slot directory which contains this application + // (or the soft-link to it.) So all we need for the path to this + // application is the file name. We use the -c option so ps strips off + // any command-line arguments for us. + sprintf(buf, "ps -cp %d -o command=", myPID); + f = popen(buf, "r"); + if (!f) + return; + PersistentFGets(pathBuf, bufSize, f); // Skip over line of column headings + PersistentFGets(pathBuf, bufSize, f); // Get the UNIX command which ran us + fclose(f); + + c = strstr(pathBuf, " -"); + if (c) + *c = 0; // Strip off any command-line arguments + + for (i=strlen(pathBuf)-1; i>=0; --i) { + if (pathBuf[i] <= ' ') + pathBuf[i] = 0; // Strip off trailing spaces, newlines, etc. + else + break; + } +} + + // Adds plst resource 0 to the file given as an argument. This // identifies the applciation to the OS as an NSUIElement, so // that the application does not show in the Dock and it has no // menu bar. -int setMacPList(char *filename) { - char path[1024]; +int setMacPList() { + char path[1024], resolvedPath[1024];; StringPtr rsrcName = (StringPtr)"\pApplication PList"; - setMacRsrcForFile(filename, MacPListData, sizeof(MacPListData), 'plst', 0, rsrcName); - boinc_resolve_filename(filename, path, sizeof(path)); - return(setMacRsrcForFile(path, MacPListData, sizeof(MacPListData), 'plst', 0, rsrcName)); + getPathToThisApp(path, sizeof(path)); + if (path[0] == 0) + return -1; // Should never happen + + setMacRsrcForFile(path, MacPListData, sizeof(MacPListData), 'plst', 0, rsrcName); + boinc_resolve_filename(path, resolvedPath, sizeof(resolvedPath)); + return(setMacRsrcForFile(resolvedPath, MacPListData, sizeof(MacPListData), 'plst', 0, rsrcName)); } diff --git a/api/x_opengl.C b/api/x_opengl.C index a4c38f1fa7..0ee1df9b99 100644 --- a/api/x_opengl.C +++ b/api/x_opengl.C @@ -431,7 +431,7 @@ void xwin_graphics_event_loop() { } else { if (!glut_is_initialized) { #ifdef __APPLE__ - setMacPList(aid.app_name); + setMacPList(); #endif set_mode(MODE_HIDE_GRAPHICS); while ( current_graphics_mode == MODE_HIDE_GRAPHICS ) { diff --git a/checkin_notes b/checkin_notes index 3086c1d30b..5970ee8a89 100755 --- a/checkin_notes +++ b/checkin_notes @@ -2424,14 +2424,6 @@ Rom 27 Feb 2006 Identification.cpp Identification.h -Charlie 27 Feb 2006 - - Mac: Get path for setMacPList in a more reilable way. - - api/ - boinc_api.h - mac_icon.C - x_openGL.C - Walt 27 Feb 2006 - Bug Fix: On Win2k and later, use global mutex so only one instance of the core client runs at a time. @@ -2439,4 +2431,12 @@ Walt 27 Feb 2006 client/ main.C cliend/win - win_util.h \ No newline at end of file + win_util.h + +Charlie 28 Feb 2006 + - Mac: Get path for setMacPList in a more reilable way. + + api/ + boinc_api.h + mac_icon.C + x_openGL.C