From 8bb68e879f96f85999d962f4a4b214430975ac4e Mon Sep 17 00:00:00 2001 From: "sgehani%netscape.com" Date: Wed, 28 Mar 2001 00:45:05 +0000 Subject: [PATCH] 66735: implement blocking processes on the mac. --- xpcom/threads/nsProcessMac.cpp | 62 +++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/xpcom/threads/nsProcessMac.cpp b/xpcom/threads/nsProcessMac.cpp index ad5c5d94b040..35aacfe012a5 100644 --- a/xpcom/threads/nsProcessMac.cpp +++ b/xpcom/threads/nsProcessMac.cpp @@ -20,6 +20,7 @@ * * Contributor(s): * Don Bragg + * Samir Gehani */ /***************************************************************************** @@ -37,6 +38,7 @@ #include "prtypes.h" #include "prio.h" +#include "prthread.h" #include #include @@ -81,26 +83,54 @@ nsProcess::Init(nsIFile* executable) NS_IMETHODIMP nsProcess::Run(PRBool blocking, const char **args, PRUint32 count, PRUint32 *pid) { - OSErr err = noErr; - LaunchParamBlockRec launchPB; - FSSpec* targetSpec; + OSErr err = noErr; + LaunchParamBlockRec launchPB; + FSSpec resolvedSpec; + Boolean bDone = false; + ProcessInfoRec info; nsCOMPtr macExecutable = do_QueryInterface(mExecutable); - macExecutable->GetFSSpec(targetSpec); - - launchPB.launchAppSpec = targetSpec; - launchPB.launchAppParameters = NULL; - launchPB.launchBlockID = extendedBlock; - launchPB.launchEPBLength = extendedBlockLen; - launchPB.launchFileFlags = NULL; - launchPB.launchControlFlags = launchContinue + launchNoFileFlags + launchUseMinimum; - launchPB.launchControlFlags += launchDontSwitch; + macExecutable->GetResolvedFSSpec(&resolvedSpec); - err = LaunchApplication(&launchPB); - if (err != noErr) - return NS_ERROR_FAILURE; + launchPB.launchAppSpec = &resolvedSpec; + launchPB.launchAppParameters = NULL; + launchPB.launchBlockID = extendedBlock; + launchPB.launchEPBLength = extendedBlockLen; + launchPB.launchFileFlags = NULL; + launchPB.launchControlFlags = launchContinue + launchNoFileFlags + launchUseMinimum; + if (!blocking) + launchPB.launchControlFlags += launchDontSwitch; + + err = LaunchApplication(&launchPB); + if (err != noErr) + return NS_ERROR_FAILURE; - return NS_OK; + // NOTE: blocking mode assumes you are running on a thread + // other than the UI thread that has teh main event loop + if (blocking) + { + do + { + info.processInfoLength = sizeof(ProcessInfoRec); + info.processName = nil; + info.processAppSpec = nil; + err = GetProcessInformation(&launchPB.launchProcessSN, &info); + + if (err == noErr) + { + // still running so sleep some more (200 msecs) + PR_Sleep(200); + } + else + { + // no longer in process manager's internal list: so assume done + bDone = true; + } + } + while (!bDone); + } + + return NS_OK; } NS_IMETHODIMP nsProcess::InitWithPid(PRUint32 pid)