OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/process/launch.h" | 5 #include "base/process/launch.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <signal.h> | 10 #include <signal.h> |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 InjectiveMultimap fd_shuffle1; | 387 InjectiveMultimap fd_shuffle1; |
388 InjectiveMultimap fd_shuffle2; | 388 InjectiveMultimap fd_shuffle2; |
389 fd_shuffle1.reserve(fd_shuffle_size); | 389 fd_shuffle1.reserve(fd_shuffle_size); |
390 fd_shuffle2.reserve(fd_shuffle_size); | 390 fd_shuffle2.reserve(fd_shuffle_size); |
391 | 391 |
392 scoped_ptr<char*[]> argv_cstr(new char*[argv.size() + 1]); | 392 scoped_ptr<char*[]> argv_cstr(new char*[argv.size() + 1]); |
393 scoped_ptr<char*[]> new_environ; | 393 scoped_ptr<char*[]> new_environ; |
394 if (options.environ) | 394 if (options.environ) |
395 new_environ.reset(AlterEnvironment(*options.environ, GetEnvironment())); | 395 new_environ.reset(AlterEnvironment(*options.environ, GetEnvironment())); |
396 | 396 |
397 sigset_t full_sigset; | |
398 sigfillset(&full_sigset); | |
399 sigset_t old_sigset; | |
400 if (pthread_sigmask(SIG_BLOCK, &full_sigset, &old_sigset) != 0) { | |
Markus (顧孟勤)
2013/08/01 01:20:54
In principle, I believe this works OK. But you are
Markus (顧孟勤)
2013/08/01 01:20:54
And now for a nitpick:
It is actually not possibl
mdempsky_google
2013/08/01 16:25:05
https://code.google.com/p/chromium/issues/detail?i
mdempsky_google
2013/08/01 16:25:05
I expect sigfillset() + pthread_sigmask() should b
| |
401 DPLOG(ERROR) << "pthread_sigmask"; | |
402 return false; | |
403 } | |
404 | |
397 pid_t pid; | 405 pid_t pid; |
398 #if defined(OS_LINUX) | 406 #if defined(OS_LINUX) |
399 if (options.clone_flags) { | 407 if (options.clone_flags) { |
400 pid = syscall(__NR_clone, options.clone_flags, 0, 0, 0); | 408 pid = syscall(__NR_clone, options.clone_flags, 0, 0, 0); |
Markus (顧孟勤)
2013/08/01 01:20:54
Do you by chance happen to know if we use this cod
mdempsky_google
2013/08/01 16:25:05
Not really. According to cs.chromium.org, the onl
| |
401 } else | 409 } else |
402 #endif | 410 #endif |
403 { | 411 { |
404 pid = fork(); | 412 pid = fork(); |
405 } | 413 } |
406 | 414 |
415 if (pid != 0) { | |
416 if (pthread_sigmask(SIG_SETMASK, &old_sigset, NULL) != 0) { | |
417 NOTREACHED(); | |
418 } | |
419 } | |
420 | |
407 if (pid < 0) { | 421 if (pid < 0) { |
408 DPLOG(ERROR) << "fork"; | 422 DPLOG(ERROR) << "fork"; |
409 return false; | 423 return false; |
410 } else if (pid == 0) { | 424 } else if (pid == 0) { |
411 // Child process | 425 // Child process |
412 | 426 |
413 // DANGER: fork() rule: in the child, if you don't end up doing exec*(), | 427 // DANGER: fork() rule: in the child, if you don't end up doing exec*(), |
414 // you call _exit() instead of exit(). This is because _exit() does not | 428 // you call _exit() instead of exit(). This is because _exit() does not |
415 // call any previously-registered (in the parent) exit handlers, which | 429 // call any previously-registered (in the parent) exit handlers, which |
416 // might do things like block waiting for threads that don't even exist | 430 // might do things like block waiting for threads that don't even exist |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 } | 476 } |
463 } | 477 } |
464 } | 478 } |
465 } | 479 } |
466 | 480 |
467 #if defined(OS_MACOSX) | 481 #if defined(OS_MACOSX) |
468 RestoreDefaultExceptionHandler(); | 482 RestoreDefaultExceptionHandler(); |
469 #endif // defined(OS_MACOSX) | 483 #endif // defined(OS_MACOSX) |
470 | 484 |
471 ResetChildSignalHandlersToDefaults(); | 485 ResetChildSignalHandlersToDefaults(); |
486 if (pthread_sigmask(SIG_SETMASK, &old_sigset, NULL) != 0) { | |
487 NOTREACHED(); | |
488 } | |
472 | 489 |
473 #if 0 | 490 #if 0 |
474 // When debugging it can be helpful to check that we really aren't making | 491 // When debugging it can be helpful to check that we really aren't making |
475 // any hidden calls to malloc. | 492 // any hidden calls to malloc. |
476 void *malloc_thunk = | 493 void *malloc_thunk = |
477 reinterpret_cast<void*>(reinterpret_cast<intptr_t>(malloc) & ~4095); | 494 reinterpret_cast<void*>(reinterpret_cast<intptr_t>(malloc) & ~4095); |
478 mprotect(malloc_thunk, 4096, PROT_READ | PROT_WRITE | PROT_EXEC); | 495 mprotect(malloc_thunk, 4096, PROT_READ | PROT_WRITE | PROT_EXEC); |
479 memset(reinterpret_cast<void*>(malloc), 0xff, 8); | 496 memset(reinterpret_cast<void*>(malloc), 0xff, 8); |
480 #endif // 0 | 497 #endif // 0 |
481 | 498 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
720 std::string* output, | 737 std::string* output, |
721 int* exit_code) { | 738 int* exit_code) { |
722 // Run |execve()| with the current environment and store "unlimited" data. | 739 // Run |execve()| with the current environment and store "unlimited" data. |
723 GetAppOutputInternalResult result = GetAppOutputInternal( | 740 GetAppOutputInternalResult result = GetAppOutputInternal( |
724 cl.argv(), NULL, output, std::numeric_limits<std::size_t>::max(), true, | 741 cl.argv(), NULL, output, std::numeric_limits<std::size_t>::max(), true, |
725 exit_code); | 742 exit_code); |
726 return result == EXECUTE_SUCCESS; | 743 return result == EXECUTE_SUCCESS; |
727 } | 744 } |
728 | 745 |
729 } // namespace base | 746 } // namespace base |
OLD | NEW |