Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19322ddd authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "adbd: move posix_fadvise after open."

parents b92cd9c8 b5d1d192
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -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;