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 #define _CRT_SECURE_NO_WARNINGS | 5 #define _CRT_SECURE_NO_WARNINGS |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #include <sys/wait.h> | 53 #include <sys/wait.h> |
54 #include <unistd.h> | 54 #include <unistd.h> |
55 #endif | 55 #endif |
56 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
57 #include <windows.h> | 57 #include <windows.h> |
58 #include "base/win/windows_version.h" | 58 #include "base/win/windows_version.h" |
59 #endif | 59 #endif |
60 #if defined(OS_MACOSX) | 60 #if defined(OS_MACOSX) |
61 #include <mach/vm_param.h> | 61 #include <mach/vm_param.h> |
62 #include <malloc/malloc.h> | 62 #include <malloc/malloc.h> |
63 #include "base/mac/mac_util.h" | |
64 #endif | 63 #endif |
65 #if defined(OS_ANDROID) | 64 #if defined(OS_ANDROID) |
66 #include "third_party/lss/linux_syscall_support.h" | 65 #include "third_party/lss/linux_syscall_support.h" |
67 #endif | 66 #endif |
68 | 67 |
69 using base::FilePath; | 68 using base::FilePath; |
70 | 69 |
71 namespace { | 70 namespace { |
72 | 71 |
73 const char kSignalFileSlow[] = "SlowChildProcess.die"; | 72 const char kSignalFileSlow[] = "SlowChildProcess.die"; |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 // Attempt to set a file-descriptor guard on |fd|. In case of success, remove | 564 // Attempt to set a file-descriptor guard on |fd|. In case of success, remove |
566 // it and return |true| to indicate that it can be guarded. Returning |false| | 565 // it and return |true| to indicate that it can be guarded. Returning |false| |
567 // means either that |fd| is guarded by some other code, or more likely EBADF. | 566 // means either that |fd| is guarded by some other code, or more likely EBADF. |
568 // | 567 // |
569 // Starting with 10.9, libdispatch began setting GUARD_DUP on a file descriptor. | 568 // Starting with 10.9, libdispatch began setting GUARD_DUP on a file descriptor. |
570 // Unfortunately, it is spun up as part of +[NSApplication initialize], which is | 569 // Unfortunately, it is spun up as part of +[NSApplication initialize], which is |
571 // not really something that Chromium can avoid using on OSX. See | 570 // not really something that Chromium can avoid using on OSX. See |
572 // <http://crbug.com/338157>. This function allows querying whether the file | 571 // <http://crbug.com/338157>. This function allows querying whether the file |
573 // descriptor is guarded before attempting to close it. | 572 // descriptor is guarded before attempting to close it. |
574 bool CanGuardFd(int fd) { | 573 bool CanGuardFd(int fd) { |
575 // The syscall is first provided in 10.9/Mavericks. | |
576 if (!base::mac::IsOSMavericksOrLater()) | |
577 return true; | |
578 | |
579 // Saves the original flags to reset later. | 574 // Saves the original flags to reset later. |
580 int original_fdflags = 0; | 575 int original_fdflags = 0; |
581 | 576 |
582 // This can be any value at all, it just has to match up between the two | 577 // This can be any value at all, it just has to match up between the two |
583 // calls. | 578 // calls. |
584 const guardid_t kGuard = 15; | 579 const guardid_t kGuard = 15; |
585 | 580 |
586 // Attempt to change the guard. This can fail with EBADF if the file | 581 // Attempt to change the guard. This can fail with EBADF if the file |
587 // descriptor is bad, or EINVAL if the fd already has a guard set. | 582 // descriptor is bad, or EINVAL if the fd already has a guard set. |
588 int ret = | 583 int ret = |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 options.current_directory = base::FilePath("/dev/null"); | 1020 options.current_directory = base::FilePath("/dev/null"); |
1026 | 1021 |
1027 base::Process process(SpawnChildWithOptions("SimpleChildProcess", options)); | 1022 base::Process process(SpawnChildWithOptions("SimpleChildProcess", options)); |
1028 ASSERT_TRUE(process.IsValid()); | 1023 ASSERT_TRUE(process.IsValid()); |
1029 | 1024 |
1030 int exit_code = kSuccess; | 1025 int exit_code = kSuccess; |
1031 EXPECT_TRUE(process.WaitForExit(&exit_code)); | 1026 EXPECT_TRUE(process.WaitForExit(&exit_code)); |
1032 EXPECT_NE(kSuccess, exit_code); | 1027 EXPECT_NE(kSuccess, exit_code); |
1033 } | 1028 } |
1034 #endif // defined(OS_LINUX) | 1029 #endif // defined(OS_LINUX) |
OLD | NEW |