(b.tv_sec * 1000000 + b.tv_usec)) \
/ 1000)
-#define KILLABLE_DAEMON_LOCK_LIMIT 1800 /* seconds, 30min */
#define FORCE_RELEASE_LOCK_INTERVAL 5 /* seconds */
-static void get_comm(pid_t pid, char *comm);
-static bool is_killable_daemon(pid_t pid);
-static gboolean pmlock_terminate_daemon_to_release_lock(gpointer data);
-static int pmlock_check(void *data);
-static int powerlock_load_config(struct parse_result *result, void *user_data);
-static void free_killable_daemon_list(void);
-
-static GList *display_lock_killable_daemon;
-static bool initialized_killable_daemon_list;
-
static struct display_config display_conf = {
.lock_wait_time = LOCK_SCREEN_WATING_TIME,
.longpress_interval = LONG_PRESS_INTERVAL,
.input_support = true,
.lockcheck_timeout = 600,
.display_init_direction = DISPLAY_INIT_DIRECTION_HORIZONTAL,
- .pmlock_check = pmlock_check,
.aod_enter_level = 40,
.aod_tsp = true,
.touch_wakeup = false,
return UNKNOWN_STR;
}
-static void get_comm(pid_t pid, char *comm)
-{
- char buf[PATH_MAX];
- int fd, r;
-
- if (pid >= INTERNAL_LOCK_BASE)
- snprintf(buf, PATH_MAX, "/proc/%d/comm", getpid());
- else
- snprintf(buf, PATH_MAX, "/proc/%d/comm", pid);
-
- fd = open(buf, O_RDONLY);
- if (fd < 0) {
- comm[0] = '\0';
- _E("Process(%d) does not exist now(may be dead without unlock).", pid);
- return;
- }
-
- r = read(fd, comm, PATH_MAX);
- if ((r > 0) && (r < PATH_MAX)) {
- if (comm[r - 1] == '\n')
- comm[r - 1] = '\0';
- else
- comm[r] = '\0';
- } else
- comm[0] = '\0';
-
- close(fd);
-}
-
-static bool is_killable_daemon(pid_t pid)
-{
- char pname[PATH_MAX] = {0, };
- const char *blacklist;
- GList *l;
-
- get_comm(pid, pname);
- if (!(*pname))
- return false;
-
- SYS_G_LIST_FOREACH(display_lock_killable_daemon, l, blacklist) {
- if (MATCH(pname, blacklist))
- return true;
- }
-
- return false;
-}
-
-static gboolean pmlock_terminate_daemon_to_release_lock(gpointer data)
-{
- pid_t pid;
- PmLockNode *node;
- enum state_t state;
- int ret;
- bool pid_exist;
- char pname[PATH_MAX] = {0, };
-
- if (!data) {
- _E("Invalid parameter.");
- return G_SOURCE_REMOVE;
- }
-
- node = (PmLockNode *) data;
- state = node->state;
- pid = node->pid;
-
- if (pid <= 0) {
- _E("Invalid lock pid.");
- del_node(state, node);
- return G_SOURCE_REMOVE;
- }
-
- if (!node->killable_daemon) {
- _E("Incorrect checker, this is not a killable daemon. Stop checking lock.");
- return G_SOURCE_REMOVE;
- }
-
- pid_exist = (kill(pid, 0) == 0);
- if (pid_exist)
- get_comm(pid, pname);
-
- if (node->force_release == false) {
- /* Stop checking lock if process had been terminated */
- if (!pid_exist) {
- del_node(state, node);
- _I("Process %d not found. Stop checking lock.", pid);
- return G_SOURCE_REMOVE;
- }
-
- /* KILLABLE_DAEMON_LOCK_LIMIT is expired. Kill the daemon */
- CRITICAL_LOG("%s(%d) holds %s lock for %ds. kill SIGTERM.",
- *pname ? pname : "Unknown", pid, states[state].name, KILLABLE_DAEMON_LOCK_LIMIT);
- ret = kill(pid, SIGTERM);
- if (ret < 0)
- CRITICAL_LOG_E("Failed to send SIGTERM to process %s(%d), %d.",
- *pname ? pname : "Unknown", pid, errno);
-
- node->force_release = true;
- node->warning_id = g_timeout_add_seconds(FORCE_RELEASE_LOCK_INTERVAL,
- pmlock_terminate_daemon_to_release_lock, (gpointer)node);
- } else if (node->force_release == true) {
- /* kill confirmation */
- if (pid_exist) {
- CRITICAL_LOG("%s(%d) is still alive, kill SIGKILL.",
- *pname ? pname : "Unknown", pid);
-
- ret = kill(pid, SIGKILL);
- if (ret < 0)
- CRITICAL_LOG_E("Failed to kill process %s(%d), %d.",
- *pname ? pname : "Unknown", pid, errno);
- }
-
- /* release lock */
- CRITICAL_LOG("Release %s lock occupied by PID %d.", states[state].name, pid);
- del_node(state, node);
- set_unlock_time(pid, state);
-
- if (!display_state_transition_is_there_state_transition_timer())
- states[get_pm_cur_state()].trans(EVENT_TIMEOUT);
- }
-
- return G_SOURCE_REMOVE;
-}
-
-static int pmlock_check(void *data)
-{
- PmLockNode *node;
- int ret;
-
- assert(data);
- node = (PmLockNode *) data;
-
- if (!initialized_killable_daemon_list) {
- ret = config_parse(POWERLOCK_CONF_FILE, powerlock_load_config, NULL);
- /* config file may not exist */
- if (ret < 0 && ret != -ENOENT)
- _W("Failed to load %s, %d.", POWERLOCK_CONF_FILE, ret);
-
- if (status == DEVICE_OPS_STATUS_UNINIT) {
- _W("Lock request before display init. Preloaded killable list.");
- initialized_killable_daemon_list = true;
- } else if (status == DEVICE_OPS_STATUS_STOP) {
- _W("Lock request after display stop. Loaded list will be freed immediately.");
- node->killable_daemon = is_killable_daemon(node->pid);
- free_killable_daemon_list();
- goto killable_marked;
- }
- }
-
- node->killable_daemon = is_killable_daemon(node->pid);
-
-killable_marked:
- /* use default lock checker */
- if (!node->killable_daemon)
- return 0;
-
- return g_timeout_add_seconds(KILLABLE_DAEMON_LOCK_LIMIT,
- pmlock_terminate_daemon_to_release_lock, (gpointer)node);
-}
-
-static void free_killable_daemon_list(void)
-{
- GList *l, *l_next;
- char *blacklist;
-
- if (!display_lock_killable_daemon)
- return;
-
- SYS_G_LIST_FOREACH_SAFE(display_lock_killable_daemon, l, l_next, blacklist) {
- SYS_G_LIST_REMOVE(display_lock_killable_daemon, blacklist);
- free(blacklist);
- }
- display_lock_killable_daemon = NULL;
- initialized_killable_daemon_list = false;
-}
-
static int get_device_flags(unsigned long *device_flags)
{
if (!device_flags)
}
}
- _SD("be requested LOCK info pname(%s), holdkeyblock(%d) flags(%d) killable_daemon(%d)",
- pname, holdkey_block, flags, tmp->killable_daemon);
+ _SD("be requested LOCK info pname(%s), holdkeyblock(%d) flags(%d)", pname, holdkey_block, flags);
set_lock_time(pid, pname, state);
device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value);
return done;
}
-static int powerlock_load_config(struct parse_result *result, void *user_data)
-{
- char *name = NULL;
-
- _D("powerlock_load_config: section=%s name=%s value=%s", result->section, result->name, result->value);
-
- if (MATCH(result->section, "KillableDaemon") && MATCH(result->name, "KillableList")) {
- name = strndup(result->value, PATH_MAX - 1);
- if (!name) {
- _E("Not enough memory.");
- return -ENOMEM;
- }
-
- CRITICAL_LOG("Add %s to killable daemon list.", name);
- SYS_G_LIST_APPEND(display_lock_killable_daemon, name);
- }
-
- return 0;
-}
-
static gboolean delayed_dpms_init_done(gpointer data)
{
int timeout;
_W("Failed to load '%s', use default value: %d",
DISPLAY_CONF_FILE, ret);
- ret = config_parse(POWERLOCK_CONF_FILE, powerlock_load_config, NULL);
- /* config file may not exist */
- if (ret < 0 && ret != -ENOENT)
- _W("Failed to load %s, %d.", POWERLOCK_CONF_FILE, ret);
- initialized_killable_daemon_list = true;
-
register_kernel_uevent_control(&lcd_uevent_ops);
register_kernel_uevent_control(&sec_dsim_uevent_ops);
exit_lcd_operation();
free_lock_info_list();
- free_killable_daemon_list();
/* free display service */
display_service_free();