OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
7 | 7 |
8 #include "bin/fdutils.h" | 8 #include "bin/fdutils.h" |
9 | 9 |
10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
11 #include <fcntl.h> // NOLINT | 11 #include <fcntl.h> // NOLINT |
12 #include <sys/ioctl.h> // NOLINT | 12 #include <sys/ioctl.h> // NOLINT |
13 #include <unistd.h> // NOLINT | 13 #include <unistd.h> // NOLINT |
14 | 14 |
15 #include "platform/signal_blocker.h" | 15 #include "platform/signal_blocker.h" |
16 | 16 |
17 namespace dart { | 17 namespace dart { |
18 namespace bin { | 18 namespace bin { |
19 | 19 |
20 bool FDUtils::SetCloseOnExec(intptr_t fd) { | 20 bool FDUtils::SetCloseOnExec(intptr_t fd) { |
21 intptr_t status; | 21 intptr_t status; |
22 status = NO_RETRY_EXPECTED(fcntl(fd, F_GETFD)); | 22 status = NO_RETRY_EXPECTED(fcntl(fd, F_GETFD)); |
23 if (status < 0) { | 23 if (status < 0) { |
| 24 perror("fcntl(F_GETFD) failed"); |
24 return false; | 25 return false; |
25 } | 26 } |
26 status |= FD_CLOEXEC; | 27 status |= FD_CLOEXEC; |
27 if (NO_RETRY_EXPECTED(fcntl(fd, F_SETFD, status)) < 0) { | 28 if (NO_RETRY_EXPECTED(fcntl(fd, F_SETFD, status)) < 0) { |
| 29 perror("fcntl(F_SETFD, FD_CLOEXEC) failed"); |
28 return false; | 30 return false; |
29 } | 31 } |
30 return true; | 32 return true; |
31 } | 33 } |
32 | 34 |
33 | 35 |
34 static bool SetBlockingHelper(intptr_t fd, bool blocking) { | 36 static bool SetBlockingHelper(intptr_t fd, bool blocking) { |
35 intptr_t status; | 37 intptr_t status; |
36 status = NO_RETRY_EXPECTED(fcntl(fd, F_GETFL)); | 38 status = NO_RETRY_EXPECTED(fcntl(fd, F_GETFL)); |
37 if (status < 0) { | 39 if (status < 0) { |
| 40 perror("fcntl(F_GETFL) failed"); |
38 return false; | 41 return false; |
39 } | 42 } |
40 status = blocking ? (status & ~O_NONBLOCK) : (status | O_NONBLOCK); | 43 status = blocking ? (status & ~O_NONBLOCK) : (status | O_NONBLOCK); |
41 if (NO_RETRY_EXPECTED(fcntl(fd, F_SETFL, status)) < 0) { | 44 if (NO_RETRY_EXPECTED(fcntl(fd, F_SETFL, status)) < 0) { |
| 45 perror("fcntl(F_SETFL, O_NONBLOCK) failed"); |
42 return false; | 46 return false; |
43 } | 47 } |
44 return true; | 48 return true; |
45 } | 49 } |
46 | 50 |
47 | 51 |
48 bool FDUtils::SetNonBlocking(intptr_t fd) { | 52 bool FDUtils::SetNonBlocking(intptr_t fd) { |
49 return SetBlockingHelper(fd, false); | 53 return SetBlockingHelper(fd, false); |
50 } | 54 } |
51 | 55 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 buffer_pos += bytes_written; | 134 buffer_pos += bytes_written; |
131 } | 135 } |
132 } | 136 } |
133 return count; | 137 return count; |
134 } | 138 } |
135 | 139 |
136 } // namespace bin | 140 } // namespace bin |
137 } // namespace dart | 141 } // namespace dart |
138 | 142 |
139 #endif // defined(TARGET_OS_LINUX) | 143 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |