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

Commit f23174cd authored by Hung Nguyen's avatar Hung Nguyen Committed by Android (Google) Code Review
Browse files

Merge "Remove zram_swap file after zram writeback setup" into main

parents c063a7ac dd300a96
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@
#include <android-base/chrono_utils.h>
#include <android-base/file.h>
#include <android-base/properties.h>
#include <android-base/scopeguard.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
@@ -97,6 +98,7 @@
using android::base::Basename;
using android::base::GetBoolProperty;
using android::base::GetUintProperty;
using android::base::make_scope_guard;
using android::base::Realpath;
using android::base::SetProperty;
using android::base::StartsWith;
@@ -1988,9 +1990,12 @@ static bool PrepareZramBackingDevice(off64_t size) {
        PERROR << "Cannot open target path: " << file_path;
        return false;
    }

    // Always unlink zram_swap file to prevent file system access.
    auto unlink_zram_swap_guard = make_scope_guard([] { unlink(file_path); });

    if (fallocate(target_fd.get(), 0, 0, size) < 0) {
        PERROR << "Cannot truncate target path: " << file_path;
        unlink(file_path);
        return false;
    }