From d9be9d3ddc05f54eee6289d9fb0ccba5546cfdc5 Mon Sep 17 00:00:00 2001 From: Kunhoon Baik Date: Mon, 14 Nov 2016 22:08:29 +0900 Subject: Bug Fix & Minor code changes - Bug Fix from Mr.Kim of MCD - Close object at the appropriate time Change-Id: Ie9331dbedf0ffa69507c99fda00bd8314c3cefb9 Signed-off-by: Kichan Kwon --- src/common/file-helper.c | 6 ++-- src/common/userinfo-list.c | 3 +- src/proc-stat/proc-main.c | 84 ++++++++++++++++++++++++---------------------- 3 files changed, 49 insertions(+), 44 deletions(-) diff --git a/src/common/file-helper.c b/src/common/file-helper.c index a5ff38e2..8f1f599e 100644 --- a/src/common/file-helper.c +++ b/src/common/file-helper.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "file-helper.h" #include "trace.h" @@ -82,14 +83,13 @@ int fwrite_uint(const char *path, const u_int32_t number) int fread_str(const char *path, char **str) { _cleanup_fclose_ FILE *f = NULL; - int ret; f = fopen(path, "r"); ret_value_errno_msg_if(!f, -errno, "Fail to open %s file.", path); - ret = fscanf(f, "%s", *str); - ret_value_errno_msg_if(ret == EOF, -errno, + *str = fgets(*str, LINE_MAX, f); + ret_value_errno_msg_if(!(*str), -ENODATA, "Fail to read file\n"); return RESOURCED_ERROR_NONE; diff --git a/src/common/userinfo-list.c b/src/common/userinfo-list.c index c6e0e514..3a4d96a5 100644 --- a/src/common/userinfo-list.c +++ b/src/common/userinfo-list.c @@ -54,9 +54,10 @@ resourced_ret_c get_all_users_info(GHashTable **table) g_strfreev(query); if (!users) { + g_object_unref(gus); + if (!(*table)) { _E("Fail to get gum user list"); - g_object_unref(gus); return RESOURCED_ERROR_FAIL; } _D("Fail to get gum user list. Use existing user list."); diff --git a/src/proc-stat/proc-main.c b/src/proc-stat/proc-main.c index cbc07960..69b5b0ec 100644 --- a/src/proc-stat/proc-main.c +++ b/src/proc-stat/proc-main.c @@ -73,17 +73,6 @@ static GSList *proc_module; /* proc sub-module list */ struct proc_app_list app_list = { .lock = PTHREAD_MUTEX_INITIALIZER }; static GSList *proc_program_list; -GSList *proc_app_list_open(void) -{ - if (app_list.tid != gettid()) { - pthread_mutex_lock(&app_list.lock); - app_list.tid = gettid(); - } - - app_list.ref++; - - return app_list.list; -} void proc_app_list_close(void) { @@ -102,6 +91,18 @@ void proc_app_list_close(void) strerror(err)); } +GSList *proc_app_list_open(void) +{ + if (app_list.tid != gettid()) { + pthread_mutex_lock(&app_list.lock); + app_list.tid = gettid(); + } + + app_list.ref++; + + return app_list.list; +} + static bool is_ui_app(enum application_type type) { if (type == PROC_TYPE_GUI || type == PROC_TYPE_WIDGET || @@ -110,6 +111,7 @@ static bool is_ui_app(enum application_type type) return false; } + static char *proc_get_runtime_app_info_path(const struct proc_app_info *pai) { char *p = NULL; @@ -147,7 +149,7 @@ static char *proc_get_runtime_app_info_path(const struct proc_app_info *pai) assert(data); \ \ snprintf(app_info_node, PATH_MAX, "%s/"#node"", path); \ - *data = (char*)malloc(PATH_MAX); \ + *data = (char*)calloc(1, PATH_MAX); \ return fread_str(app_info_node, data); \ } @@ -291,6 +293,7 @@ static int proc_runtime_app_info_read_procs(const char *path, pid_list *child_li snprintf(app_info_node, PATH_MAX, "%s/procs", path); + buf = calloc(1, PATH_MAX); ret = fread_str(app_info_node, &buf); if (ret < 0) return ret; @@ -365,10 +368,11 @@ struct proc_app_info *find_app_info_by_appid(const char *appid) GSList *iter = NULL; struct proc_app_info *pai; - if (!appid) + proc_app_list = proc_app_list_open(); + + if (!appid || !proc_app_list) return NULL; - proc_app_list = proc_app_list_open(); gslist_for_each_item(iter, proc_app_list) { pai = (struct proc_app_info *)iter->data; if (equal_name_info(pai->appid, appid)) @@ -384,14 +388,15 @@ struct proc_app_info *find_app_info(const pid_t pid) struct proc_app_info *pai = NULL; proc_app_list = proc_app_list_open(); + + if (!proc_app_list) + return NULL; + gslist_for_each_item(iter, proc_app_list) { pai = (struct proc_app_info *)iter->data; - if (pai->main_pid == pid) + if ((pai->main_pid == pid) || + (pai->childs && g_slist_find(pai->childs, PID_TO_GPOINTER(pid)))) return pai; - if (pai->childs) { - if (g_slist_find(pai->childs, PID_TO_GPOINTER(pid))) - return pai; - } } return NULL; } @@ -672,8 +677,6 @@ struct proc_app_info *proc_add_app_list(const int type, const pid_t pid, static void _remove_child_pids(struct proc_app_info *pai, pid_t pid) { _cleanup_free_ char *runtime_app_info_path = NULL; - GSList *iter, *next; - pid_t *child; int ret; assert(pai); @@ -682,21 +685,6 @@ static void _remove_child_pids(struct proc_app_info *pai, pid_t pid) if (!pai->childs) return; - /* - * if pid has a valid value, remove only one child with same pid - * otherwise pid is zero, remove all child pids - */ - gslist_for_each_safe(pai->childs, iter, next, child) { - if (pid && pid != *child) - continue; - pai->childs = g_slist_remove(pai->childs, child); - if (pid) - return; - } - - if (!g_slist_find(pai->childs, PID_TO_GPOINTER(pid))) - return; - runtime_app_info_path = proc_get_runtime_app_info_path(pai); if (!runtime_app_info_path) { _E("Failed to get runtime appinfo path: %s", strerror(ENOMEM)); @@ -706,6 +694,9 @@ static void _remove_child_pids(struct proc_app_info *pai, pid_t pid) if (pid == 0) goto remove_all; + if (!g_slist_find(pai->childs, PID_TO_GPOINTER(pid))) + return; + pai->childs = g_slist_remove(pai->childs, PID_TO_GPOINTER(pid)); if (!g_slist_length(pai->childs)) goto remove_all; @@ -745,12 +736,13 @@ int proc_remove_app_list(const pid_t pid) continue; if (pai->main_pid == pid) { + _remove_child_pids(pai, 0); + ret = proc_runtime_remove_app_info(pai); if (ret < 0) _E("Failed to remove appinfo '%s': %s", pai->appid, strerror(-ret)); - _remove_child_pids(pai, 0); ppi = pai->program; if (ppi) { if (is_ui_app(pai->type)) @@ -768,8 +760,10 @@ int proc_remove_app_list(const pid_t pid) free(pai); break; } else if (pai->childs) { - _remove_child_pids(pai, pid); - break; + if (g_slist_find(pai->childs, PID_TO_GPOINTER(pid))) { + _remove_child_pids(pai, pid); + break; + } } else continue; } @@ -861,8 +855,13 @@ static void proc_dump_process_list(FILE *fp) struct proc_app_info *pai = NULL; int index = 0, ret, oom_score_adj; - LOG_DUMP(fp, "[APPLICATION LISTS]\n"); proc_app_list = proc_app_list_open(); + + LOG_DUMP(fp, "[APPLICATION LISTS]\n"); + + if (!proc_app_list) + return; + gslist_for_each_item(iter, proc_app_list) { char *typestr; unsigned int size; @@ -1350,6 +1349,11 @@ void proc_set_group(pid_t ownerpid, pid_t childpid, char *pkgname) ps.pid = childpid; proc_set_oom_score_adj(childpid, owner_oom); } + + if (!ps.pid) + return; + + ps.pai = owner; resourced_notify(RESOURCED_NOTIFIER_APP_WAKEUP, &ps); } -- cgit v1.2.3