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, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 | 66 |
67 void MultiprocessExec::MultiprocessChild() { | 67 void MultiprocessExec::MultiprocessChild() { |
68 // Make sure that stdin, stdout, and stderr are FDs 0, 1, and 2, respectively. | 68 // Make sure that stdin, stdout, and stderr are FDs 0, 1, and 2, respectively. |
69 // All FDs above this will be closed. | 69 // All FDs above this will be closed. |
70 static_assert(STDIN_FILENO == 0, "stdin must be fd 0"); | 70 static_assert(STDIN_FILENO == 0, "stdin must be fd 0"); |
71 static_assert(STDOUT_FILENO == 1, "stdout must be fd 1"); | 71 static_assert(STDOUT_FILENO == 1, "stdout must be fd 1"); |
72 static_assert(STDERR_FILENO == 2, "stderr must be fd 2"); | 72 static_assert(STDERR_FILENO == 2, "stderr must be fd 2"); |
73 | 73 |
74 // Move the read pipe to stdin. | 74 // Move the read pipe to stdin. |
75 int read_fd = ReadPipeFD(); | 75 int read_fd = ReadPipeHandle(); |
76 ASSERT_NE(read_fd, STDIN_FILENO); | 76 ASSERT_NE(read_fd, STDIN_FILENO); |
77 ASSERT_NE(read_fd, STDOUT_FILENO); | 77 ASSERT_NE(read_fd, STDOUT_FILENO); |
78 ASSERT_EQ(STDIN_FILENO, fileno(stdin)); | 78 ASSERT_EQ(STDIN_FILENO, fileno(stdin)); |
79 | 79 |
80 int rv = fpurge(stdin); | 80 int rv = fpurge(stdin); |
81 ASSERT_EQ(0, rv) << ErrnoMessage("fpurge"); | 81 ASSERT_EQ(0, rv) << ErrnoMessage("fpurge"); |
82 | 82 |
83 rv = HANDLE_EINTR(dup2(read_fd, STDIN_FILENO)); | 83 rv = HANDLE_EINTR(dup2(read_fd, STDIN_FILENO)); |
84 ASSERT_EQ(STDIN_FILENO, rv) << ErrnoMessage("dup2"); | 84 ASSERT_EQ(STDIN_FILENO, rv) << ErrnoMessage("dup2"); |
85 | 85 |
86 // Move the write pipe to stdout. | 86 // Move the write pipe to stdout. |
87 int write_fd = WritePipeFD(); | 87 int write_fd = WritePipeHandle(); |
88 ASSERT_NE(write_fd, STDIN_FILENO); | 88 ASSERT_NE(write_fd, STDIN_FILENO); |
89 ASSERT_NE(write_fd, STDOUT_FILENO); | 89 ASSERT_NE(write_fd, STDOUT_FILENO); |
90 ASSERT_EQ(STDOUT_FILENO, fileno(stdout)); | 90 ASSERT_EQ(STDOUT_FILENO, fileno(stdout)); |
91 | 91 |
92 // Make a copy of the original stdout file descriptor so that in case there’s | 92 // Make a copy of the original stdout file descriptor so that in case there’s |
93 // an execv() failure, the original stdout can be restored so that gtest | 93 // an execv() failure, the original stdout can be restored so that gtest |
94 // messages directed to stdout go to the right place. Mark it as | 94 // messages directed to stdout go to the right place. Mark it as |
95 // close-on-exec, so that the child won’t see it after a successful exec(), | 95 // close-on-exec, so that the child won’t see it after a successful exec(), |
96 // but it will still be available in this process after an unsuccessful | 96 // but it will still be available in this process after an unsuccessful |
97 // exec(). | 97 // exec(). |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 IGNORE_EINTR(close(STDOUT_FILENO)); | 131 IGNORE_EINTR(close(STDOUT_FILENO)); |
132 HANDLE_EINTR(dup2(dup_orig_stdout_fd, STDOUT_FILENO)); | 132 HANDLE_EINTR(dup2(dup_orig_stdout_fd, STDOUT_FILENO)); |
133 IGNORE_EINTR(close(dup_orig_stdout_fd)); | 133 IGNORE_EINTR(close(dup_orig_stdout_fd)); |
134 | 134 |
135 forbid_return.Disarm(); | 135 forbid_return.Disarm(); |
136 FAIL() << ErrnoMessage("execv") << ": " << argv_[0]; | 136 FAIL() << ErrnoMessage("execv") << ": " << argv_[0]; |
137 } | 137 } |
138 | 138 |
139 } // namespace test | 139 } // namespace test |
140 } // namespace crashpad | 140 } // namespace crashpad |
OLD | NEW |