display: Relocate get_pname() to reduce plugin duplication 65/292465/10
authorYunhee Seo <yuni.seo@samsung.com>
Fri, 28 Apr 2023 06:36:37 +0000 (15:36 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Thu, 25 May 2023 01:54:07 +0000 (10:54 +0900)
Remove and redefine get_pname function in plugins/display/core.c

This function is added to below display-misc.
void display_misc_get_process_name(pid_t pid, char *pname)
-> This function gets process name by pid parameter.

During display plugins refactoring, this function will be relocated.
To use macro value in poll.h, poll.h is relocated to core from plugin-common.
All plugin-common files will be moved to display core during refactoring process.

Change-Id: Iaaa32254bd93ee37f7bf5bfe5edafac4beb5ab83
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
plugins/iot-headed/display/core.c
plugins/mobile/display/core.c
plugins/tv/display/core.c
plugins/wearable/display/core.c
src/display/display-misc.c
src/display/display-misc.h
src/display/poll.h [moved from src/display/plugin-common/poll.h with 100% similarity]

index 5fef73b..1da1c84 100644 (file)
@@ -377,32 +377,6 @@ void set_lcd_paneloff_mode(int val)
                disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL);
 }
 
-void get_pname(pid_t pid, char *pname)
-{
-       char buf[PATH_MAX];
-       int cmdline, r;
-
-       if (pid >= INTERNAL_LOCK_BASE)
-               snprintf(buf, PATH_MAX, "/proc/%d/cmdline", getpid());
-       else
-               snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid);
-
-       cmdline = open(buf, O_RDONLY);
-       if (cmdline < 0) {
-               pname[0] = '\0';
-               _E("Process(%d) does not exist now(may be dead without unlock).", pid);
-               return;
-       }
-
-       r = read(cmdline, pname, PATH_MAX);
-       if ((r >= 0) && (r < PATH_MAX))
-               pname[r] = '\0';
-       else
-               pname[0] = '\0';
-
-       close(cmdline);
-}
-
 static void del_state_cond(void *data, enum state_t state)
 {
        PmLockNode *tmp = NULL;
@@ -858,7 +832,7 @@ static void proc_condition_lock(PMMsg *data)
                return;
 
        flags = GET_COND_FLAG(data->cond);
-       get_pname(pid, pname);
+       display_misc_get_process_name(pid, pname);
 
        if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) &&
            (pm_get_power_lock() == POWER_UNLOCK))
@@ -939,7 +913,7 @@ static void proc_condition_unlock(PMMsg *data)
                return;
 
        flags = GET_COND_FLAG(data->cond);
-       get_pname(pid, pname);
+       display_misc_get_process_name(pid, pname);
 
        tmp = find_node(state, pid);
        del_node(state, tmp);
@@ -1073,7 +1047,7 @@ void print_info(int fd)
 
        for (s_index = S_NORMAL; s_index < S_END; s_index++) {
                SYS_G_LIST_FOREACH(get_cond_head(s_index), elem, t) {
-                       get_pname((pid_t)t->pid, pname);
+                       display_misc_get_process_name((pid_t)t->pid, pname);
                        ctime_r(&t->time, time_buf);
                        time_buf[strlen(time_buf) - 1] = 0;
                        snprintf(buf, sizeof(buf),
index 2762b3b..cf359f1 100644 (file)
@@ -384,32 +384,6 @@ void set_lcd_paneloff_mode(int val)
                disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL);
 }
 
-void get_pname(pid_t pid, char *pname)
-{
-       char buf[PATH_MAX];
-       int cmdline, r;
-
-       if (pid >= INTERNAL_LOCK_BASE)
-               snprintf(buf, PATH_MAX, "/proc/%d/cmdline", getpid());
-       else
-               snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid);
-
-       cmdline = open(buf, O_RDONLY);
-       if (cmdline < 0) {
-               pname[0] = '\0';
-               _E("Process(%d) does not exist now(may be dead without unlock).", pid);
-               return;
-       }
-
-       r = read(cmdline, pname, PATH_MAX);
-       if ((r >= 0) && (r < PATH_MAX))
-               pname[r] = '\0';
-       else
-               pname[0] = '\0';
-
-       close(cmdline);
-}
-
 static void del_state_cond(void *data, enum state_t state)
 {
        PmLockNode *tmp = NULL;
@@ -869,7 +843,7 @@ static void proc_condition_lock(PMMsg *data)
                return;
 
        flags = GET_COND_FLAG(data->cond);
-       get_pname(pid, pname);
+       display_misc_get_process_name(pid, pname);
 
        if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) &&
            (pm_get_power_lock() == POWER_UNLOCK))
@@ -949,7 +923,7 @@ static void proc_condition_unlock(PMMsg *data)
                return;
 
        flags = GET_COND_FLAG(data->cond);
-       get_pname(pid, pname);
+       display_misc_get_process_name(pid, pname);
 
        tmp = find_node(state, pid);
        del_node(state, tmp);
@@ -1083,7 +1057,7 @@ void print_info(int fd)
 
        for (s_index = S_NORMAL; s_index < S_END; s_index++) {
                SYS_G_LIST_FOREACH(get_cond_head(s_index), elem, t) {
-                       get_pname((pid_t)t->pid, pname);
+                       display_misc_get_process_name((pid_t)t->pid, pname);
                        ctime_r(&t->time, time_buf);
                        time_buf[strlen(time_buf) - 1] = 0;
                        snprintf(buf, sizeof(buf),
index bb65640..f6adbad 100644 (file)
@@ -377,32 +377,6 @@ void set_lcd_paneloff_mode(int val)
                disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL);
 }
 
-void get_pname(pid_t pid, char *pname)
-{
-       char buf[PATH_MAX];
-       int cmdline, r;
-
-       if (pid >= INTERNAL_LOCK_BASE)
-               snprintf(buf, PATH_MAX, "/proc/%d/cmdline", getpid());
-       else
-               snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid);
-
-       cmdline = open(buf, O_RDONLY);
-       if (cmdline < 0) {
-               pname[0] = '\0';
-               _E("Process(%d) does not exist now(may be dead without unlock).", pid);
-               return;
-       }
-
-       r = read(cmdline, pname, PATH_MAX);
-       if ((r >= 0) && (r < PATH_MAX))
-               pname[r] = '\0';
-       else
-               pname[0] = '\0';
-
-       close(cmdline);
-}
-
 static void del_state_cond(void *data, enum state_t state)
 {
        PmLockNode *tmp = NULL;
@@ -858,7 +832,7 @@ static void proc_condition_lock(PMMsg *data)
                return;
 
        flags = GET_COND_FLAG(data->cond);
-       get_pname(pid, pname);
+       display_misc_get_process_name(pid, pname);
 
        if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) &&
            (pm_get_power_lock() == POWER_UNLOCK))
@@ -939,7 +913,7 @@ static void proc_condition_unlock(PMMsg *data)
                return;
 
        flags = GET_COND_FLAG(data->cond);
-       get_pname(pid, pname);
+       display_misc_get_process_name(pid, pname);
 
        tmp = find_node(state, pid);
        del_node(state, tmp);
@@ -1073,7 +1047,7 @@ void print_info(int fd)
 
        for (s_index = S_NORMAL; s_index < S_END; s_index++) {
                SYS_G_LIST_FOREACH(get_cond_head(s_index), elem, t) {
-                       get_pname((pid_t)t->pid, pname);
+                       display_misc_get_process_name((pid_t)t->pid, pname);
                        ctime_r(&t->time, time_buf);
                        time_buf[strlen(time_buf) - 1] = 0;
                        snprintf(buf, sizeof(buf),
index f0e71dd..4f52af4 100644 (file)
@@ -654,32 +654,6 @@ void set_lcd_paneloff_mode(int val)
                disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL);
 }
 
-void get_pname(pid_t pid, char *pname)
-{
-       char buf[PATH_MAX];
-       int cmdline, r;
-
-       if (pid >= INTERNAL_LOCK_BASE)
-               snprintf(buf, PATH_MAX, "/proc/%d/cmdline", getpid());
-       else
-               snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid);
-
-       cmdline = open(buf, O_RDONLY);
-       if (cmdline < 0) {
-               pname[0] = '\0';
-               _E("Process(%d) does not exist now(may be dead without unlock).", pid);
-               return;
-       }
-
-       r = read(cmdline, pname, PATH_MAX);
-       if ((r >= 0) && (r < PATH_MAX))
-               pname[r] = '\0';
-       else
-               pname[0] = '\0';
-
-       close(cmdline);
-}
-
 static void del_state_cond(void *data, enum state_t state)
 {
        PmLockNode *tmp = NULL;
@@ -1168,7 +1142,7 @@ static void proc_condition_lock(PMMsg *data)
                return;
 
        flags = GET_COND_FLAG(data->cond);
-       get_pname(pid, pname);
+       display_misc_get_process_name(pid, pname);
 
        if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) &&
            (pm_get_power_lock() == POWER_UNLOCK))
@@ -1249,7 +1223,7 @@ static void proc_condition_unlock(PMMsg *data)
                return;
 
        flags = GET_COND_FLAG(data->cond);
-       get_pname(pid, pname);
+       display_misc_get_process_name(pid, pname);
 
        tmp = find_node(state, pid);
        del_node(state, tmp);
@@ -1383,7 +1357,7 @@ void print_info(int fd)
 
        for (s_index = S_NORMAL; s_index < S_END; s_index++) {
                SYS_G_LIST_FOREACH(get_cond_head(s_index), elem, t) {
-                       get_pname((pid_t)t->pid, pname);
+                       display_misc_get_process_name((pid_t)t->pid, pname);
                        ctime_r(&t->time, time_buf);
                        time_buf[strlen(time_buf) - 1] = 0;
                        snprintf(buf, sizeof(buf),
index eac18f0..5acd18e 100644 (file)
  * limitations under the License.
  */
 
+#include <stdio.h>
+
 #include <vconf-keys.h>
 
+#include "shared/log.h"
 #include "display-misc.h"
+#include "poll.h"
 
 /* FIXME: This fucntion should be relocated under the battery module */
 bool display_misc_is_low_battery_state(int val)
@@ -32,3 +36,30 @@ bool display_misc_is_low_battery_state(int val)
 
        return false;
 }
+
+/* FIXME: The location of this function should be discussed later */
+void display_misc_get_process_name(pid_t pid, char *pname)
+{
+       char buf[PATH_MAX];
+       int cmdline, r;
+
+       if (pid >= INTERNAL_LOCK_BASE)
+               snprintf(buf, PATH_MAX, "/proc/%d/cmdline", getpid());
+       else
+               snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid);
+
+       cmdline = open(buf, O_RDONLY);
+       if (cmdline < 0) {
+               pname[0] = '\0';
+               _E("Process(%d) does not exist now(may be dead without unlock).", pid);
+               return;
+       }
+
+       r = read(cmdline, pname, PATH_MAX);
+       if ((r >= 0) && (r < PATH_MAX))
+               pname[r] = '\0';
+       else
+               pname[0] = '\0';
+
+       close(cmdline);
+}
index aabb477..ef4a78e 100644 (file)
@@ -25,7 +25,9 @@
 #define __DISPLAY_MISC_H__
 
 #include <stdbool.h>
+#include <sys/types.h>
 
 bool display_misc_is_low_battery_state(int val);
+void display_misc_get_process_name(pid_t pid, char *pname);
 
 #endif /* __DISPLAY_MISC_H__ */
\ No newline at end of file