Add signal handler for client process
[platform/core/multimedia/mm-resource-manager.git] / src / lib / mm_resource_manager_signal.c
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "common/mm_resource_manager_utils.h"
18 #include "lib/mm_resource_manager_priv.h"
19
20 static struct sigaction rm_segv_old_action;
21 static struct sigaction rm_abrt_old_action;
22 static struct sigaction rm_term_old_action;
23
24 static void __rm_signal_handler(int signo)
25 {
26         MM_RM_DEBUG("signal %d is received", signo);
27
28         switch (signo) {
29         case SIGSEGV:
30                 sigaction(SIGSEGV, &rm_segv_old_action, NULL);
31                 break;
32         case SIGABRT:
33                 sigaction(SIGABRT, &rm_abrt_old_action, NULL);
34                 break;
35         case SIGTERM:
36                 sigaction(SIGTERM, &rm_term_old_action, NULL);
37                 break;
38         default:
39                 break;
40         }
41
42         raise(signo);
43 }
44
45 int _mm_resource_manager_set_signal_handlers(void)
46 {
47         struct sigaction sa_exec;
48
49         sa_exec.sa_handler = __rm_signal_handler;
50         sigemptyset(&sa_exec.sa_mask);
51         sa_exec.sa_flags = SA_RESETHAND;
52
53         return sigaction(SIGSEGV, &sa_exec, &rm_segv_old_action) != -1
54                         && sigaction(SIGABRT, &sa_exec, &rm_abrt_old_action) != -1
55                         && sigaction(SIGTERM, &sa_exec, &rm_term_old_action) != -1;
56 }
57