gecko-dev/xpcom/threads/nsProcess.h
Jed Davis b39b9e95d4 Bug 1406971 - Change nsProcess to use LaunchApp from IPC, instead of NSPR, on Unix. r=froydnj
This also fixes the Unix part of bug 678369, and fixes bug 147659 as a
convenient side-effect of using LaunchApp (which has the desired
fd-closing behavior already) rather than directly using fork/exec.

The main goal is to work around bug 227246, where PR_CreateProcess on
Unix interferes with anything else that tries to use child processes.
This does not fix that bug -- NSPR will still cause problems if used in
that way -- but it's an adequate workaround for that bug in Gecko in
almost all cases (the one known exception is nsAuthSambaNTLM, which uses
NSPR directly and needs to be fixed separately).

Waiting for the child process uses waitpid() directly, sharing the
existing code used for OS X.

MozReview-Commit-ID: 6zfZ1Zgk2i9

--HG--
extra : rebase_source : e8230503d82943af4563d8d63baa029d8a698683
2017-10-06 19:58:33 -06:00

85 lines
2.2 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _nsPROCESSWIN_H_
#define _nsPROCESSWIN_H_
#if defined(XP_WIN)
#define PROCESSMODEL_WINAPI
#endif
#include "mozilla/Attributes.h"
#include "mozilla/Mutex.h"
#include "nsIProcess.h"
#include "nsIFile.h"
#include "nsIThread.h"
#include "nsIObserver.h"
#include "nsIWeakReferenceUtils.h"
#include "nsIObserver.h"
#include "nsString.h"
#ifndef XP_UNIX
#include "prproces.h"
#endif
#if defined(PROCESSMODEL_WINAPI)
#include <windows.h>
#include <shellapi.h>
#endif
#define NS_PROCESS_CID \
{0x7b4eeb20, 0xd781, 0x11d4, \
{0x8A, 0x83, 0x00, 0x10, 0xa4, 0xe0, 0xc9, 0xca}}
class nsProcess final
: public nsIProcess
, public nsIObserver
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIPROCESS
NS_DECL_NSIOBSERVER
nsProcess();
private:
~nsProcess();
static void Monitor(void* aArg);
void ProcessComplete();
nsresult CopyArgsAndRunProcess(bool aBlocking, const char** aArgs,
uint32_t aCount, nsIObserver* aObserver,
bool aHoldWeak);
nsresult CopyArgsAndRunProcessw(bool aBlocking, const char16_t** aArgs,
uint32_t aCount, nsIObserver* aObserver,
bool aHoldWeak);
// The 'args' array is null-terminated.
nsresult RunProcess(bool aBlocking, char** aArgs, nsIObserver* aObserver,
bool aHoldWeak, bool aArgsUTF8);
PRThread* mThread;
mozilla::Mutex mLock;
bool mShutdown;
bool mBlocking;
bool mStartHidden;
bool mNoShell;
nsCOMPtr<nsIFile> mExecutable;
nsString mTargetPath;
int32_t mPid;
nsCOMPtr<nsIObserver> mObserver;
nsWeakPtr mWeakObserver;
// These members are modified by multiple threads, any accesses should be
// protected with mLock.
int32_t mExitValue;
#if defined(PROCESSMODEL_WINAPI)
HANDLE mProcess;
#elif !defined(XP_UNIX)
PRProcess* mProcess;
#endif
};
#endif