From 6f9b0350d94a322c603be4507fcdc4ed3cb7c76c Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Sat, 12 Jul 2008 03:46:11 -0500 Subject: [PATCH] Bug 440840 - "mailcap handling may fail due to race conditions between thread waiting and system()" [p=mh+mozilla@glandium.org (Mike Hommey) r+sr=bzbarsky] --- .../exthandler/unix/nsOSHelperAppService.cpp | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/uriloader/exthandler/unix/nsOSHelperAppService.cpp b/uriloader/exthandler/unix/nsOSHelperAppService.cpp index dc92a2d7dbc..0023c4e5fc2 100644 --- a/uriloader/exthandler/unix/nsOSHelperAppService.cpp +++ b/uriloader/exthandler/unix/nsOSHelperAppService.cpp @@ -67,7 +67,6 @@ #include "nsDirectoryServiceUtils.h" #include "prenv.h" // for PR_GetEnv() #include "nsAutoPtr.h" -#include // for system() #define LOG(args) PR_LOG(mLog, PR_LOG_DEBUG, args) #define LOG_ENABLED() PR_LOG_TEST(mLog, PR_LOG_DEBUG) @@ -1141,9 +1140,32 @@ nsOSHelperAppService::GetHandlerAndDescriptionFromMailcapFile(const nsAString& a aMinorType, aTypeOptions, testCommand); + if (NS_FAILED(rv)) + continue; + nsCOMPtr process = do_CreateInstance(NS_PROCESS_CONTRACTID, &rv); + if (NS_FAILED(rv)) + continue; + nsCOMPtr file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv)); + if (NS_FAILED(rv)) + continue; + rv = file->InitWithNativePath(NS_LITERAL_CSTRING("/bin/sh")); + if (NS_FAILED(rv)) + continue; + rv = process->Init(file); + if (NS_FAILED(rv)) + continue; + const char *args[] = { "-c", testCommand.get() }; LOG(("Running Test: %s\n", testCommand.get())); - // XXX this should not use system(), since that can block the UI thread! - if (NS_SUCCEEDED(rv) && system(testCommand.get()) != 0) { + PRUint32 pid; + rv = process->Run(PR_TRUE, args, 2, &pid); + if (NS_FAILED(rv)) + continue; + PRInt32 exitValue; + rv = process->GetExitValue(&exitValue); + if (NS_FAILED(rv)) + continue; + LOG(("Exit code: %d\n", exitValue)); + if (exitValue) { match = PR_FALSE; } }