Add reason to send signal when printing the debug log.
Change-Id: I3c5cd6b93e7c96435764be47cff7a50704c0e01f
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
return (val == 1);
}
-int safe_kill(pid_t pid, int sig)
+static char* convert_reason_to_string(enum safe_kill_reason safe_kill_reason)
+{
+ switch (safe_kill_reason) {
+ case SAFE_KILL_BY_UNKNOWN_REASON:
+ return "unknown reason";
+ case SAFE_KILL_BY_OOM:
+ return "out of memory";
+ case SAFE_KILL_BY_WATCHDOG:
+ return "watchdog";
+ case SAFE_KILL_BY_MEMORY_LIMIT:
+ return "memory limit";
+ case SAFE_KILL_BY_CGROUP_PROC_KILL:
+ return "cgroup process killed";
+ case SAFE_KILL_BY_FREEZER:
+ return "freezer";
+ case SAFE_KILL_BY_MEMORY_SWEEP:
+ return "memory sweep";
+ default:
+ return "";
+ }
+}
+
+int safe_kill(pid_t pid, int sig, enum safe_kill_reason safe_kill_reason)
{
/* Pass signals other than SIGKILL, as other signals are not delivered to
* a process that's dumping a core anyway, and SIGKILL is the only one that
* Alternatively, with SIGKILL check if process is coredumping.
*/
if (sig != SIGKILL || !is_process_coredumping(pid)) {
- _D("safe-kill: delivering signal %d to process %d immediately", sig, pid);
+ _D("safe-kill: Send signal (%d) to process (%d) by %s",
+ sig, pid, convert_reason_to_string(safe_kill_reason));
return kill(pid, sig);
}
extern "C" {
#endif /* __cplusplus */
-int safe_kill(pid_t pid, int sig);
+enum safe_kill_reason {
+ SAFE_KILL_BY_UNKNOWN_REASON = 0,
+ SAFE_KILL_BY_OOM,
+ SAFE_KILL_BY_WATCHDOG,
+ SAFE_KILL_BY_MEMORY_LIMIT,
+ SAFE_KILL_BY_CGROUP_PROC_KILL,
+ SAFE_KILL_BY_FREEZER,
+ SAFE_KILL_BY_MEMORY_SWEEP,
+};
+
+int safe_kill(pid_t pid, int sig, enum safe_kill_reason safe_kill_reason);
#ifdef _UNIT_TEST
bool is_process_coredumping(pid_t pid);
ret = proc_get_oom_score_adj(pid, &oom_score_adj);
if (!ret) {
_E("app watchdog pid %d not terminated, kill again\n", pid);
- safe_kill(pid, SIGKILL);
+ safe_kill(pid, SIGKILL, SAFE_KILL_BY_WATCHDOG);
}
app_watchdog_check_timer = NULL;
app_watchdog.pid = -1;
if (app_watchdog_check_timer) {
if (app_watchdog.pid == pid) {
_E("[WATCHDOG] app %s, pid %d has already received watchdog siganl but not terminated", pai->appid, pid);
- safe_kill(pid, SIGKILL);
+ safe_kill(pid, SIGKILL, SAFE_KILL_BY_WATCHDOG);
app_watchdog.pid = -1;
app_watchdog.signum = -1;
return;
resourced_proc_status_change(PROC_CGROUP_SET_TERMINATE_REQUEST,
pid, NULL, NULL, PROC_TYPE_NONE);
- safe_kill(pid, SIGABRT);
+ safe_kill(pid, SIGABRT, SAFE_KILL_BY_WATCHDOG);
if (!app_watchdog_check_timer) {
app_watchdog_check_timer = g_timeout_source_new_seconds(APP_WATCHDOG_TIMER_INTERVAL);
g_source_set_callback(app_watchdog_check_timer, check_app_watchdog_cb, NULL, NULL);
}
cur_oom = atoi(buf);
if (cur_oom >= OOMADJ_FAVORITE) {
- safe_kill(pid, SIGKILL);
- _D("sweep memory : background process %d killed by sigkill", pid);
+ safe_kill(pid, SIGKILL, SAFE_KILL_BY_MEMORY_SWEEP);
}
fclose(fp);
}
piddata = g_new(gint, 1);
*piddata = pid;
g_hash_table_insert(proc_sweep_list, piddata, NULL);
- safe_kill(pid, SIGTERM);
+ safe_kill(pid, SIGTERM, SAFE_KILL_BY_MEMORY_SWEEP);
_D("sweep memory : background process %d(%s) killed",
pid, appname);
count++;
if (!g_slist_find(app_watchdog_list, wai))
return false;
- if (safe_kill(wai->pid, 0) == -1) {
+ if (safe_kill(wai->pid, 0, SAFE_KILL_BY_WATCHDOG) == -1) {
_I("[WATCHDOG] %d process doesn't exit, remove watchdog handler", wai->pid);
app_watchdog_list = g_slist_remove(app_watchdog_list, wai);
free(wai);
} else {
_D("[WATCHDOG] timeout!!, kill child process(%s)\n",
argv[0]);
- safe_kill(pid, SIGKILL);
+ safe_kill(pid, SIGKILL, SAFE_KILL_BY_CGROUP_PROC_KILL);
}
}
} while (wpid == 0 && times <= MAX_TIMES);
return;
_E("Kill broken app=%s(DBus ConnectionOverflow)", pai->appid);
- safe_kill(pid, SIGKILL); // 🚮
+ safe_kill(pid, SIGKILL, SAFE_KILL_BY_FREEZER); // 🚮
}
static bool was_thawed_recently(const struct proc_app_info *pai)
}
if (sigterm)
- safe_kill(pid, SIGTERM);
+ safe_kill(pid, SIGTERM, SAFE_KILL_BY_OOM);
else
- safe_kill(pid, SIGKILL);
+ safe_kill(pid, SIGKILL, SAFE_KILL_BY_OOM);
_D("[LMK] we killed, force(%d), %d (%s) score = %d, size: rss = %u KB, sigterm = %d\n",
flags & OOM_FORCE, pid, appname, tsk->oom_score_adj,
if (kill(pid, 0) == 0) {
_I("[MEMORY-LIMIT] pid (%d) is still alive, so kill forcibly", pid);
- safe_kill(pid, SIGKILL);
+ safe_kill(pid, SIGKILL, SAFE_KILL_BY_MEMORY_LIMIT);
}
}
if (lowmem_limit_broadcast(pid)) {
_E("[MEMORY-LIMIT] Failed to broadcast of process (%s)", cg_dir);
- safe_kill(pid, SIGTERM);
+ safe_kill(pid, SIGTERM, SAFE_KILL_BY_MEMORY_LIMIT);
}
}
if (!pid)
continue;
- safe_kill(pid, SIGTERM);
+ safe_kill(pid, SIGTERM, SAFE_KILL_BY_MEMORY_LIMIT);
}
g_timeout_add_seconds(2, liveness_check_cb, pids_array);
break;
expect_string(__wrap_fopen, pathname, "/proc/3/status");
expect_string(__wrap_fopen, mode, "r");
- assert(safe_kill(3, SIGKILL) == 0);
+ assert(safe_kill(3, SIGKILL, SAFE_KILL_BY_UNKNOWN_REASON) == 0);
}
static void safe_kill_negative(void **state)
will_return(__wrap_kill, true);
expect_value(__wrap_kill, pid, 1);
expect_value(__wrap_kill, sig, SIGUSR1);
- assert(safe_kill(1, SIGUSR1) == 0);
+ assert(safe_kill(1, SIGUSR1, SAFE_KILL_BY_UNKNOWN_REASON) == 0);
/* SIGKILL should be delivered if the process is not coredumping */
will_return(__wrap_fopen, 1);
will_return(__wrap_kill, true);
expect_value(__wrap_kill, pid, 2);
expect_value(__wrap_kill, sig, SIGKILL);
- assert(safe_kill(2, SIGKILL) == 0);
+ assert(safe_kill(2, SIGKILL, SAFE_KILL_BY_UNKNOWN_REASON) == 0);
}