OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <sched.h> | 5 #include <sched.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <string.h> | 7 #include <string.h> |
8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
9 #include <sys/syscall.h> | 9 #include <sys/syscall.h> |
10 #include <sys/wait.h> | 10 #include <sys/wait.h> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
18 #include "base/posix/eintr_wrapper.h" | 18 #include "base/posix/eintr_wrapper.h" |
19 #include "base/posix/unix_domain_socket_linux.h" | 19 #include "base/posix/unix_domain_socket_linux.h" |
20 #include "base/process/process_handle.h" | 20 #include "base/process/process.h" |
21 #include "sandbox/linux/services/syscall_wrappers.h" | 21 #include "sandbox/linux/services/syscall_wrappers.h" |
22 #include "sandbox/linux/tests/unit_tests.h" | 22 #include "sandbox/linux/tests/unit_tests.h" |
23 | 23 |
24 // Additional tests for base's UnixDomainSocket to make sure it behaves | 24 // Additional tests for base's UnixDomainSocket to make sure it behaves |
25 // correctly in the presence of sandboxing functionality (e.g., receiving | 25 // correctly in the presence of sandboxing functionality (e.g., receiving |
26 // PIDs across namespaces). | 26 // PIDs across namespaces). |
27 | 27 |
28 namespace sandbox { | 28 namespace sandbox { |
29 | 29 |
30 namespace { | 30 namespace { |
(...skipping 19 matching lines...) Expand all Loading... |
50 int status; | 50 int status; |
51 CHECK_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0))); | 51 CHECK_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0))); |
52 CHECK(WIFEXITED(status)); | 52 CHECK(WIFEXITED(status)); |
53 CHECK_EQ(0, WEXITSTATUS(status)); | 53 CHECK_EQ(0, WEXITSTATUS(status)); |
54 } | 54 } |
55 | 55 |
56 base::ProcessId GetParentProcessId(base::ProcessId pid) { | 56 base::ProcessId GetParentProcessId(base::ProcessId pid) { |
57 // base::GetParentProcessId() is defined as taking a ProcessHandle instead of | 57 // base::GetParentProcessId() is defined as taking a ProcessHandle instead of |
58 // a ProcessId, even though it's a POSIX-only function and IDs and Handles | 58 // a ProcessId, even though it's a POSIX-only function and IDs and Handles |
59 // are both simply pid_t on POSIX... :/ | 59 // are both simply pid_t on POSIX... :/ |
60 base::ProcessHandle handle; | 60 base::Process process = base::Process::Open(pid); |
61 CHECK(base::OpenProcessHandle(pid, &handle)); | 61 CHECK(process.IsValid()); |
62 base::ProcessId ret = base::GetParentProcessId(pid); | 62 base::ProcessId ret = base::GetParentProcessId(process.Handle()); |
63 base::CloseProcessHandle(handle); | |
64 return ret; | 63 return ret; |
65 } | 64 } |
66 | 65 |
67 // SendHello sends a "hello" to socket fd, and then blocks until the recipient | 66 // SendHello sends a "hello" to socket fd, and then blocks until the recipient |
68 // acknowledges it by calling RecvHello. | 67 // acknowledges it by calling RecvHello. |
69 void SendHello(int fd) { | 68 void SendHello(int fd) { |
70 int pipe_fds[2]; | 69 int pipe_fds[2]; |
71 CHECK_EQ(0, pipe(pipe_fds)); | 70 CHECK_EQ(0, pipe(pipe_fds)); |
72 base::ScopedFD read_pipe(pipe_fds[0]); | 71 base::ScopedFD read_pipe(pipe_fds[0]); |
73 base::ScopedFD write_pipe(pipe_fds[1]); | 72 base::ScopedFD write_pipe(pipe_fds[1]); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 258 |
260 // Parent process. | 259 // Parent process. |
261 recv_sock.reset(); | 260 recv_sock.reset(); |
262 SendHello(send_sock.get()); | 261 SendHello(send_sock.get()); |
263 WaitForExit(pid); | 262 WaitForExit(pid); |
264 } | 263 } |
265 | 264 |
266 } // namespace | 265 } // namespace |
267 | 266 |
268 } // namespace sandbox | 267 } // namespace sandbox |
OLD | NEW |