OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "test/multiprocess_exec.h" | 15 #include "test/multiprocess_exec.h" |
16 | 16 |
17 #include <fcntl.h> | 17 #include <fcntl.h> |
18 #include <stdio.h> | 18 #include <stdio.h> |
19 #include <stdlib.h> | 19 #include <stdlib.h> |
20 #include <unistd.h> | 20 #include <unistd.h> |
21 | 21 |
22 #include "base/posix/eintr_wrapper.h" | 22 #include "base/posix/eintr_wrapper.h" |
23 #include "gtest/gtest.h" | 23 #include "gtest/gtest.h" |
24 #include "test/errors.h" | 24 #include "test/errors.h" |
25 #include "util/misc/scoped_forbid_return.h" | 25 #include "util/misc/scoped_forbid_return.h" |
26 #include "util/posix/close_multiple.h" | 26 #include "util/posix/close_multiple.h" |
27 | 27 |
| 28 #if defined(OS_LINUX) |
| 29 #include <stdio_ext.h> |
| 30 #endif |
| 31 |
28 namespace crashpad { | 32 namespace crashpad { |
29 namespace test { | 33 namespace test { |
30 | 34 |
31 MultiprocessExec::MultiprocessExec() | 35 MultiprocessExec::MultiprocessExec() |
32 : Multiprocess(), | 36 : Multiprocess(), |
33 command_(), | 37 command_(), |
34 arguments_(), | 38 arguments_(), |
35 argv_() { | 39 argv_() { |
36 } | 40 } |
37 | 41 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 static_assert(STDIN_FILENO == 0, "stdin must be fd 0"); | 75 static_assert(STDIN_FILENO == 0, "stdin must be fd 0"); |
72 static_assert(STDOUT_FILENO == 1, "stdout must be fd 1"); | 76 static_assert(STDOUT_FILENO == 1, "stdout must be fd 1"); |
73 static_assert(STDERR_FILENO == 2, "stderr must be fd 2"); | 77 static_assert(STDERR_FILENO == 2, "stderr must be fd 2"); |
74 | 78 |
75 // Move the read pipe to stdin. | 79 // Move the read pipe to stdin. |
76 FileHandle read_handle = ReadPipeHandle(); | 80 FileHandle read_handle = ReadPipeHandle(); |
77 ASSERT_NE(read_handle, STDIN_FILENO); | 81 ASSERT_NE(read_handle, STDIN_FILENO); |
78 ASSERT_NE(read_handle, STDOUT_FILENO); | 82 ASSERT_NE(read_handle, STDOUT_FILENO); |
79 ASSERT_EQ(STDIN_FILENO, fileno(stdin)); | 83 ASSERT_EQ(STDIN_FILENO, fileno(stdin)); |
80 | 84 |
81 int rv = fpurge(stdin); | 85 int rv; |
| 86 |
| 87 #if defined(OS_LINUX) |
| 88 __fpurge(stdin); |
| 89 #else |
| 90 rv = fpurge(stdin); |
82 ASSERT_EQ(0, rv) << ErrnoMessage("fpurge"); | 91 ASSERT_EQ(0, rv) << ErrnoMessage("fpurge"); |
| 92 #endif |
83 | 93 |
84 rv = HANDLE_EINTR(dup2(read_handle, STDIN_FILENO)); | 94 rv = HANDLE_EINTR(dup2(read_handle, STDIN_FILENO)); |
85 ASSERT_EQ(STDIN_FILENO, rv) << ErrnoMessage("dup2"); | 95 ASSERT_EQ(STDIN_FILENO, rv) << ErrnoMessage("dup2"); |
86 | 96 |
87 // Move the write pipe to stdout. | 97 // Move the write pipe to stdout. |
88 FileHandle write_handle = WritePipeHandle(); | 98 FileHandle write_handle = WritePipeHandle(); |
89 ASSERT_NE(write_handle, STDIN_FILENO); | 99 ASSERT_NE(write_handle, STDIN_FILENO); |
90 ASSERT_NE(write_handle, STDOUT_FILENO); | 100 ASSERT_NE(write_handle, STDOUT_FILENO); |
91 ASSERT_EQ(STDOUT_FILENO, fileno(stdout)); | 101 ASSERT_EQ(STDOUT_FILENO, fileno(stdout)); |
92 | 102 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 IGNORE_EINTR(close(STDOUT_FILENO)); | 142 IGNORE_EINTR(close(STDOUT_FILENO)); |
133 HANDLE_EINTR(dup2(dup_orig_stdout_fd, STDOUT_FILENO)); | 143 HANDLE_EINTR(dup2(dup_orig_stdout_fd, STDOUT_FILENO)); |
134 IGNORE_EINTR(close(dup_orig_stdout_fd)); | 144 IGNORE_EINTR(close(dup_orig_stdout_fd)); |
135 | 145 |
136 forbid_return.Disarm(); | 146 forbid_return.Disarm(); |
137 FAIL() << ErrnoMessage("execv") << ": " << argv_[0]; | 147 FAIL() << ErrnoMessage("execv") << ": " << argv_[0]; |
138 } | 148 } |
139 | 149 |
140 } // namespace test | 150 } // namespace test |
141 } // namespace crashpad | 151 } // namespace crashpad |
OLD | NEW |