From e784c0e27004e6d04a289db46d4583857c75bcd1 Mon Sep 17 00:00:00 2001 From: Abhishek Vijay Date: Fri, 25 Sep 2020 19:25:10 +0530 Subject: [PATCH] [Non-ACR] check file availability Change-Id: Ibebb9f69e40ef63b62d34704a79998f5c2c5c166 Signed-off-by: Abhishek Vijay --- include/bm_util.h | 2 +- src/battery_dump/bm_listeners.c | 19 +++++++++++++++---- src/bm_util.c | 7 ++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/bm_util.h b/include/bm_util.h index 06d8aff..3349270 100644 --- a/include/bm_util.h +++ b/include/bm_util.h @@ -61,7 +61,7 @@ GDBusConnection* bm_get_dbus_connection_obj(void); void bd_get_focussed_app_id(char **app_name); -void bm_get_name_from_pid(pid_t pid, char **pname); +void bm_get_name_for_pid(pid_t pid, char **pname); void bm_data_free(gpointer data); diff --git a/src/battery_dump/bm_listeners.c b/src/battery_dump/bm_listeners.c index d390fe7..160b36b 100644 --- a/src/battery_dump/bm_listeners.c +++ b/src/battery_dump/bm_listeners.c @@ -1714,21 +1714,29 @@ static void _bd_listener_create_lock_event(char *lock_type, pid_t pid) static int prev_lock = 0; char *pname = NULL; + _INFO("lock [%s], pid [%d]", lock_type, pid); + if (g_strcmp0(lock_type, "lcdoff") == 0) val = 0; else if (g_strcmp0(lock_type, "lcddim") == 0) val = 1; else if (g_strcmp0(lock_type, "lcdon") == 0) val = 2; - else + else { + _DBG("different lock_type - [%s]", lock_type); return; + } - if (prev_lock == val) + if (prev_lock == val) { + _DBG("return due to same values"); return; - else + } else { prev_lock = val; + } + + bm_get_name_for_pid(pid, &pname); - bm_get_name_from_pid(pid, &pname); + _DBG("received process name - [%s]", pname); /* get event object */ event_pool *event = bd_listener_get_event_obj(LISTEN_POWERLOCKUNLOCK_STATE, val, pname); @@ -1749,9 +1757,11 @@ static void _bd_listener_powerlock_signal_cb(GDBusConnection *conn, const gchar const gchar *iface, const gchar *signal, GVariant *params, gpointer user_data) { ENTER; + pid_t pid; char *lock_type; unsigned int timeout; + g_variant_get(params, "(&sii)", &lock_type, &pid, &timeout); _INFO(" powerlock value changed =%s Pid=%d, timeout=%d", lock_type, pid, timeout); @@ -1766,6 +1776,7 @@ static void _bd_listener_powerunlock_signal_cb(GDBusConnection *conn, const gcha const gchar *iface, const gchar *signal, GVariant *params, gpointer user_data) { ENTER; + pid_t pid; char *lock_type; unsigned int timeout; diff --git a/src/bm_util.c b/src/bm_util.c index 5665a51..49f397a 100644 --- a/src/bm_util.c +++ b/src/bm_util.c @@ -369,7 +369,7 @@ void bd_get_focussed_app_id(char **app_name) return; } -void bm_get_name_from_pid(pid_t pid, char **pname) +void bm_get_name_for_pid(pid_t pid, char **pname) { _INFO("pid = [%d]", pid); @@ -383,6 +383,11 @@ void bm_get_name_from_pid(pid_t pid, char **pname) snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid); + if (access(buf, F_OK) != 0) { + _ERR("maybe pid no more exists"); + return; + } + fd = open(buf, O_RDONLY); if (fd < 0) { _ERR("process(%d) does not exist now.", pid); -- 2.7.4