monitor->inotify = ret;
ret_lib = inotify_add_watch_full(monitor->inotify, monitor->global_label_file_path.c_str(),
IN_CLOSE_WRITE | IN_DELETE_SELF, &(monitor->global_labels_file_watch));
- if (ret_lib != SECURITY_MANAGER_SUCCESS) {
- security_manager_app_labels_monitor_finish(monitor);
+ if (ret_lib != SECURITY_MANAGER_SUCCESS)
return ret_lib;
- }
+
ret_lib = inotify_add_watch_full(monitor->inotify, monitor->user_label_file_path.c_str(),
IN_CLOSE_WRITE | IN_DELETE_SELF, &(monitor->user_labels_file_watch));
- if (ret_lib != SECURITY_MANAGER_SUCCESS) {
- security_manager_app_labels_monitor_finish(monitor);
+ if (ret_lib != SECURITY_MANAGER_SUCCESS)
return ret_lib;
- }
return SECURITY_MANAGER_SUCCESS;
}
+static void close_inotify(app_labels_monitor *monitor) noexcept
+{
+ if (monitor->inotify == -1)
+ return;
+
+ if (monitor->global_labels_file_watch != -1) {
+ int ret = inotify_rm_watch(monitor->inotify, monitor->global_labels_file_watch);
+ if (ret == -1) {
+ try {
+ LogErrno("Inotify watch removal on file " << APPS_LABELS_FILE);
+ } catch (...) {}
+ }
+ monitor->global_labels_file_watch = -1;
+ }
+ if (monitor->user_labels_file_watch != -1) {
+ int ret = inotify_rm_watch(monitor->inotify, monitor->user_labels_file_watch);
+ if (ret == -1) {
+ try {
+ LogErrno("Inotify watch removal on file " << monitor->user_label_file_path);
+ } catch (...) {}
+ }
+ monitor->user_labels_file_watch = -1;
+ }
+ close(monitor->inotify);
+ delete monitor;
+}
+
static void readPermissibleFile(std::vector<std::string> &appLabels, const std::string &filePath, app_install_type installType, uid_t uid)
{
try {
*monitor = nullptr;
- auto monitorPtr = makeUnique(new app_labels_monitor, security_manager_app_labels_monitor_finish);
+ auto monitorPtr = makeUnique(new app_labels_monitor, close_inotify);
if (!monitorPtr) {
LogError("Bad memory allocation for app_labels_monitor");
return SECURITY_MANAGER_ERROR_MEMORY;
SECURITY_MANAGER_API
void security_manager_app_labels_monitor_finish(app_labels_monitor *monitor)
{
- try_catch([&] {
+ (void)try_catch([&] {
LogDebug("security_manager_app_labels_monitor_finish() called");
if (monitor == nullptr) {
LogDebug("input param \"monitor\" is nullptr");
- return 0;
}
- auto monitorPtr = makeUnique(monitor);
- if (monitorPtr->inotify != -1) {
- if (monitorPtr->global_labels_file_watch != -1) {
- int ret = inotify_rm_watch(monitorPtr->inotify, monitorPtr->global_labels_file_watch);
- if (ret == -1) {
- LogErrno("Inotify watch removal on file " << APPS_LABELS_FILE);
- }
- monitorPtr->global_labels_file_watch = -1;
- }
- if (monitorPtr->user_labels_file_watch != -1) {
- int ret = inotify_rm_watch(monitorPtr->inotify, monitorPtr->user_labels_file_watch);
- if (ret == -1) {
- LogErrno("Inotify watch removal on file " << monitor->user_label_file_path);
- }
- monitorPtr->user_labels_file_watch = -1;
- }
- close(monitorPtr->inotify);
- monitorPtr->inotify = -1;
- }
- return 0;
+ return SECURITY_MANAGER_SUCCESS;
});
+ close_inotify(monitor);
}
SECURITY_MANAGER_API