--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "launchpad-process-pool/app_labels_monitor.hh"
+
+#include <exception.hh>
+
+#include "launchpad-process-pool/log.hh"
+#include "launchpad-process-pool/log_private.hh"
+
+namespace launchpad {
+
+AppLabelsMonitor::AppLabelsMonitor() {
+ app_labels_monitor* monitor = nullptr;
+ int ret = security_manager_app_labels_monitor_init(&monitor);
+ if (ret != SECURITY_MANAGER_SUCCESS) {
+ _E("Failed to initialize app labels monitor. error: %d", ret);
+ THROW(ret);
+ }
+
+ auto monitor_auto =
+ std::unique_ptr<app_labels_monitor,
+ decltype(security_manager_app_labels_monitor_finish)*>(
+ monitor, security_manager_app_labels_monitor_finish);
+
+ ret = security_manager_app_labels_monitor_process(monitor);
+ if (ret != SECURITY_MANAGER_SUCCESS) {
+ _E("Failed to process app labels monitor. error: %d", ret);
+ THROW(ret);
+ }
+
+ int fd = -1;
+ ret = security_manager_app_labels_monitor_get_fd(monitor, &fd);
+ if (ret != SECURITY_MANAGER_SUCCESS) {
+ _E("Failed to get file descriptor. error: %d", ret);
+ THROW(ret);
+ }
+
+ channel_ = std::make_unique<IOChannel>(fd, IOChannel::IOCondition::IO_IN,
+ this);
+ channel_->SetCloseOnDestroy(false);
+ handle_ = monitor_auto.release();
+}
+
+AppLabelsMonitor::~AppLabelsMonitor() {
+ if (handle_ != nullptr)
+ security_manager_app_labels_monitor_finish(handle_);
+}
+
+void AppLabelsMonitor::SetEventListener(IEvent* listener) {
+ listener_ = listener;
+}
+
+void AppLabelsMonitor::OnIOEventReceived(int fd, int condition) {
+ _D("fd(%d), condition(%d)", fd, condition);
+ Log::Print("[APP_LABELS]", "fd(%d), condition(%d)", fd, condition);
+ security_manager_app_labels_monitor_process(handle_);
+
+ if (listener_ != nullptr)
+ listener_->OnAppLabelsChanged();
+}
+
+} // namespace launchpad
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LAUNCHPAD_PROCESS_POOL_APP_LABELS_MONITOR_HH_
+#define LAUNCHPAD_PROCESS_POOL_APP_LABELS_MONITOR_HH_
+
+#include <security-manager.h>
+
+#include <memory>
+
+#include <io_channel.hh>
+
+namespace launchpad {
+
+class AppLabelsMonitor : public IOChannel::IEvent {
+ public:
+ class IEvent {
+ public:
+ virtual ~IEvent() = default;
+ virtual void OnAppLabelsChanged() = 0;
+ };
+
+ AppLabelsMonitor();
+ ~AppLabelsMonitor();
+ AppLabelsMonitor(const AppLabelsMonitor&) = delete;
+ AppLabelsMonitor& operator=(const AppLabelsMonitor&) = delete;
+
+ void SetEventListener(IEvent* listener);
+
+ private:
+ void OnIOEventReceived(int fd, int condition) override;
+
+ private:
+ std::unique_ptr<IOChannel> channel_;
+ app_labels_monitor* handle_ = nullptr;
+ IEvent* listener_ = nullptr;
+};
+
+} // namespace launchpad
+
+#endif // LAUNCHPAD_PROCESS_POOL_APP_LABELS_MONITOR_HH_
#include <algorithm>
#include <string>
+#include <exception.hh>
#include <procfs.hh>
#include "launchpad-process-pool/launchpad_io_channel.h"
#include "lib/common/inc/perf.h"
#include "launchpad-process-pool/app_defined_loader_info_manager.hh"
+#include "launchpad-process-pool/app_labels_monitor.hh"
#include "launchpad-process-pool/config.hh"
#include "launchpad-process-pool/debug.hh"
#include "launchpad-process-pool/dbus.hh"
static candidate_process_context_t* __find_slot_from_loader_name(
const char* loader_name);
static int __remove_slot(int type, int loader_id);
+static void HandleAppLabelsChanged();
namespace {
}
};
+class AppLabelsChangedEventHandler
+ : public launchpad::AppLabelsMonitor::IEvent {
+ private:
+ void OnAppLabelsChanged() override {
+ HandleAppLabelsChanged();
+ }
+};
+
std::unique_ptr<launchpad::LoaderInfoManager> loader_info_manager;
AppDefinedLoaderInfoEventHandler app_defined_loader_info_event_handler;
std::unique_ptr<launchpad::AppDefinedLoaderInfoManager>
app_defined_loader_info_manager;
int user_slot_offset;
GList* candidate_slot_list;
-app_labels_monitor* label_monitor;
std::vector<launchpad::LauncherInfoPtr> launcher_info_list;
GHashTable* __pid_table;
sequencer __sequencer;
io_channel_h __logger_channel;
-io_channel_h __label_monitor_channel;
io_channel_h __launchpad_channel;
int __client_fd = -1;
std::unique_ptr<launchpad::Worker> cleaner;
std::unique_ptr<launchpad::HWAccelerationConfig> hwacc_config;
std::unique_ptr<launchpad::LanguageConfig> lang_config;
std::unique_ptr<launchpad::RegionFormatConfig> region_format_config;
-
+AppLabelsChangedEventHandler app_labels_changed_event_handler;
+std::unique_ptr<launchpad::AppLabelsMonitor> label_monitor;
} // namespace
}
}
-static bool __handle_label_monitor(int fd, io_condition_e cond, void* data) {
- candidate_process_context_t* cpc;
+static void HandleAppLabelsChanged() {
GList* iter = candidate_slot_list;
-
- if (cond & (IO_ERR | IO_HUP | IO_NVAL)) {
- _E("fd(%d), io_condition(%d)", fd, cond);
- abort();
- return false;
- }
-
- _D("fd(%d) condition(%d)", fd, cond);
- launchpad::Log::Print("[LABEL]", "fd(%d), condition(%d)", fd, cond);
- security_manager_app_labels_monitor_process(label_monitor);
-
while (iter) {
- cpc = reinterpret_cast<candidate_process_context_t*>(iter->data);
+ auto* cpc = reinterpret_cast<candidate_process_context_t*>(iter->data);
if (cpc->is_hydra) {
if (cpc->hydra_pid > 0) {
__dispose_hydra_process(cpc);
iter = g_list_next(iter);
}
-
- return true;
}
static float __interpolator(float input, int cpu_max, int cpu_min) {
return 0;
}
-static int __init_label_monitor_fd(void) {
- int r;
- int fd = -1;
-
- auto err_handler = [&]() -> int {
- if (fd > 0)
- close(fd);
-
- if (label_monitor) {
- security_manager_app_labels_monitor_finish(label_monitor);
- label_monitor = nullptr;
- }
- return -1;
- };
-
- r = security_manager_app_labels_monitor_init(&label_monitor);
- if (r != SECURITY_MANAGER_SUCCESS)
- return -1;
-
- r = security_manager_app_labels_monitor_process(label_monitor);
- if (r != SECURITY_MANAGER_SUCCESS)
- return err_handler();
-
- security_manager_app_labels_monitor_get_fd(label_monitor, &fd);
- if (fd < 0) {
- _E("failed to get fd");
- return err_handler();
- }
-
- auto cond = IO_IN | IO_PRI | IO_HUP | IO_ERR | IO_NVAL;
- __label_monitor_channel = _io_channel_create(
- fd, static_cast<io_condition_e>(cond), __handle_label_monitor, nullptr);
- if (!__label_monitor_channel)
- return err_handler();
-
- return 0;
-}
-
static int __verify_loader_caps(const char* loader) {
cap_t cap_d;
cap_flag_value_t eff_state;
return -1;
}
- ret = __init_label_monitor_fd();
- if (ret != 0)
- _W("Failed to initialize label monitor");
+ try {
+ label_monitor.reset(new launchpad::AppLabelsMonitor());
+ label_monitor->SetEventListener(&app_labels_changed_event_handler);
+ } catch (const launchpad::Exception& e) {
+ _W("Failed to initialize label monitor. error: %s", e.what());
+ }
MemoryManager::GetInst().Init();
__add_default_slots();
launchpad::Debug::GetInst().Dispose();
launcher_info_list.clear();
app_defined_loader_info_manager.reset();
-
- if (__label_monitor_channel)
- _io_channel_destroy(__label_monitor_channel);
-
- if (label_monitor)
- security_manager_app_labels_monitor_finish(label_monitor);
+ label_monitor.reset();
if (__logger_channel)
_io_channel_destroy(__logger_channel);