OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "services/native_support/make_pty_pair.h" | 5 #include "services/native_support/make_pty_pair.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/posix/eintr_wrapper.h" | 13 #include "base/posix/eintr_wrapper.h" |
14 | 14 |
15 namespace native_support { | 15 namespace native_support { |
16 | 16 |
17 bool MakePtyPair(base::ScopedFD* master_fd, | 17 bool MakePtyPair(base::ScopedFD* master_fd, |
18 base::ScopedFD* slave_fd, | 18 base::ScopedFD* slave_fd, |
19 int* errno_value) { | 19 int* errno_value) { |
20 DCHECK(master_fd); | 20 DCHECK(master_fd); |
21 DCHECK(!master_fd->is_valid()); // Not very wrong, but unlikely. | 21 DCHECK(!master_fd->is_valid()); // Not very wrong, but unlikely. |
22 DCHECK(slave_fd); | 22 DCHECK(slave_fd); |
23 DCHECK(!slave_fd->is_valid()); // Not very wrong, but unlikely. | 23 DCHECK(!slave_fd->is_valid()); // Not very wrong, but unlikely. |
24 DCHECK(errno_value); | 24 DCHECK(errno_value); |
25 | 25 |
26 // TODO(vtl): |getpt()| is a glibc extension. | 26 #if defined(FNL_MUSL) |
| 27 base::ScopedFD master(posix_openpt(O_RDWR | O_NOCTTY)); |
| 28 #else |
| 29 // Android doesn't yet have posix_openpt |
27 base::ScopedFD master(getpt()); | 30 base::ScopedFD master(getpt()); |
| 31 #endif |
28 if (!master.is_valid()) { | 32 if (!master.is_valid()) { |
29 *errno_value = errno; | 33 *errno_value = errno; |
30 PLOG(ERROR) << "getpt()"; | 34 PLOG(ERROR) << "posix_openpt/getpt"; |
31 return false; | 35 return false; |
32 } | 36 } |
33 | 37 |
34 if (grantpt(master.get()) < 0) { | 38 if (grantpt(master.get()) < 0) { |
35 *errno_value = errno; | 39 *errno_value = errno; |
36 PLOG(ERROR) << "grantpt()"; | 40 PLOG(ERROR) << "grantpt()"; |
37 return false; | 41 return false; |
38 } | 42 } |
39 | 43 |
40 if (unlockpt(master.get()) < 0) { | 44 if (unlockpt(master.get()) < 0) { |
(...skipping 15 matching lines...) Expand all Loading... |
56 PLOG(ERROR) << "open()"; | 60 PLOG(ERROR) << "open()"; |
57 return false; | 61 return false; |
58 } | 62 } |
59 | 63 |
60 *master_fd = master.Pass(); | 64 *master_fd = master.Pass(); |
61 *slave_fd = slave.Pass(); | 65 *slave_fd = slave.Pass(); |
62 return true; | 66 return true; |
63 } | 67 } |
64 | 68 |
65 } // namespace native_support | 69 } // namespace native_support |
OLD | NEW |