1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Mozilla Public
5
* License Version 1.1 (the "MPL"); you may not use this file
6
* except in compliance with the MPL. You may obtain a copy of
7
* the MPL at http://www.mozilla.org/MPL/
9
* Software distributed under the MPL is distributed on an "AS
10
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11
* implied. See the MPL for the specific language governing
12
* rights and limitations under the MPL.
14
* The Original Code is the Netscape Portable Runtime (NSPR).
16
* The Initial Developer of the Original Code is Netscape
17
* Communications Corporation. Portions created by Netscape are
18
* Copyright (C) 1998-2000 Netscape Communications Corporation. All
22
* Ramalingam Saravanan <svn@xmlterm.org>
23
* Patrick Brunschwig <patrick@mozilla-enigmail.org>
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the MPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
39
#ifndef IPCProcess_h__
40
#define IPCProcess_h__
46
/* Define XP_WIN_IPC to enable Win32-specific IPC stuff;
47
* this avoids some problems with the NSPR IPC implementation on Win32
48
* which can sometimes cause processes to hang when trying to read STDIN
59
typedef DWORD (WINAPI*GetProcessIdPtr)(HANDLE process);
61
#define IPCProcess void
62
#define IPCFileDesc void
63
#define IPC_NULL_HANDLE NULL
65
#define IPC_CreateProcessRedirected IPC_CreateProcessRedirectedWin32
66
#define IPC_CreateInheritablePipe IPC_CreateInheritablePipeWin32
68
#define IPC_WaitProcess IPC_WaitProcessWin32
69
#define IPC_KillProcess IPC_KillProcessWin32
70
#define IPC_GetProcessId IPC_GetProcessIdWin32
71
#define IPC_Read IPC_ReadWin32
72
#define IPC_Write IPC_WriteWin32
73
#define IPC_Close IPC_CloseWin32
74
#define IPC_GetError IPC_GetErrorWin32
78
#define IPCProcess PRProcess
79
#define IPCFileDesc PRFileDesc
80
#define IPC_NULL_HANDLE NULL
82
#define IPC_CreateProcessRedirected IPC_CreateProcessRedirectedNSPR
83
#define IPC_CreateInheritablePipe IPC_CreateInheritablePipeNSPR
85
#define IPC_WaitProcess PR_WaitProcess
86
#define IPC_KillProcess PR_KillProcess
87
#define IPC_GetProcessId IPC_GetProcessIdNSPR
88
#define IPC_Read PR_Read
89
#define IPC_Write PR_Write
90
#define IPC_Close PR_Close
91
#define IPC_GetError PR_GetError
92
#endif /* !XP_WIN_IPC */
95
* Creates a process and assigns the stdin/stdout/stderr file descriptors
97
* @param path Path to the executable file in native encoding
98
* @param argv Array of arguments to the process in native encoding
99
* @param envp Array of environment variables in native encoding
100
* @param cwd The subprocess' woring directory in native encoding
101
* @param std_in The STDIN file descriptor of the subprocess
102
* @param std_out The STDOUT file descriptor of the subprocess
103
* @param std_err The STDERR file descriptor of the subprocess
104
* @param detach True if the process should be detached from the parent
106
PRProcess* IPC_CreateProcessRedirectedNSPR(const char *path,
116
* Set the file descriptors of a pipe, e.g. STDIN, to (not) inheritable
117
* Usually the file descriptor of the intended direction is inheritable (e.g.
120
* @param readPipe File descriptor of the reading pipe
121
* @param writePipe File descriptor of the writing pipe
122
* @param readInherit True if reader should be inheritable
123
* @param writeInherit True if writer should be inheritable
125
PRStatus IPC_CreateInheritablePipeNSPR(PRFileDesc* *readPipe,
126
PRFileDesc* *writePipe,
128
IPCBool writeInherit);
131
* Get the process ID of a running subprocess
133
PRStatus IPC_GetProcessIdNSPR(IPCProcess* process, PRInt32 *pid);
140
* @see IPC_CreateProcessRedirectedNSPR
143
IPCProcess* IPC_CreateProcessRedirectedWin32(const char *path,
148
IPCFileDesc* std_out,
149
IPCFileDesc* std_err,
152
* @see IPC_CreateInheritablePipeNSPR
155
PRStatus IPC_CreateInheritablePipeWin32(IPCFileDesc* *readPipe,
156
IPCFileDesc* *writePipe,
158
IPCBool writeInherit);
161
* @see PR_WaitProcess in prprocess.h
163
PRStatus IPC_WaitProcessWin32(IPCProcess* process, PRInt32 *exitCode);
166
* @see PR_KillProcess in prprocess.h
168
PRStatus IPC_KillProcessWin32(IPCProcess* process);
171
* @see PR_Read in prprocess.h
173
PRInt32 IPC_ReadWin32(IPCFileDesc* fd, void *buf, PRInt32 amount);
176
* @see PR_Write in prprocess.h
178
PRInt32 IPC_WriteWin32(IPCFileDesc* fd, const void *buf, PRInt32 amount);
181
* @see PR_Close in prprocess.h
183
PRStatus IPC_CloseWin32(IPCFileDesc* fd);
186
* @see PR_GetProcessId in prprocess.h
188
PRStatus IPC_GetProcessIdWin32(IPCProcess* process, PRInt32 *pid);
191
* @see PR_GetError in prprocess.h
193
PRErrorCode IPC_GetErrorWin32();
196
#endif // IPCProcess_h__