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

Commit ec2b1fb9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "android_os_SELinux.cpp: Refactor GetSELabelHandle" into main

parents 1c9eb66a d5bbf856
Loading
Loading
Loading
Loading
+11 −7
Original line number Original line Diff line number Diff line
@@ -34,23 +34,27 @@


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


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


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


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


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


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