LocalProcess.patch
uppsrc/Core/LocalProcess.cpp (working copy) | ||
---|---|---|
17 | 17 |
#endif |
18 | 18 |
#ifdef PLATFORM_POSIX |
19 | 19 |
pid = 0; |
20 |
doublefork = false; |
|
20 | 21 |
rpipe[0] = rpipe[1] = wpipe[0] = wpipe[1] = epipe[0] = epipe[1] = -1; |
21 | 22 |
#endif |
22 | 23 |
exit_code = Null; |
... | ... | |
264 | 265 |
sNoBlock(epipe[0]); |
265 | 266 |
close(epipe[1]); epipe[1]=-1; |
266 | 267 |
} |
268 |
if (doublefork) |
|
269 |
pid = 0; |
|
267 | 270 |
return true; |
268 | 271 |
} |
272 |
|
|
273 |
if (doublefork) { |
|
274 |
pid_t pid2 = fork(); |
|
275 |
LLOG("\tfork2, pid2 = " << (int)pid2 << ", getpid = " << (int)getpid()); |
|
276 |
if (pid2 < 0) { |
|
277 |
LLOG("fork2 failed"); |
|
278 |
Exit(1); |
|
279 |
} |
|
280 |
if (pid2) { |
|
281 |
LLOG("exiting intermediary process"); |
|
282 |
close(rpipe[0]); rpipe[0]=-1; |
|
283 |
close(wpipe[1]); wpipe[1]=-1; |
|
284 |
sNoBlock(rpipe[1]); |
|
285 |
sNoBlock(wpipe[0]); |
|
286 |
if (spliterr) { |
|
287 |
sNoBlock(epipe[0]); |
|
288 |
close(epipe[1]); epipe[1]=-1; |
|
289 |
} |
|
290 |
// we call exec instead of Exit, because exit doesn't behave nicelly with threads |
|
291 |
execl("/usr/bin/true", "[closing fork]", (char*)NULL); |
|
292 |
// only call Exit when execl fails |
|
293 |
Exit(0); |
|
294 |
} |
|
295 |
} |
|
296 |
|
|
269 | 297 |
LLOG("child process - execute application"); |
270 | 298 |
// rpipe[1] = wpipe[0] = -1; |
271 | 299 |
dup2(rpipe[0], 0); |
... | ... | |
372 | 400 |
|
373 | 401 |
void LocalProcess::Detach() |
374 | 402 |
{ |
403 |
#ifdef PLATFORM_POSIX |
|
404 |
if (doublefork) |
|
405 |
waitpid(pid, 0, WUNTRACED); |
|
406 |
#endif |
|
375 | 407 |
Free(); |
376 | 408 |
} |
377 | 409 |
|
uppsrc/Core/LocalProcess.h (working copy) | ||
---|---|---|
52 | 52 |
pid_t pid; |
53 | 53 |
int rpipe[2], wpipe[2], epipe[2]; |
54 | 54 |
String exit_string; |
55 |
bool doublefork; |
|
55 | 56 |
#endif |
56 | 57 |
int exit_code; |
57 | 58 |
String wreso, wrese; // Output fetched during Write |
... | ... | |
68 | 69 |
bool Start2(const char *cmd, const Vector<String>& arg, const char *envptr = NULL) { return DoStart(cmd, &arg, true, envptr); } |
69 | 70 |
|
70 | 71 |
#ifdef PLATFORM_POSIX |
72 |
LocalProcess& DoubleFork(bool b = true) { doublefork = b; return *this; } |
|
73 |
LocalProcess& NoDoubleFork(bool b = true) { return DoubleFork(false); } |
|
74 |
|
|
71 | 75 |
int GetPid() const { return pid; } |
72 | 76 |
#endif |
73 | 77 |
|