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

Commit 895f8fc7 authored by Narayan Kamath's avatar Narayan Kamath
Browse files

dumpstate: Fix IO Errors during zip writing.

We need to always call FinishEntry, even when the poll times
out for whatever unrelated reason.

Bug: 124089395
Test: manual
Test: adb shell /data/nativetest64/dumpstate_test/dumpstate_test
Test: adb shell /data/nativetest64/dumpstate_smoke_test/dumpstate_smoke_test

Change-Id: I039f3b049042988e5e520771b45d0b511d11c461
parent cf867594
Loading
Loading
Loading
Loading
+15 −3
Original line number Original line Diff line number Diff line
@@ -768,6 +768,17 @@ status_t Dumpstate::AddZipEntryFromFd(const std::string& entry_name, int fd,
               ZipWriter::ErrorCodeString(err));
               ZipWriter::ErrorCodeString(err));
        return UNKNOWN_ERROR;
        return UNKNOWN_ERROR;
    }
    }
    bool finished_entry = false;
    auto finish_entry = [this, &finished_entry] {
        if (!finished_entry) {
            // This should only be called when we're going to return an earlier error,
            // which would've been logged. This may imply the file is already corrupt
            // and any further logging from FinishEntry is more likely to mislead than
            // not.
            this->zip_writer_->FinishEntry();
        }
    };
    auto scope_guard = android::base::make_scope_guard(finish_entry);
    auto start = std::chrono::steady_clock::now();
    auto start = std::chrono::steady_clock::now();
    auto end = start + timeout;
    auto end = start + timeout;
    struct pollfd pfd = {fd, POLLIN};
    struct pollfd pfd = {fd, POLLIN};
@@ -784,11 +795,11 @@ status_t Dumpstate::AddZipEntryFromFd(const std::string& entry_name, int fd,


            int rc = TEMP_FAILURE_RETRY(poll(&pfd, 1, time_left_ms()));
            int rc = TEMP_FAILURE_RETRY(poll(&pfd, 1, time_left_ms()));
            if (rc < 0) {
            if (rc < 0) {
                MYLOGE("Error in poll while adding from fd to zip entry %s:%s", entry_name.c_str(),
                MYLOGE("Error in poll while adding from fd to zip entry %s:%s\n",
                       strerror(errno));
                       entry_name.c_str(), strerror(errno));
                return -errno;
                return -errno;
            } else if (rc == 0) {
            } else if (rc == 0) {
                MYLOGE("Timed out adding from fd to zip entry %s:%s Timeout:%lldms",
                MYLOGE("Timed out adding from fd to zip entry %s:%s Timeout:%lldms\n",
                       entry_name.c_str(), strerror(errno), timeout.count());
                       entry_name.c_str(), strerror(errno), timeout.count());
                return TIMED_OUT;
                return TIMED_OUT;
            }
            }
@@ -809,6 +820,7 @@ status_t Dumpstate::AddZipEntryFromFd(const std::string& entry_name, int fd,
    }
    }


    err = zip_writer_->FinishEntry();
    err = zip_writer_->FinishEntry();
    finished_entry = true;
    if (err != 0) {
    if (err != 0) {
        MYLOGE("zip_writer_->FinishEntry(): %s\n", ZipWriter::ErrorCodeString(err));
        MYLOGE("zip_writer_->FinishEntry(): %s\n", ZipWriter::ErrorCodeString(err));
        return UNKNOWN_ERROR;
        return UNKNOWN_ERROR;