adbd: move posix_fadvise after open.

Test: treehugger
Change-Id: I531e452eda46d7df3106fd59192e9936e64876b1
This commit is contained in:
Josh Gao 2019-04-24 17:22:47 -07:00
parent cc30f4d7dd
commit b5d1d19269
1 changed files with 10 additions and 7 deletions

View File

@ -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<char>& 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<char>& 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;