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

Commit 8bcd8db9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "dumpstate: mount debugfs in non-user builds" am: e6b43971

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1542298

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I8375e067e581ed74e6180c74b4f31e264d965c64
parents 98025cc9 e6b43971
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/poll.h>
#include <sys/prctl.h>
#include <sys/resource.h>
@@ -2156,6 +2157,22 @@ void Dumpstate::DumpstateBoard(int out_fd) {
        return;
    }

    /*
     * mount debugfs for non-user builds which launch with S and unmount it
     * after invoking dumpstateBoard_* methods. This is to enable debug builds
     * to not have debugfs mounted during runtime. It will also ensure that
     * debugfs is only accessed by the dumpstate HAL.
     */
    auto api_level = android::base::GetIntProperty("ro.product.first_api_level", 0);
    bool mount_debugfs = !PropertiesHelper::IsUserBuild() && api_level >= 31;

    if (mount_debugfs) {
        RunCommand("mount debugfs", {"mount", "-t", "debugfs", "debugfs", "/sys/kernel/debug"},
                   AS_ROOT_20);
        RunCommand("chmod debugfs", {"chmod", "0755", "/sys/kernel/debug"},
                   AS_ROOT_20);
    }

    std::vector<std::string> paths;
    std::vector<android::base::ScopeGuard<std::function<void()>>> remover;
    for (int i = 0; i < NUM_OF_DUMPS; i++) {
@@ -2255,6 +2272,10 @@ void Dumpstate::DumpstateBoard(int out_fd) {
               "there might be racing in content\n", killing_timeout_sec);
    }

    if (mount_debugfs) {
        RunCommand("unmount debugfs", {"umount", "/sys/kernel/debug"}, AS_ROOT_20);
    }

    auto file_sizes = std::make_unique<ssize_t[]>(paths.size());
    for (size_t i = 0; i < paths.size(); i++) {
        struct stat s;