From b5d1d1926924555dffa17dc70e69a9a0fd1b5807 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Wed, 24 Apr 2019 17:22:47 -0700 Subject: [PATCH] adbd: move posix_fadvise after open. Test: treehugger Change-Id: I531e452eda46d7df3106fd59192e9936e64876b1 --- adb/daemon/file_sync_service.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/adb/daemon/file_sync_service.cpp b/adb/daemon/file_sync_service.cpp index e82a51f2b..0e70d4719 100644 --- a/adb/daemon/file_sync_service.cpp +++ b/adb/daemon/file_sync_service.cpp @@ -229,17 +229,13 @@ static bool SendSyncFailErrno(int fd, const std::string& reason) { static bool handle_send_file(int s, const char* path, uint32_t* timestamp, uid_t uid, gid_t gid, uint64_t capabilities, mode_t mode, std::vector& buffer, bool do_unlink) { + int rc; syncmsg msg; __android_log_security_bswrite(SEC_TAG_ADB_SEND_FILE, path); unique_fd fd(adb_open_mode(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, mode)); - if (posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL | POSIX_FADV_NOREUSE | POSIX_FADV_WILLNEED) < - 0) { - D("[ Failed to fadvise: %d ]", errno); - } - if (fd < 0 && errno == ENOENT) { if (!secure_mkdirs(Dirname(path))) { SendSyncFailErrno(s, "secure_mkdirs failed"); @@ -270,6 +266,12 @@ static bool handle_send_file(int s, const char* path, uint32_t* timestamp, uid_t fchmod(fd.get(), mode); } + rc = posix_fadvise(fd.get(), 0, 0, + POSIX_FADV_SEQUENTIAL | POSIX_FADV_NOREUSE | POSIX_FADV_WILLNEED); + if (rc != 0) { + D("[ Failed to fadvise: %s ]", strerror(rc)); + } + while (true) { if (!ReadFdExactly(s, &msg.data, sizeof(msg.data))) goto fail; @@ -464,8 +466,9 @@ static bool do_recv(int s, const char* path, std::vector& buffer) { return false; } - if (posix_fadvise(fd.get(), 0, 0, POSIX_FADV_SEQUENTIAL | POSIX_FADV_NOREUSE) < 0) { - D("[ Failed to fadvise: %d ]", errno); + int rc = posix_fadvise(fd.get(), 0, 0, POSIX_FADV_SEQUENTIAL | POSIX_FADV_NOREUSE); + if (rc != 0) { + D("[ Failed to fadvise: %s ]", strerror(rc)); } syncmsg msg;