summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Gao2018-05-23 13:04:58 -0500
committerJosh Gao2018-05-23 13:14:57 -0500
commit9da1a9118bbbff1d8dab8b15449d23e6e512f9e3 (patch)
tree97266914ff6ab96870a1cd1d948c9ed3f3634345
parent85bd9ca978772341c4e481317f0f768fa2b2aade (diff)
downloadplatform-system-core-9da1a9118bbbff1d8dab8b15449d23e6e512f9e3.tar.gz
platform-system-core-9da1a9118bbbff1d8dab8b15449d23e6e512f9e3.tar.xz
platform-system-core-9da1a9118bbbff1d8dab8b15449d23e6e512f9e3.zip
Revert "Revert "adb: add support for O_CLOEXEC to unique_fd pipe wrapper.""
Implement pipe2 ourselves on darwin. This reverts commit f139ba47a13de0637732af9fd70aab0e8c877e45. Test: none! Change-Id: I42c2a8d07712fe4ac75b5824f754e79a5b9f5cb4
-rw-r--r--adb/adb_unique_fd.h29
1 files changed, 28 insertions, 1 deletions
diff --git a/adb/adb_unique_fd.h b/adb/adb_unique_fd.h
index 9c02cbeec..7d2354d0e 100644
--- a/adb/adb_unique_fd.h
+++ b/adb/adb_unique_fd.h
@@ -28,11 +28,38 @@ struct AdbCloser {
28using unique_fd = android::base::unique_fd_impl<AdbCloser>; 28using unique_fd = android::base::unique_fd_impl<AdbCloser>;
29 29
30#if !defined(_WIN32) 30#if !defined(_WIN32)
31inline bool Pipe(unique_fd* read, unique_fd* write) { 31inline bool Pipe(unique_fd* read, unique_fd* write, int flags = 0) {
32 int pipefd[2]; 32 int pipefd[2];
33#if !defined(__APPLE__)
34 if (pipe2(pipefd, flags) != 0) {
35 return false;
36 }
37#else
38 // Darwin doesn't have pipe2. Implement it ourselves.
39 if (flags != 0 && (flags & ~(O_CLOEXEC | O_NONBLOCK)) != 0) {
40 errno = EINVAL;
41 return false;
42 }
43
33 if (pipe(pipefd) != 0) { 44 if (pipe(pipefd) != 0) {
34 return false; 45 return false;
35 } 46 }
47
48 if (flags & O_CLOEXEC) {
49 if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) != 0 ||
50 fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) != 0) {
51 PLOG(FATAL) << "failed to set FD_CLOEXEC on newly created pipe";
52 }
53 }
54
55 if (flags & O_NONBLOCK) {
56 if (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) != 0 ||
57 fcntl(pipefd[1], F_SETFL, O_NONBLOCK) != 0) {
58 PLOG(FATAL) << "failed to set O_NONBLOCK on newly created pipe";
59 }
60 }
61#endif
62
36 read->reset(pipefd[0]); 63 read->reset(pipefd[0]);
37 write->reset(pipefd[1]); 64 write->reset(pipefd[1]);
38 return true; 65 return true;