diff options
author | 2023-12-05 19:15:37 +0000 | |
---|---|---|
committer | 2023-12-05 19:15:37 +0000 | |
commit | fb2ba2eb599bad2da15a7b96623f7f167208b04c (patch) | |
tree | debb1c378fa31fb4a9ac65802fdd964079948deb /cmds/installd/InstalldNativeService.cpp | |
parent | b55d9cfc6e3d221c2329deaa2cfb2dacc92f0b84 (diff) | |
parent | e4e7c515e20fce3076489a10775570f197c28bb6 (diff) |
Merge "Resume interrupted restorecon in a separate thread." into main am: f1e4a20532 am: e4e7c515e2
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2850152
Change-Id: I351a6c1738ec71a8528f7c5da78a3cff70a620da
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'cmds/installd/InstalldNativeService.cpp')
-rw-r--r-- | cmds/installd/InstalldNativeService.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp index 1347450a77..cad77874fd 100644 --- a/cmds/installd/InstalldNativeService.cpp +++ b/cmds/installd/InstalldNativeService.cpp @@ -40,6 +40,7 @@ #include <fstream> #include <functional> #include <regex> +#include <thread> #include <unordered_set> #include <android-base/file.h> @@ -556,19 +557,33 @@ static int restorecon_app_data_lazy(const std::string& path, const std::string& // If the initial top-level restorecon above changed the label, then go // back and restorecon everything recursively if (inProgress || before != after) { - ScopedTrace tracer("label-change"); if (existing) { LOG(DEBUG) << "Detected label change from " << before << " to " << after << " at " - << path << "; running recursive restorecon"; + << path << "; running recursive restorecon"; } - // Temporary mark the folder as "in-progress" to resume in case of reboot/other failure. - RestoreconInProgress fence(path); + auto restorecon = [path, seInfo, uid]() { + ScopedTrace tracer("label-change"); - if (selinux_android_restorecon_pkgdir(path.c_str(), seInfo.c_str(), uid, - SELINUX_ANDROID_RESTORECON_RECURSE) < 0) { - PLOG(ERROR) << "Failed recursive restorecon for " << path; - return -1; + // Temporary mark the folder as "in-progress" to resume in case of reboot/other failure. + RestoreconInProgress fence(path); + + if (selinux_android_restorecon_pkgdir(path.c_str(), seInfo.c_str(), uid, + SELINUX_ANDROID_RESTORECON_RECURSE) < 0) { + PLOG(ERROR) << "Failed recursive restorecon for " << path; + return -1; + } + return 0; + }; + if (inProgress) { + // The previous restorecon was interrupted. It's either crashed (unlikely), or the phone + // was rebooted. Possibly because it took too much time. This time let's move it to a + // separate thread - so it won't block the rest of the OS. + std::thread(restorecon).detach(); + } else { + if (int result = restorecon(); result) { + return result; + } } } |