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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
8 #if defined(OS_MACOSX) | 8 #if defined(OS_MACOSX) |
9 extern "C" { | 9 extern "C" { |
10 #include <sandbox.h> | 10 #include <sandbox.h> |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // of descriptors, and not because of the channel closing unexpectedly. | 146 // of descriptors, and not because of the channel closing unexpectedly. |
147 CHECK(listener.GotExpectedNumberOfDescriptors()); | 147 CHECK(listener.GotExpectedNumberOfDescriptors()); |
148 | 148 |
149 return 0; | 149 return 0; |
150 } | 150 } |
151 | 151 |
152 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendFdsClient) { | 152 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendFdsClient) { |
153 struct stat st; | 153 struct stat st; |
154 int fd = open(kDevZeroPath, O_RDONLY); | 154 int fd = open(kDevZeroPath, O_RDONLY); |
155 fstat(fd, &st); | 155 fstat(fd, &st); |
156 EXPECT_GE(HANDLE_EINTR(close(fd)), 0); | 156 EXPECT_GE(IGNORE_EINTR(close(fd)), 0); |
157 return SendFdsClientCommon("SendFdsClient", st.st_ino); | 157 return SendFdsClientCommon("SendFdsClient", st.st_ino); |
158 } | 158 } |
159 | 159 |
160 #if defined(OS_MACOSX) | 160 #if defined(OS_MACOSX) |
161 // Test that FDs are correctly sent to a sandboxed process. | 161 // Test that FDs are correctly sent to a sandboxed process. |
162 // TODO(port): Make this test cross-platform. | 162 // TODO(port): Make this test cross-platform. |
163 TEST_F(IPCSendFdsTest, DescriptorTestSandboxed) { | 163 TEST_F(IPCSendFdsTest, DescriptorTestSandboxed) { |
164 Init("SendFdsSandboxedClient"); | 164 Init("SendFdsSandboxedClient"); |
165 RunServer(); | 165 RunServer(); |
166 } | 166 } |
167 | 167 |
168 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendFdsSandboxedClient) { | 168 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendFdsSandboxedClient) { |
169 struct stat st; | 169 struct stat st; |
170 const int fd = open(kDevZeroPath, O_RDONLY); | 170 const int fd = open(kDevZeroPath, O_RDONLY); |
171 fstat(fd, &st); | 171 fstat(fd, &st); |
172 if (HANDLE_EINTR(close(fd)) < 0) | 172 if (IGNORE_EINTR(close(fd)) < 0) |
173 return -1; | 173 return -1; |
174 | 174 |
175 // Enable the sandbox. | 175 // Enable the sandbox. |
176 char* error_buff = NULL; | 176 char* error_buff = NULL; |
177 int error = sandbox_init(kSBXProfilePureComputation, SANDBOX_NAMED, | 177 int error = sandbox_init(kSBXProfilePureComputation, SANDBOX_NAMED, |
178 &error_buff); | 178 &error_buff); |
179 bool success = (error == 0 && error_buff == NULL); | 179 bool success = (error == 0 && error_buff == NULL); |
180 if (!success) | 180 if (!success) |
181 return -1; | 181 return -1; |
182 | 182 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 for (int i = 0; i < pipes_to_send; i++) { | 314 for (int i = 0; i < pipes_to_send; i++) { |
315 received_.Reset(); | 315 received_.Reset(); |
316 std::pair<int, int> pipe_fds = make_socket_pair(); | 316 std::pair<int, int> pipe_fds = make_socket_pair(); |
317 t->message_loop()->PostTask( | 317 t->message_loop()->PostTask( |
318 FROM_HERE, | 318 FROM_HERE, |
319 base::Bind(&PipeChannelHelper::Send, | 319 base::Bind(&PipeChannelHelper::Send, |
320 base::Unretained(dest), | 320 base::Unretained(dest), |
321 pipe_fds.second)); | 321 pipe_fds.second)); |
322 char tmp = 'x'; | 322 char tmp = 'x'; |
323 CHECK_EQ(1, HANDLE_EINTR(write(pipe_fds.first, &tmp, 1))); | 323 CHECK_EQ(1, HANDLE_EINTR(write(pipe_fds.first, &tmp, 1))); |
324 CHECK_EQ(0, HANDLE_EINTR(close(pipe_fds.first))); | 324 CHECK_EQ(0, IGNORE_EINTR(close(pipe_fds.first))); |
325 received_.Wait(); | 325 received_.Wait(); |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 void ConsumerHandleFD(int fd) { | 329 void ConsumerHandleFD(int fd) { |
330 char tmp = 'y'; | 330 char tmp = 'y'; |
331 CHECK_EQ(1, HANDLE_EINTR(read(fd, &tmp, 1))); | 331 CHECK_EQ(1, HANDLE_EINTR(read(fd, &tmp, 1))); |
332 CHECK_EQ(tmp, 'x'); | 332 CHECK_EQ(tmp, 'x'); |
333 CHECK_EQ(0, HANDLE_EINTR(close(fd))); | 333 CHECK_EQ(0, IGNORE_EINTR(close(fd))); |
334 received_.Signal(); | 334 received_.Signal(); |
335 } | 335 } |
336 | 336 |
337 base::Thread* CreateThread(const char* name) { | 337 base::Thread* CreateThread(const char* name) { |
338 base::Thread* ret = new base::Thread(name); | 338 base::Thread* ret = new base::Thread(name); |
339 base::Thread::Options options; | 339 base::Thread::Options options; |
340 options.message_loop_type = base::MessageLoop::TYPE_IO; | 340 options.message_loop_type = base::MessageLoop::TYPE_IO; |
341 ret->StartWithOptions(options); | 341 ret->StartWithOptions(options); |
342 return ret; | 342 return ret; |
343 } | 343 } |
(...skipping 27 matching lines...) Expand all Loading... |
371 base::WaitableEvent received_; | 371 base::WaitableEvent received_; |
372 }; | 372 }; |
373 | 373 |
374 TEST_F(IPCMultiSendingFdsTest, StressTest) { | 374 TEST_F(IPCMultiSendingFdsTest, StressTest) { |
375 Run(); | 375 Run(); |
376 } | 376 } |
377 | 377 |
378 } // namespace | 378 } // namespace |
379 | 379 |
380 #endif // defined(OS_POSIX) | 380 #endif // defined(OS_POSIX) |
OLD | NEW |