aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llappviewermacosx.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llappviewermacosx.cpp')
-rw-r--r--linden/indra/newview/llappviewermacosx.cpp110
1 files changed, 98 insertions, 12 deletions
diff --git a/linden/indra/newview/llappviewermacosx.cpp b/linden/indra/newview/llappviewermacosx.cpp
index e3fd425..0e5062d 100644
--- a/linden/indra/newview/llappviewermacosx.cpp
+++ b/linden/indra/newview/llappviewermacosx.cpp
@@ -4,7 +4,7 @@
4 * 4 *
5 * $LicenseInfo:firstyear=2007&license=viewergpl$ 5 * $LicenseInfo:firstyear=2007&license=viewergpl$
6 * 6 *
7 * Copyright (c) 2007-2008, Linden Research, Inc. 7 * Copyright (c) 2007-2009, Linden Research, Inc.
8 * 8 *
9 * Second Life Viewer Source Code 9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab 10 * The source code in this file ("Source Code") is provided by Linden Lab
@@ -49,12 +49,24 @@
49#include <Carbon/Carbon.h> 49#include <Carbon/Carbon.h>
50#include "lldir.h" 50#include "lldir.h"
51#include <signal.h> 51#include <signal.h>
52
52namespace 53namespace
53{ 54{
54 // The command line args stored. 55 // The command line args stored.
55 // They are not used immediately by the app. 56 // They are not used immediately by the app.
56 int gArgC; 57 int gArgC;
57 char** gArgV; 58 char** gArgV;
59
60 bool sCrashReporterIsRunning = false;
61
62 OSErr AEQuitHandler(const AppleEvent *messagein, AppleEvent *reply, long refIn)
63 {
64 OSErr result = noErr;
65
66 LLAppViewer::instance()->userQuit();
67
68 return(result);
69 }
58} 70}
59 71
60int main( int argc, char **argv ) 72int main( int argc, char **argv )
@@ -256,8 +268,37 @@ void LLAppViewerMacOSX::handleSyncCrashTrace()
256 // do nothing 268 // do nothing
257} 269}
258 270
271static OSStatus CarbonEventHandler(EventHandlerCallRef inHandlerCallRef,
272 EventRef inEvent,
273 void* inUserData)
274{
275 ProcessSerialNumber psn;
276
277 GetEventParameter(inEvent,
278 kEventParamProcessID,
279 typeProcessSerialNumber,
280 NULL,
281 sizeof(psn),
282 NULL,
283 &psn);
284
285 if( GetEventKind(inEvent) == kEventAppTerminated )
286 {
287 Boolean matching_psn = FALSE;
288 OSErr os_result = SameProcess(&psn, (ProcessSerialNumber*)inUserData, &matching_psn);
289 if(os_result >= 0 && matching_psn)
290 {
291 sCrashReporterIsRunning = false;
292 }
293 }
294 return noErr;
295}
296
259void LLAppViewerMacOSX::handleCrashReporting(bool reportFreeze) 297void LLAppViewerMacOSX::handleCrashReporting(bool reportFreeze)
260{ 298{
299 // This used to use fork&exec, but is switched to LSOpenApplication to
300 // Make sure the crash reporter launches in front of the SL window.
301
261 std::string command_str; 302 std::string command_str;
262 //command_str = "open Second Life.app/Contents/Resources/mac-crash-logger.app"; 303 //command_str = "open Second Life.app/Contents/Resources/mac-crash-logger.app";
263 command_str = "mac-crash-logger.app/Contents/MacOS/mac-crash-logger"; 304 command_str = "mac-crash-logger.app/Contents/MacOS/mac-crash-logger";
@@ -279,15 +320,69 @@ void LLAppViewerMacOSX::handleCrashReporting(bool reportFreeze)
279 { 320 {
280 // Make sure freeze reporting launches the crash logger synchronously, lest 321 // Make sure freeze reporting launches the crash logger synchronously, lest
281 // Log files get changed by SL while the logger is running. 322 // Log files get changed by SL while the logger is running.
323
324 // *NOTE:Mani A better way - make a copy of the data that the crash reporter will send
325 // and let SL go about its business. This way makes the mac work like windows and linux
326 // and is the smallest patch for the issue.
327 sCrashReporterIsRunning = true;
328 ProcessSerialNumber o_psn;
329
330 static EventHandlerRef sCarbonEventsRef = NULL;
331 static const EventTypeSpec kEvents[] =
332 {
333 { kEventClassApplication, kEventAppTerminated }
334 };
335
336 // Install the handler to detect crash logger termination
337 InstallEventHandler(GetApplicationEventTarget(),
338 (EventHandlerUPP) CarbonEventHandler,
339 GetEventTypeCount(kEvents),
340 kEvents,
341 &o_psn,
342 &sCarbonEventsRef
343 );
344
345 // Remove, temporarily the quit handler - which has *crash* behavior before
346 // the mainloop gets running!
347 AERemoveEventHandler(kCoreEventClass,
348 kAEQuitApplication,
349 NewAEEventHandlerUPP(AEQuitHandler),
350 false);
351
352 // Launch the crash reporter.
353 os_result = LSOpenApplication(&appParams, &o_psn);
354
355 if(os_result >= 0)
356 {
357 EventRecord evt;
358 while(sCrashReporterIsRunning)
359 {
360 while(WaitNextEvent(osMask, &evt, 0, NULL))
361 {
362 // null op!?!
363 }
364 }
365 }
366
367 // Re-install the apps quit handler.
368 AEInstallEventHandler(kCoreEventClass,
369 kAEQuitApplication,
370 NewAEEventHandlerUPP(AEQuitHandler),
371 0,
372 false);
373
374 // Remove the crash reporter quit handler.
375 RemoveEventHandler(sCarbonEventsRef);
282 } 376 }
283 else 377 else
284 { 378 {
285 appParams.flags |= kLSLaunchAsync; 379 appParams.flags |= kLSLaunchAsync;
286 clear_signals(); 380 clear_signals();
381
382 ProcessSerialNumber o_psn;
383 os_result = LSOpenApplication(&appParams, &o_psn);
287 } 384 }
288 385
289 ProcessSerialNumber o_psn;
290 os_result = LSOpenApplication(&appParams, &o_psn);
291 } 386 }
292 387
293 if(!reportFreeze) 388 if(!reportFreeze)
@@ -352,15 +447,6 @@ OSErr AEGURLHandler(const AppleEvent *messagein, AppleEvent *reply, long refIn)
352 return(result); 447 return(result);
353} 448}
354 449
355OSErr AEQuitHandler(const AppleEvent *messagein, AppleEvent *reply, long refIn)
356{
357 OSErr result = noErr;
358
359 LLAppViewer::instance()->userQuit();
360
361 return(result);
362}
363
364OSStatus simpleDialogHandler(EventHandlerCallRef handler, EventRef event, void *userdata) 450OSStatus simpleDialogHandler(EventHandlerCallRef handler, EventRef event, void *userdata)
365{ 451{
366 OSStatus result = eventNotHandledErr; 452 OSStatus result = eventNotHandledErr;