From 5591c64687ff9de47595027e9bc6c2296898780a Mon Sep 17 00:00:00 2001
From: Matt Arsenault <arsenm2@rpi.edu>
Date: Wed, 22 Jun 2011 18:17:13 -0400
Subject: [PATCH 2/6] Fix OS X build issues
---
api/Makefile.am | 4 +-
api/mac_icon.cpp | 81 ++++++++++++++++++++++++++++++++---------------------
lib/coproc.h | 2 +-
3 files changed, 52 insertions(+), 35 deletions(-)
diff --git a/api/Makefile.am b/api/Makefile.am
index 04fcf78..8d5b4c7 100644
a
|
b
|
libboinc_api_la_LDFLAGS = -L$(libdir) -rpath $(libdir) -version-number $(LIBBOIN |
39 | 39 | if BUILD_GRAPHICS_API |
40 | 40 | lib_LTLIBRARIES += libboinc_graphics2.la |
41 | 41 | libboinc_graphics2_la_SOURCES = $(graphics2_files) |
42 | | libboinc_graphics2_la_CPPFLAGS = -I$(top_srcdir)/lib |
| 42 | libboinc_graphics2_la_CPPFLAGS = -I$(top_srcdir)/lib |
43 | 43 | libboinc_graphics2_la_LDFLAGS = -L$(libdir) -rpath $(libdir) -version-number $(LIBBOINC_VERSION) |
44 | 44 | endif #BUILD_GRAPHICS_API |
45 | 45 | |
… |
… |
pkginclude_HEADERS = \ |
51 | 51 | gutil.h |
52 | 52 | endif ## INSTALL_HEADERS |
53 | 53 | |
54 | | # Some OSs may not prefix libraries with lib. |
| 54 | # Some OSs may not prefix libraries with lib. |
55 | 55 | # For example OS2 |
56 | 56 | if OS_OS2 |
57 | 57 | LIBBOINC_API_STATIC=boinc_api.${LIBEXT} |
diff --git a/api/mac_icon.cpp b/api/mac_icon.cpp
index e534bb8..64d438f 100644
a
|
b
|
|
16 | 16 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | |
18 | 18 | /* Mac-specific code to display custom icon for science application (optional) |
19 | | adapted from code written by Bernd Machenschalk. Used with permission of the |
| 19 | adapted from code written by Bernd Machenschalk. Used with permission of the |
20 | 20 | Einstein@home project. |
21 | | |
| 21 | |
22 | 22 | To use this code: |
23 | 23 | 1. Create a *.icns file using "/Developer/Applications/utilities/Icon Composer.app" |
24 | | 2. Convert the *.icns file to an app_icon.h file as follows: in Terminal, run |
25 | | "MakeAppIcon_h <source_file> <dest_file>". (The MakeAppIcon_h command-line utility |
| 24 | 2. Convert the *.icns file to an app_icon.h file as follows: in Terminal, run |
| 25 | "MakeAppIcon_h <source_file> <dest_file>". (The MakeAppIcon_h command-line utility |
26 | 26 | is built by the Mac boinc XCode project.) |
27 | 27 | 3. In the science application's main(), #include "app_icon.h" and call: |
28 | 28 | setMacIcon(argv[0], MacAppIconData, sizeof(MacAppIconData)); |
… |
… |
char MacPListData[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
52 | 52 | return(e); } } |
53 | 53 | |
54 | 54 | // Adds the specified resource to the file given as an argument. |
55 | | int setMacRsrcForFile(char *filename, char *rsrcData, long rsrcSize, |
56 | | OSType rsrcType, int rsrcID, StringPtr rsrcName) { |
| 55 | int setMacRsrcForFile(char *filename, char *rsrcData, long rsrcSize, |
| 56 | OSType rsrcType, int rsrcID, ConstStringPtr rsrcName) { |
57 | 57 | OSErr oserr; /* stores an OS error code */ |
58 | 58 | // FSSpec fsspec; /* FileSpec */ |
59 | 59 | HFSUniStr255 forkName; /* Unicode name of resource fork "RESOURCE_FORK" */ |
… |
… |
int setMacRsrcForFile(char *filename, char *rsrcData, long rsrcSize, |
62 | 62 | short rref; /* Resource Reference */ |
63 | 63 | Handle hand; |
64 | 64 | int retry; |
65 | | |
| 65 | |
66 | 66 | /* get finder spec for this file */ |
67 | 67 | CHECK_OSERR((int)FSPathMakeRef((StringPtr)filename, &fsref, NULL)); |
68 | 68 | // CHECK_OSERR(FSGetCatalogInfo(&fsref, nil, NULL, NULL, &fsspec, NULL)); |
69 | 69 | |
70 | 70 | /* Open the resource fork for writing, create it if it does not exist. |
71 | | On a dual-processor system, the other cpu may have the resource fork |
| 71 | On a dual-processor system, the other cpu may have the resource fork |
72 | 72 | open for writing, so if we fail we wait and retry. |
73 | 73 | */ |
74 | 74 | for (retry=0;retry<5;retry++) { |
… |
… |
int setMacRsrcForFile(char *filename, char *rsrcData, long rsrcSize, |
92 | 92 | } |
93 | 93 | // We may not have permissions to set resources in debug runs |
94 | 94 | if ((oserr == noErr) || (oserr == wrPermErr) || (oserr == permErr)) |
95 | | break; |
| 95 | break; |
96 | 96 | sleep (1); |
97 | 97 | }; |
98 | 98 | |
99 | 99 | if (oserr) |
100 | 100 | return oserr; // give up after 5 seconds |
101 | | |
| 101 | |
102 | 102 | /* add the resource if not already present */ |
103 | 103 | if (!GetResource(rsrcType, rsrcID)) { /* if resource not found */ |
104 | 104 | oserr = PtrToHand(rsrcData, &hand, rsrcSize); |
… |
… |
void getPathToThisApp(char* pathBuf, size_t bufSize) { |
145 | 145 | pid_t myPID = getpid(); |
146 | 146 | int i; |
147 | 147 | struct stat stat_buf; |
148 | | |
| 148 | |
149 | 149 | strcpy(pathBuf, GRAPHICS_APP_FILENAME); |
150 | 150 | if (!stat(pathBuf, &stat_buf)) { |
151 | 151 | // stat() returns zero on success |
152 | 152 | return; |
153 | 153 | } |
154 | | |
| 154 | |
155 | 155 | *pathBuf = 0; // in case of failure |
156 | | |
157 | | // Before launching this project application, the BOINC client set the |
158 | | // current directory to the slot directory which contains this application |
159 | | // (or the soft-link to it.) So all we need for the path to this |
160 | | // application is the file name. We use the -c option so ps strips off |
| 156 | |
| 157 | // Before launching this project application, the BOINC client set the |
| 158 | // current directory to the slot directory which contains this application |
| 159 | // (or the soft-link to it.) So all we need for the path to this |
| 160 | // application is the file name. We use the -c option so ps strips off |
161 | 161 | // any command-line arguments for us. |
162 | 162 | sprintf(buf, "ps -wcp %d -o command=", myPID); |
163 | 163 | f = popen(buf, "r"); |
… |
… |
void getPathToThisApp(char* pathBuf, size_t bufSize) { |
167 | 167 | PersistentFGets(pathBuf, bufSize, f); // Get the UNIX command which ran us |
168 | 168 | pclose(f); |
169 | 169 | |
170 | | c = strstr(pathBuf, " -"); |
| 170 | c = strstr(pathBuf, " -"); |
171 | 171 | if (c) |
172 | 172 | *c = 0; // Strip off any command-line arguments |
173 | | |
| 173 | |
174 | 174 | for (i=strlen(pathBuf)-1; i>=0; --i) { |
175 | 175 | if (pathBuf[i] <= ' ') |
176 | 176 | pathBuf[i] = 0; // Strip off trailing spaces, newlines, etc. |
… |
… |
void getPathToThisApp(char* pathBuf, size_t bufSize) { |
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | | |
183 | | // Adds plst resource 0 to the file given as an argument. This |
184 | | // identifies the application to the OS as an NSUIElement, so |
185 | | // that the application does not show in the Dock and it has no |
| 182 | // Adds plst resource 0 to the file given as an argument. This |
| 183 | // identifies the application to the OS as an NSUIElement, so |
| 184 | // that the application does not show in the Dock and it has no |
186 | 185 | // menu bar. |
187 | 186 | int setMacPList() { |
| 187 | int rc; |
188 | 188 | char path[1024], resolvedPath[1024]; |
189 | | StringPtr rsrcName = (StringPtr)"\pApplication PList"; |
| 189 | const char plistStr[] = "Application PList"; |
| 190 | CFStringRef plistCFStr = CFStringCreateWithCString(kCFAllocatorDefault, plistStr, kCFStringEncodingMacRoman); |
| 191 | ConstStringPtr rsrcName = CFStringGetPascalStringPtr(plistCFStr, kCFStringEncodingMacRoman); |
| 192 | if (!rsrcName) { |
| 193 | return -2; |
| 194 | } |
190 | 195 | |
191 | | // If resource already exists, don't call getPathToThisApp() |
| 196 | // If resource already exists, don't call getPathToThisApp() |
192 | 197 | // which leaves a zombie process. |
193 | | if (GetResource('plst', 0)) { |
| 198 | if (GetResource('plst', 0)) { |
194 | 199 | return 0; |
195 | 200 | } |
196 | | |
| 201 | |
197 | 202 | getPathToThisApp(path, sizeof(path)); |
198 | 203 | if (path[0] == 0) |
199 | 204 | return -1; // Should never happen |
200 | | |
| 205 | |
201 | 206 | setMacRsrcForFile(path, MacPListData, sizeof(MacPListData), 'plst', 0, rsrcName); |
202 | 207 | boinc_resolve_filename(path, resolvedPath, sizeof(resolvedPath)); |
203 | | return(setMacRsrcForFile(resolvedPath, MacPListData, sizeof(MacPListData), 'plst', 0, rsrcName)); |
| 208 | rc = setMacRsrcForFile(resolvedPath, MacPListData, sizeof(MacPListData), 'plst', 0, rsrcName); |
| 209 | |
| 210 | CFRelease(plistCFStr); |
| 211 | return rc; |
204 | 212 | } |
205 | 213 | |
206 | 214 | |
207 | 215 | // Adds icns resource to the file given as an argument. |
208 | | // If the file is a soft link, also adds icns resource to the resolved flle. |
| 216 | // If the file is a soft link, also adds icns resource to the resolved flle. |
209 | 217 | // Typically called from a main() with argv[0] to attach resources to itself */ |
210 | 218 | int setMacIcon(char *filename, char *iconData, long iconSize) { |
| 219 | int rc; |
211 | 220 | char path[1024]; |
212 | | StringPtr rsrcName = (StringPtr)"\pApplication icons"; |
| 221 | const char iconStr[] = "Application icons"; |
| 222 | CFStringRef iconCFStr = CFStringCreateWithCString(kCFAllocatorDefault, iconStr, kCFStringEncodingMacRoman); |
| 223 | ConstStringPtr rsrcName = CFStringGetPascalStringPtr(iconCFStr, kCFStringEncodingMacRoman); // FIXME: How to release this? |
| 224 | if (!rsrcName) { |
| 225 | return -2; |
| 226 | } |
213 | 227 | |
214 | 228 | setMacRsrcForFile(filename, iconData, iconSize, 'icns', RESIDICON, rsrcName); |
215 | 229 | boinc_resolve_filename(filename, path, sizeof(path)); |
216 | | return(setMacRsrcForFile(path, iconData, iconSize, 'icns', RESIDICON, rsrcName)); |
| 230 | rc = setMacRsrcForFile(path, iconData, iconSize, 'icns', RESIDICON, rsrcName); |
| 231 | |
| 232 | CFRelease(iconCFStr); |
| 233 | return rc; |
217 | 234 | } |
diff --git a/lib/coproc.h b/lib/coproc.h
index 771c081..89371c6 100644
a
|
b
|
struct COPROCS { |
334 | 334 | } |
335 | 335 | } |
336 | 336 | } |
337 | | void COPROCS::clear() { |
| 337 | void clear() { |
338 | 338 | n_rsc = 0; |
339 | 339 | for (int i=0; i<MAX_RSC; i++) { |
340 | 340 | coprocs[i].clear(); |