| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 7 | 7 |
| 8 #include "bin/file_system_watcher.h" | 8 #include "bin/file_system_watcher.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| 11 #include <sys/inotify.h> // NOLINT | 11 #include <sys/inotify.h> // NOLINT |
| 12 | 12 |
| 13 #include "bin/fdutils.h" |
| 14 |
| 13 | 15 |
| 14 namespace dart { | 16 namespace dart { |
| 15 namespace bin { | 17 namespace bin { |
| 16 | 18 |
| 17 bool FileSystemWatcher::IsSupported() { | 19 bool FileSystemWatcher::IsSupported() { |
| 18 return true; | 20 return true; |
| 19 } | 21 } |
| 20 | 22 |
| 21 | 23 |
| 22 intptr_t FileSystemWatcher::WatchPath(const char* path, | 24 intptr_t FileSystemWatcher::WatchPath(const char* path, |
| 23 int events, | 25 int events, |
| 24 bool recursive) { | 26 bool recursive) { |
| 25 int fd = TEMP_FAILURE_RETRY(inotify_init1(IN_NONBLOCK | IN_CLOEXEC)); | 27 int fd = TEMP_FAILURE_RETRY(inotify_init()); |
| 26 if (fd < 0) return -1; | 28 if (fd < 0 || !FDUtils::SetNonBlocking(fd) || !FDUtils::SetCloseOnExec(fd)) { |
| 29 return -1; |
| 30 } |
| 27 int list_events = 0; | 31 int list_events = 0; |
| 28 if (events & kCreate) list_events |= IN_CREATE; | 32 if (events & kCreate) list_events |= IN_CREATE; |
| 29 if (events & kModifyContent) list_events |= IN_MODIFY | IN_ATTRIB; | 33 if (events & kModifyContent) list_events |= IN_MODIFY | IN_ATTRIB; |
| 30 if (events & kDelete) list_events |= IN_DELETE; | 34 if (events & kDelete) list_events |= IN_DELETE; |
| 31 if (events & kMove) list_events |= IN_MOVE; | 35 if (events & kMove) list_events |= IN_MOVE; |
| 32 int path_fd = TEMP_FAILURE_RETRY(inotify_add_watch(fd, path, list_events)); | 36 int path_fd = TEMP_FAILURE_RETRY(inotify_add_watch(fd, path, list_events)); |
| 33 if (path_fd < 0) { | 37 if (path_fd < 0) { |
| 34 close(fd); | 38 close(fd); |
| 35 return -1; | 39 return -1; |
| 36 } | 40 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 offset += kEventSize + e->len; | 87 offset += kEventSize + e->len; |
| 84 } | 88 } |
| 85 ASSERT(offset == bytes); | 89 ASSERT(offset == bytes); |
| 86 return events; | 90 return events; |
| 87 } | 91 } |
| 88 | 92 |
| 89 } // namespace bin | 93 } // namespace bin |
| 90 } // namespace dart | 94 } // namespace dart |
| 91 | 95 |
| 92 #endif // defined(TARGET_OS_ANDROID) | 96 #endif // defined(TARGET_OS_ANDROID) |
| 93 | |
| OLD | NEW |