display: Remove unused killable-daemon code 00/294200/2
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 14 Jun 2023 06:38:34 +0000 (15:38 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Wed, 14 Jun 2023 07:19:54 +0000 (16:19 +0900)
Change-Id: Idffac4921c3b147ec3fced2525c92eb8e3444f52
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
plugins/wearable/display/core.c
src/display/display-config.h
src/display/display-lock.c
src/display/display-lock.h

index 697b776..2aadae3 100644 (file)
@@ -155,19 +155,8 @@ static struct state states[S_END] = {
        (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,
@@ -186,7 +175,6 @@ static struct display_config display_conf = {
        .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,
@@ -248,181 +236,6 @@ static const char* __device_flags_to_string(enum device_flags flags)
                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)
@@ -952,8 +765,7 @@ static void proc_condition_lock(PMMsg *data)
                }
        }
 
-       _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);
@@ -1582,26 +1394,6 @@ static int delayed_init_done(void *data)
        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;
@@ -1812,12 +1604,6 @@ static void display_init(void *data)
                _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);
 
@@ -1969,7 +1755,6 @@ static void display_exit(void *data)
 
        exit_lcd_operation();
        free_lock_info_list();
-       free_killable_daemon_list();
 
        /* free display service */
        display_service_free();
index 71c060b..967e9bd 100644 (file)
@@ -43,13 +43,6 @@ struct display_config {
        int continuous_sampling;
        int lockcheck_timeout;
        int display_init_direction;
-
-       /* Define pmlock checker.
-        * Return id of the lock checker.
-        *
-        * Returning 0 will use default lock checker */
-       int (*pmlock_check) (void *data);
-
        int aod_enter_level;
        bool aod_tsp;
        bool timeout_enable;
index 5b2df70..0e20288 100644 (file)
@@ -199,8 +199,7 @@ static gboolean default_pmlock_check(void *data)
        }
 
        if (!is_app(pid)) {
-               /* For (non-killable) daemon,
-                * no need to ask resourced if it is abnormal lock */
+               /* For daemon, no need to ask resourced if it is abnormal lock */
                broadcast_pmlock_expired(pid, state, NULL, node->time);
                return G_SOURCE_CONTINUE;
        }
@@ -361,18 +360,9 @@ PmLockNode *display_lock_add_pmlock_node(enum state_t s_index, pid_t pid, bool h
        }
        n->broadcast_warning = true;
 
-       if (pid < INTERNAL_LOCK_BASE) {
-               /* check if this lock node needs custom-defined lock checker.
-                * n->warning_id would be 0 if fails to register the checker,
-                * or there is no need to use that checker */
-               if (g_display_plugin.config->pmlock_check)
-                       n->warning_id = g_display_plugin.config->pmlock_check(n);
-
-               /* use default lock checker */
-               if (!n->warning_id)
-                       n->warning_id = g_timeout_add_seconds(g_display_plugin.config->lockcheck_timeout,
-                               default_pmlock_check, (gpointer)n);
-       }
+       if (pid < INTERNAL_LOCK_BASE)
+               n->warning_id = g_timeout_add_seconds(g_display_plugin.config->lockcheck_timeout,
+                       default_pmlock_check, (gpointer)n);
 
        SYS_G_LIST_APPEND(cond_head[s_index], n);
 
index 30e8006..abf2b9f 100644 (file)
@@ -38,18 +38,6 @@ typedef struct _pm_lock_node {
        bool holdkey_block;
        bool app_background;
        bool broadcast_warning;
-
-       /* Set true when the lock holder is an entry of
-        * the list display_lock_killable_daemon.
-        * If true, deviced tries to kill this lock holder when
-        * the holder holds lock longer than KILLABLE_DAEMON_LOCK_LIMIT */
-       bool killable_daemon;
-
-       /* Set true when the lock holder holds lock
-        * longer than KILLABLE_DAEMON_LOCK_LIMIT.
-        * After a while, FORCE_RELEASE_LOCK_INTERVAL,
-        * this lock will be released. */
-       bool force_release;
 } PmLockNode;
 
 bool check_lock_state(int state);