2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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
8 * http://floralicense.org/license/
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.
24 #include <sys/types.h>
35 #include <widget_provider.h>
36 #include <widget_conf.h>
38 #include "critical_log.h"
47 #if defined(_USE_ECORE_TIME_GET)
50 struct timeval alarm_tv;
54 struct sigaction SEGV_act;
55 struct sigaction ILL_act;
56 struct sigaction ALRM_act;
57 struct sigaction USR1_act;
58 struct sigaction ABRT_act;
66 static void signal_handler(int signum, siginfo_t *info, void *unused)
71 so_fname = util_get_current_module(&symbol);
73 if (info->si_signo == SIGALRM) {
75 DbgPrint("Ignore false alarm signal [false]\n");
79 #if defined(_USE_ECORE_TIME_GET)
81 tv = ecore_time_get();
82 if (tv - s_info.alarm_tv < DEFAULT_LIFE_TIMER) {
83 DbgPrint("Ignore false alarm signal [%lf]\n", tv - s_info.alarm_tv);
87 CRITICAL_LOG("ALARM: %lf (%d, %d)\n", tv - s_info.alarm_tv, DEFAULT_LIFE_TIMER, DEFAULT_LOAD_TIMER);
90 struct timeval res_tv;
92 if (gettimeofday(&tv, NULL) < 0) {
93 ErrPrint("gettimeofday: %d\n", errno);
98 timersub(&tv, &s_info.alarm_tv, &res_tv);
104 if (res_tv.tv_sec < DEFAULT_LIFE_TIMER) {
105 DbgPrint("Ignore false alarm signal [%d]\n", res_tv.tv_sec);
109 CRITICAL_LOG("ALARM: %d.%d (%d, %d)\n",
110 res_tv.tv_sec, res_tv.tv_usec, DEFAULT_LIFE_TIMER, DEFAULT_LOAD_TIMER);
112 } else if (so_fname) {
116 snprintf(log_fname, sizeof(log_fname), "%s/slave.%d", WIDGET_CONF_LOG_PATH, getpid());
117 fd = open(log_fname, O_WRONLY|O_CREAT|O_SYNC, 0644);
119 if (write(fd, so_fname, strlen(so_fname)) != strlen(so_fname)) {
120 ErrPrint("Failed to recording the fault SO filename (%s)\n", so_fname);
123 ErrPrint("close: %d\n", errno);
128 CRITICAL_LOG("SIGNAL> Received from PID[%d]\n", info->si_pid);
129 CRITICAL_LOG("SIGNAL> Signal: %d (%d)\n", signum, info->si_signo);
130 CRITICAL_LOG("SIGNAL> Error code: %d\n", info->si_code);
131 CRITICAL_LOG("SIGNAL> Address: %p\n", info->si_addr);
132 CRITICAL_LOG("Package: [%s] Symbol[%s]\n", so_fname, symbol);
135 int len = strlen(s_info.argv[0]);
136 memset(s_info.argv[0], 0, len);
137 strncpy(s_info.argv[0], util_basename(so_fname), len - 1);
140 CRITICAL_LOG("Unable to find a so_fname (%s)\n", symbol);
147 s_info.SEGV_act.sa_sigaction(signum, info, unused);
150 s_info.ALRM_act.sa_sigaction(signum, info, unused);
153 s_info.ABRT_act.sa_sigaction(signum, info, unused);
156 s_info.ILL_act.sa_sigaction(signum, info, unused);
159 s_info.USR1_act.sa_sigaction(signum, info, unused);
162 ErrPrint("Unhandled signal\n");
167 HAPI int fault_init(char **argv)
169 struct sigaction act;
174 act.sa_sigaction = signal_handler;
175 act.sa_flags = SA_SIGINFO;
177 if (sigemptyset(&act.sa_mask) != 0) {
178 ErrPrint("Failed to init signal: %d\n", errno);
181 if (sigaddset(&act.sa_mask, SIGUSR1) != 0) {
182 ErrPrint("Failed to add set: %d\n", errno);
185 if (sigaddset(&act.sa_mask, SIGALRM) != 0) {
186 ErrPrint("Failed to add set: %d\n", errno);
189 ecore_abort = getenv("ECORE_ERROR_ABORT");
190 if (!ecore_abort || ecore_abort[0] != '1') {
191 if (sigaddset(&act.sa_mask, SIGSEGV) != 0) {
192 ErrPrint("Failed to add set: %d\n", errno);
194 if (sigaddset(&act.sa_mask, SIGABRT) != 0) {
195 ErrPrint("Failed to add set: %d\n", errno);
197 if (sigaddset(&act.sa_mask, SIGILL) != 0) {
198 ErrPrint("Failed to add set: %d\n", errno);
201 if (sigaction(SIGSEGV, &act, &s_info.SEGV_act) < 0) {
202 ErrPrint("Failed to install the SEGV handler\n");
205 if (sigaction(SIGABRT, &act, &s_info.ABRT_act) < 0) {
206 ErrPrint("Faield to install the ABRT handler\n");
209 if (sigaction(SIGILL, &act, &s_info.ILL_act) < 0) {
210 ErrPrint("Faield to install the ILL handler\n");
214 if (sigaction(SIGUSR1, &act, &s_info.USR1_act) < 0) {
215 ErrPrint("Failed to install the USR1 handler\n");
218 if (sigaction(SIGALRM, &act, &s_info.ALRM_act) < 0) {
219 ErrPrint("Failed to install the ALRM handler\n");
225 HAPI int fault_fini(void)
229 * remove all signal handlers
234 HAPI int fault_mark_call(const char *pkgname, const char *filename, const char *funcname, int noalarm, int life_time)
236 if (!s_info.disable_checker) {
237 widget_provider_send_call(pkgname, filename, funcname);
241 * To use this "alarm", the widget have to do not use the 'sleep' series functions.
242 * because those functions will generate alarm signal.
243 * then the module will be deactivated
245 * Enable alarm for detecting infinite loop
248 #if defined(_USE_ECORE_TIME_GET)
249 s_info.alarm_tv = ecore_time_get();
251 if (gettimeofday(&s_info.alarm_tv, NULL) < 0) {
252 ErrPrint("gettimeofday: %d\n", errno);
253 s_info.alarm_tv.tv_sec = 0;
254 s_info.alarm_tv.tv_usec = 0;
264 HAPI int fault_unmark_call(const char *pkgname, const char *filename, const char *funcname, int noalarm)
275 if (!s_info.disable_checker) {
276 widget_provider_send_ret(pkgname, filename, funcname);
281 HAPI void fault_disable_call_option(void)
283 s_info.disable_checker = 1;