Revert "[Non-ACR] hold pid always, change app_id" 97/259497/1
authorRandeep Singh <randeep.s@samsung.com>
Wed, 9 Jun 2021 05:04:31 +0000 (05:04 +0000)
committerRandeep Singh <randeep.s@samsung.com>
Wed, 9 Jun 2021 05:04:31 +0000 (05:04 +0000)
This reverts commit a1772216ce7ae95a1fa97b4862609d454f4e234c.

Change-Id: If0802a39547748459a2d7141a7d41013eaf5c9c5

src/battery_dump/bm_listeners.c

index 8e57b40cd608fbeacfa9ce910ff4c7d61e8fed9c..5f4632d047f4c2a7bcfe1d83cf90da2d2c86cf62 100644 (file)
@@ -87,16 +87,15 @@ static void bd_set_free_data_object(void)
 
 static void bd_get_app_id_from_table(gint pid, char **app_id)
 {
-       BD_CHECK_VALIDITY_RETURN((pid_map != NULL), {});
-
-       if (g_hash_table_size(pid_map) <= 0) {
-               _WARN("empty app_id-pid map");
+       if (pid_map == NULL) {
+               _ERR("invalid pid_map");
                return;
        }
 
-       _DBG("get app_id for pid[%d], table size[%d]", pid, g_hash_table_size(pid_map));
+       _DBG("app_id for pid[%d], table size[%d]", pid, g_hash_table_size(pid_map));
 
-       void *orig_pid = NULL, *orig_app_id = NULL;
+       void *orig_pid = NULL;
+       void *orig_app_id = NULL;
 
        if (g_hash_table_lookup_extended(pid_map, &pid, &orig_pid, &orig_app_id) == true) {
                *app_id = strdup((char *)orig_app_id);
@@ -111,52 +110,22 @@ static void bd_get_app_id_from_table(gint pid, char **app_id)
 
 static void bd_insert_app_id_into_table(gint pid, char *appid)
 {
-       BD_CHECK_VALIDITY_RETURN((appid != NULL), {});
-
-       gint* lpid = NULL;
-       static bool isEmpty = true;
-
-       _DBG("insert app_id for pid[%d], table size[%d]", pid, g_hash_table_size(pid_map));
-
-       if (!isEmpty) {
-               gpointer orig_pid = NULL, orig_app_id = NULL;
-               /* if not empty then check if pid-app_id is redundant */
-               if (g_hash_table_lookup_extended(pid_map, &pid, &orig_pid, &orig_app_id) == true) {
-                       /* redundant pid, check if redundant app_id */
-                       if (g_strcmp0(appid, (char *)orig_app_id) == 0) {
-                               _DBG("redundant pid[%d], app_id[%s]", pid, appid);
-                               return;
-                       } else {
-                               _DBG("replacing pid[%d], app_id[%s]", pid, appid);
-                               /* app_id is not redundant,
-                                * means this pid is assigned to new app_id
-                                * replace old app_id with new app_id, delete old pid-app_id */
-                               lpid = g_new0(gint, 1);
-                               BD_CHECK_VALIDITY_RETURN((lpid != NULL), {});
-
-                               *lpid = pid;
+       if (appid == NULL) {
+               _ERR("invalid appid");
+               return;
+       }
 
-                               if (g_hash_table_replace(pid_map, lpid, strdup(appid)) == false)
-                                       _ERR("failed to replace old app_id");
-                       }
-               } else {
-                       GHashTableIter iter;
-                       gpointer stale_pid = NULL, stale_app_id = NULL;
-
-                       g_hash_table_iter_init(&iter, pid_map);
-                       /* delete stale pid-app_id */
-                       while (g_hash_table_iter_next(&iter, &stale_pid, &stale_app_id)) {
-                               if (g_strcmp0(appid, (char *)stale_app_id) == 0) {
-                                       _DBG("removed stale - pid[%d], app_id[%s]", \
-                                               *((int *)stale_pid), (char *)stale_app_id);
-                                       g_hash_table_iter_remove(&iter);
-                               }
-                       }
-               }
+       /* redundant keys are not required */
+       if (g_hash_table_contains(pid_map, &pid) == true) {
+               _DBG("key[%d] already present, no insertion required", pid);
+               return;
        }
 
-       lpid = g_new0(gint, 1);
-       BD_CHECK_VALIDITY_RETURN((lpid != NULL), {});
+       gint* lpid = g_new0(gint, 1);
+       if (lpid == NULL) {
+               _ERR("failed to allocate memory");
+               return;
+       }
 
        *lpid = pid;
 
@@ -165,8 +134,19 @@ static void bd_insert_app_id_into_table(gint pid, char *appid)
        if (g_hash_table_insert(pid_map, lpid, strdup(appid)) == false)
                _WARN("key already available, replacing old value");
 
-       isEmpty = false;
+       return;
+}
 
+static void bd_remove_app_id_from_table(gint pid)
+{
+       if (g_hash_table_contains(pid_map, &pid) != true) {
+               _DBG("key[%d] not present in list", pid);
+               return;
+       }
+
+       g_hash_table_remove(pid_map, &pid);
+
+       _DBG("removed key[%d] from table", pid);
        return;
 }
 
@@ -1989,6 +1969,9 @@ static void _bd_listener_app_terminate_signal_cb(GDBusConnection *conn, const gc
                return;
        }
 
+       /* remove app_id from table as terminate signal is received */
+       bd_remove_app_id_from_table(pid);
+
        /* get event object */
        event_pool *event = bd_listener_get_event_obj(LISTEN_APP_STATUS, val, app_id);
        if (event == NULL) {