SET(SRCS
src/lib/mm_resource_manager.c
src/lib/mm_resource_manager_priv.c
+ src/lib/mm_resource_manager_signal.c
src/common/${fw_dbus_name}.c
src/common/mm_resource_manager_utils.c
)
Name: mm-resource-manager
Summary: A Multimedia Resource Manager API
-Version: 0.2.21
+Version: 0.2.22
Release: 0
Group: Multimedia/API
License: Apache-2.0
static GMainLoop *main_loop;
static gboolean restart = FALSE;
+static struct sigaction rm_term_old_action;
+static struct sigaction rm_int_old_action;
+static struct sigaction rm_quit_old_action;
+static struct sigaction rm_hup_old_action;
int notify_fd[2];
static gboolean remove_ready_file(void);
static gboolean remove_daemon_setup_file(void);
static int set_signal_handlers(void);
-static void terminate_handler(int signum);
-static void reload_conf_handler(int signum);
+static void terminate_handler(int signo);
+static void reload_conf_handler(int signo);
static void quit_main_loop(void);
sigemptyset(&sa_ignore.sa_mask);
sa_ignore.sa_flags = 0;
- return sigaction(SIGTERM, &sa_term, NULL) != -1 &&
- sigaction(SIGINT, &sa_ignore, NULL) != -1 &&
- sigaction(SIGQUIT, &sa_ignore, NULL) != -1 &&
- sigaction(SIGHUP, &sa_reload_conf, NULL) != -1;
+ return sigaction(SIGTERM, &sa_term, &rm_term_old_action) != -1
+ && sigaction(SIGINT, &sa_ignore, &rm_int_old_action) != -1
+ && sigaction(SIGQUIT, &sa_ignore, &rm_quit_old_action) != -1
+ && sigaction(SIGHUP, &sa_reload_conf, &rm_hup_old_action) != -1;
}
-static void terminate_handler(int signum)
+static void terminate_handler(int signo)
{
MM_RM_DEBUG("SIGTERM is received");
quit_main_loop();
}
-static void reload_conf_handler(int signum)
+static void reload_conf_handler(int signo)
{
MM_RM_DEBUG("SIGHUP is received");
restart = TRUE;
for (i = 0; i < MM_RESOURCE_MANAGER_RES_TYPE_MAX; i++) {
mm_resource_manager_conf.max_instance[i] = iniparser_getint(ini,
- g_string_append(g_string_assign(param_name,
- MM_RESOURCE_MANAGER_INI_MAX_INSTANCE),
+ g_string_append(g_string_assign(param_name,
+ MM_RESOURCE_MANAGER_INI_MAX_INSTANCE),
_mm_resource_manager_get_res_str(i))->str,
- MM_RESOURCE_MANAGER_NO_RES);
+ MM_RESOURCE_MANAGER_NO_RES);
}
g_string_free(param_name, TRUE);
* the next sync.
*/
sync.revents = 0;
- if (poll(&sync, 1, RELEASE_CB_SYNC_TIMEOUT * 1000) == 0
- || (sync.revents & (POLLHUP | POLLERR)) == 0)
+ if (poll(&sync, 1, RELEASE_CB_SYNC_TIMEOUT * 1000) == 0 || (sync.revents & (POLLHUP | POLLERR)) == 0)
MM_RM_ERROR("The client didn't close the FIFO");
} else {
MM_RM_ERROR("Read is failed (revents=%hd,read_size=%zd)", sync.revents, read_size);
GThread *dispatcher_thread;
} mm_resource_manager_s;
-static void __init_lib() __attribute__((constructor));
-static void __deinit_lib() __attribute__((destructor));
+static void __init_lib(void) __attribute__((constructor));
+static void __deinit_lib(void) __attribute__((destructor));
static int __check_resource(mm_resource_manager_s *rm,
mm_resource_manager_res_type_e type,
mm_resource_manager_res_volume volume);
mm_resource_manager_res_type_e type,
mm_resource_manager_res_volume volume)
{
- mm_resource_manager_res_volume remaining_local_volume =
- rm->__max_resource_volumes[type];
+ mm_resource_manager_res_volume local_volume = rm->__max_resource_volumes[type];
mm_resource_manager_res_p i_res;
int i;
- MM_RM_INFO("[#%"PRIu64" type : %d] resource (#%d) for the platform", _mm_rm_hash64(rm->id), type, remaining_local_volume);
+ if (local_volume == MM_RESOURCE_MANAGER_NO_RES)
+ MM_RM_ERROR("[#%"PRIu64" type : %d volume : %d] resource (#%d) for the platform",
+ _mm_rm_hash64(rm->id), type, volume, local_volume);
if (volume > 0) {
for (i = 0; i < rm->resources->len; i++) {
i_res = (mm_resource_manager_res_p) rm->resources->pdata[i];
- if (i_res->type == type &&
- i_res->state != MM_RESOURCE_MANAGER_RES_STATE_FOR_RELEASE &&
- (i_res->volume == MM_RESOURCE_MANAGER_RES_VOLUME_FULL ||
- (remaining_local_volume -= i_res->volume) < volume)) {
+ if (i_res->type == type && i_res->state != MM_RESOURCE_MANAGER_RES_STATE_FOR_RELEASE
+ && (i_res->volume == MM_RESOURCE_MANAGER_RES_VOLUME_FULL
+ || (local_volume -= i_res->volume) < volume)) {
MM_RM_ERROR("Requested volume %d exceeds remaining local volume %d",
- volume,
- i_res->volume == MM_RESOURCE_MANAGER_RES_VOLUME_FULL ?
- 0 : remaining_local_volume);
+ volume, i_res->volume == MM_RESOURCE_MANAGER_RES_VOLUME_FULL ?
+ 0 : local_volume);
return MM_RESOURCE_MANAGER_ERROR_NOT_ENOUGH;
}
}
close(sync_fd);
}
-static void __init_lib()
+static void __init_lib(void)
{
handles = g_ptr_array_sized_new(MM_RESOURCE_MANAGER_RESERVED_HANDLE_ARRAY_SIZE);
MM_RM_RETM_IF(handles == NULL, "API lib cannot be initialized");
- MM_RM_INFO("API lib is loaded");
+ MM_RM_INFO("API lib is loaded [%d] Set signal handler", _mm_resource_manager_set_signal_handlers());
}
-static void __deinit_lib()
+static void __deinit_lib(void)
{
if (handles->len > 0) {
MM_RM_DEBUG("Handles array [%d] is not empty. It will be cleaned now.", handles->len);
MM_RESOURCE_MANAGER_ERROR_INVALID_OPERATION, "Variant data are empty");
if (g_variant_iter_init(&volume_iter, max_volume) == MM_RESOURCE_MANAGER_RES_TYPE_MAX) {
- for (i = 0; g_variant_iter_next(&volume_iter, "i", &handle->__max_resource_volumes[i]); i++) {
- if (handle->__max_resource_volumes[i] == MM_RESOURCE_MANAGER_NO_RES)
- MM_RM_INFO("Maybe occur the error operation related dbus");
- }
+ for (i = 0; g_variant_iter_next(&volume_iter, "i", &handle->__max_resource_volumes[i]); i++);
g_variant_unref(max_volume);
max_volume = NULL;
} else {
mm_resource_manager_res_volume *volume);
int _mm_resource_manager_get_type_max_instance(mm_resource_manager_h rm,
mm_resource_manager_res_type_e type, int *max_instance);
+int _mm_resource_manager_set_signal_handlers(void);
#endif /* __MM_RESOURCE_MANAGER_PRIVATE__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 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 "common/mm_resource_manager_utils.h"
+#include "lib/mm_resource_manager_priv.h"
+
+static struct sigaction rm_segv_old_action;
+static struct sigaction rm_abrt_old_action;
+static struct sigaction rm_term_old_action;
+
+static void __rm_signal_handler(int signo)
+{
+ MM_RM_DEBUG("signal %d is received", signo);
+
+ switch (signo) {
+ case SIGSEGV:
+ sigaction(SIGSEGV, &rm_segv_old_action, NULL);
+ break;
+ case SIGABRT:
+ sigaction(SIGABRT, &rm_abrt_old_action, NULL);
+ break;
+ case SIGTERM:
+ sigaction(SIGTERM, &rm_term_old_action, NULL);
+ break;
+ default:
+ break;
+ }
+
+ raise(signo);
+}
+
+int _mm_resource_manager_set_signal_handlers(void)
+{
+ struct sigaction sa_exec;
+
+ sa_exec.sa_handler = __rm_signal_handler;
+ sigemptyset(&sa_exec.sa_mask);
+ sa_exec.sa_flags = SA_RESETHAND;
+
+ return sigaction(SIGSEGV, &sa_exec, &rm_segv_old_action) != -1
+ && sigaction(SIGABRT, &sa_exec, &rm_abrt_old_action) != -1
+ && sigaction(SIGTERM, &sa_exec, &rm_term_old_action) != -1;
+}
+