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

Commit 6d24a8fc authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "android_os_SELinux.cpp: Refactor GetSELabelHandle" into main am: ec2b1fb9

parents 535ad888 ec2b1fb9
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -34,23 +34,27 @@

namespace android {
namespace {
std::atomic<selabel_handle*> sehandle{nullptr};
std::atomic<selabel_handle *> file_sehandle{nullptr};

selabel_handle* GetSELabelHandle() {
    selabel_handle* h = sehandle.load();
selabel_handle *GetSELabelHandle_impl(selabel_handle *(*handle_func)(),
                                      std::atomic<selabel_handle *> *handle_cache) {
    selabel_handle *h = handle_cache->load();
    if (h != nullptr) {
        return h;
    }

    h = selinux_android_file_context_handle();
    h = handle_func();
    selabel_handle* expected = nullptr;
    if (!sehandle.compare_exchange_strong(expected, h)) {
    if (!handle_cache->compare_exchange_strong(expected, h)) {
        selabel_close(h);
        return sehandle.load();
        return handle_cache->load();
    }
    return h;
}

selabel_handle *GetSELabelFileBackendHandle() {
    return GetSELabelHandle_impl(selinux_android_file_context_handle, &file_sehandle);
}
}

struct SecurityContext_Delete {
@@ -106,7 +110,7 @@ static jstring fileSelabelLookup(JNIEnv* env, jobject, jstring pathStr) {
        return NULL;
    }

    auto* selabel_handle = GetSELabelHandle();
    auto *selabel_handle = GetSELabelFileBackendHandle();
    if (selabel_handle == NULL) {
        ALOGE("fileSelabelLookup => Failed to get SEHandle");
        return NULL;