2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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
8 * http://www.tizenopensource.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>
36 #include "critical_log.h"
45 struct timeval alarm_tv;
53 static void signal_handler(int signum, siginfo_t *info, void *unused)
58 so_fname = util_get_current_module(&symbol);
60 if (info->si_signo == SIGALRM) {
62 struct timeval res_tv;
65 DbgPrint("Ignore false alarm signal [false]\n");
69 gettimeofday(&tv, NULL);
71 timersub(&tv, &s_info.alarm_tv, &res_tv);
77 if (res_tv.tv_sec < DEFAULT_LIFE_TIMER) {
78 DbgPrint("Ignore false alarm signal [%d]\n", res_tv.tv_sec);
82 DbgPrint("ALARM: %d.%d (%d, %d)\n",
83 res_tv.tv_sec, res_tv.tv_usec, DEFAULT_LIFE_TIMER, DEFAULT_LOAD_TIMER);
84 } else if (so_fname) {
88 snprintf(log_fname, sizeof(log_fname), "%s/slave.%d", SLAVE_LOG_PATH, getpid());
89 fd = open(log_fname, O_WRONLY|O_CREAT|O_SYNC, 0644);
91 if (write(fd, so_fname, strlen(so_fname)) != strlen(so_fname))
92 ErrPrint("Failed to recording the fault SO filename (%s)\n", so_fname);
98 ErrPrint("SIGNAL> Received from PID[%d]\n", info->si_pid);
99 ErrPrint("SIGNAL> Signal: %d (%d)\n", signum, info->si_signo);
100 ErrPrint("SIGNAL> Error code: %d\n", info->si_code);
101 ErrPrint("SIGNAL> Address: %p\n", info->si_addr);
102 ErrPrint("Package: [%s] Symbol[%s]\n", so_fname, symbol);
110 HAPI int fault_init(void)
112 struct sigaction act;
114 if (access("/tmp/live.err", F_OK) == 0)
115 ErrPrint("Error log still exists (/tmp/live.err)\n");
117 act.sa_sigaction = signal_handler;
118 act.sa_flags = SA_SIGINFO;
120 sigemptyset(&act.sa_mask);
121 sigaddset(&act.sa_mask, SIGSEGV);
122 sigaddset(&act.sa_mask, SIGABRT);
123 sigaddset(&act.sa_mask, SIGILL);
124 sigaddset(&act.sa_mask, SIGUSR1);
125 sigaddset(&act.sa_mask, SIGALRM);
127 if (sigaction(SIGSEGV, &act, NULL) < 0)
128 ErrPrint("Failed to install the SEGV handler\n");
130 if (sigaction(SIGABRT, &act, NULL) < 0)
131 ErrPrint("Faield to install the ABRT handler\n");
133 if (sigaction(SIGILL, &act, NULL) < 0)
134 ErrPrint("Faield to install the ILL handler\n");
136 if (sigaction(SIGUSR1, &act, NULL) < 0)
137 ErrPrint("Failed to install the USR1 handler\n");
139 if (sigaction(SIGALRM, &act, NULL) < 0)
140 ErrPrint("Failed to install the ALRM handler\n");
145 HAPI int fault_fini(void)
149 * remove all signal handlers
154 HAPI int fault_mark_call(const char *pkgname, const char *filename, const char *funcname, int noalarm, int life_time)
156 if (!s_info.disable_checker)
157 provider_send_call(pkgname, filename, funcname);
160 * To use this "alarm", the livebox have to do not use the 'sleep' series functions.
161 * because those functions will generate alarm signal.
162 * then the module will be deactivated
164 * Enable alarm for detecting infinite loop
167 gettimeofday(&s_info.alarm_tv, NULL);
175 HAPI int fault_unmark_call(const char *pkgname, const char *filename, const char *funcname, int noalarm)
186 if (!s_info.disable_checker)
187 provider_send_ret(pkgname, filename, funcname);
191 HAPI void fault_disable_call_option(void)
193 s_info.disable_checker = 1;