diff options
author | Kichan Kwon <k_c.kwon@samsung.com> | 2017-02-20 19:29:45 +0900 |
---|---|---|
committer | Kichan Kwon <k_c.kwon@samsung.com> | 2017-02-20 19:31:19 +0900 |
commit | 92f501816e80b0ad5f44824fbe00239b368f936a (patch) | |
tree | f6a1c2e1af1cdd846ba5e137586f7a44ed926d25 | |
parent | 2e0fab7271d810a648a563b83e42e7d6d1dbae72 (diff) | |
parent | f503660e8a7664f738e81e49f5b8e58c10bed827 (diff) | |
download | resourced-92f501816e80b0ad5f44824fbe00239b368f936a.tar.gz resourced-92f501816e80b0ad5f44824fbe00239b368f936a.tar.bz2 resourced-92f501816e80b0ad5f44824fbe00239b368f936a.zip |
Merge branch 'tizen_3.0' into tizen
Change-Id: I5af804e7f0c19044071d805096102f72b2462d15
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
-rw-r--r-- | src/common/notifier.h | 5 | ||||
-rw-r--r-- | src/heart/heart-cpu.c | 19 | ||||
-rw-r--r-- | src/heart/include/logging.h | 1 | ||||
-rw-r--r-- | src/heart/logging.c | 142 | ||||
-rw-r--r-- | src/proc-stat/proc-main.c | 10 |
5 files changed, 150 insertions, 27 deletions
diff --git a/src/common/notifier.h b/src/common/notifier.h index 70ffde93..3b55b5f8 100644 --- a/src/common/notifier.h +++ b/src/common/notifier.h @@ -51,6 +51,11 @@ enum notifier_type { RESOURCED_NOTIFIER_APP_SUSPEND, /* + * group some applications + */ + RESOURCED_NOTIFIER_APP_GROUP, + + /* * service status */ RESOURCED_NOTIFIER_SERVICE_LAUNCH, diff --git a/src/heart/heart-cpu.c b/src/heart/heart-cpu.c index 7743890b..71ec5262 100644 --- a/src/heart/heart-cpu.c +++ b/src/heart/heart-cpu.c @@ -1143,6 +1143,23 @@ int heart_cpu_get_appusage_list(int uid, GHashTable *lists, int top) return RESOURCED_ERROR_NONE; } +static int heart_cpu_update_appid(void *data) +{ + int pid; + char old_appid[MAX_APPID_LENGTH], new_appid[MAX_APPID_LENGTH]; + char *info; + + if (!data) { + _E("Invalid parameter"); + return RESOURCED_ERROR_INVALID_PARAMETER; + } + + info = (char*)data; + sscanf(info, "%d %s %s", &pid, old_appid, new_appid); + + return logging_modify_appid(CPU_NAME, old_appid, new_appid, pid); +} + static DBusMessage *edbus_heart_get_cpu_data(E_DBus_Object *obj, DBusMessage *msg) { int period, index, i, ret; @@ -1539,6 +1556,7 @@ static int heart_cpu_init(void *data) register_notifier(RESOURCED_NOTIFIER_SERVICE_LAUNCH, heart_cpu_service_launch); register_notifier(RESOURCED_NOTIFIER_APP_FOREGRD, heart_cpu_foreground_state); register_notifier(RESOURCED_NOTIFIER_APP_BACKGRD, heart_cpu_background_state); + register_notifier(RESOURCED_NOTIFIER_APP_GROUP, heart_cpu_update_appid); register_notifier(RESOURCED_NOTIFIER_DATA_UPDATE, heart_cpu_update_app_list); register_notifier(RESOURCED_NOTIFIER_DATA_RESET, heart_cpu_reset); @@ -1555,6 +1573,7 @@ static int heart_cpu_exit(void *data) unregister_notifier(RESOURCED_NOTIFIER_SERVICE_LAUNCH, heart_cpu_service_launch); unregister_notifier(RESOURCED_NOTIFIER_APP_FOREGRD, heart_cpu_foreground_state); unregister_notifier(RESOURCED_NOTIFIER_APP_BACKGRD, heart_cpu_background_state); + unregister_notifier(RESOURCED_NOTIFIER_APP_GROUP, heart_cpu_update_appid); unregister_notifier(RESOURCED_NOTIFIER_DATA_UPDATE, heart_cpu_update_app_list); unregister_notifier(RESOURCED_NOTIFIER_DATA_RESET, heart_cpu_reset); diff --git a/src/heart/include/logging.h b/src/heart/include/logging.h index d855ff56..80f5780d 100644 --- a/src/heart/include/logging.h +++ b/src/heart/include/logging.h @@ -129,6 +129,7 @@ int logging_write(int pid, char *name, char *appid, char *pkgid, time_t time, ch int logging_delete(int uid, char *name, char *data); int logging_read_foreach(char *name, char *appid, char *pkgid, time_t start_time, time_t end_time, logging_info_cb callback, void *user_data); +int logging_modify_appid(char *module_name, char *old_appid, char *new_appid, int pid); void logging_update(int force); void logging_save_to_storage(int force); int logging_sync(DBusMessage *reply); diff --git a/src/heart/logging.c b/src/heart/logging.c index 6f5c44ea..b0922738 100644 --- a/src/heart/logging.c +++ b/src/heart/logging.c @@ -62,6 +62,7 @@ #define DELETE_QUERY_WITH_DATA "DELETE from %s where data = ?;" #define INSERT_QUERY "INSERT INTO %s values (?, ?, ?, ?, ?);" #define SELECT_QUERY "SELECT * FROM %s WHERE time > %d AND time < %d;" +#define UPDATE_APPID_QUERY "UPDATE %s SET appid = \'%s\' WHERE appid = \'%s\';" #define SELECT_BEGIN_QUERY "SELECT * FROM %s " #define SELECT_WHERE_QUERY "WHERE" @@ -162,6 +163,35 @@ long logging_get_time_ms(void) return (tv.tv_sec * 1000 + tv.tv_usec / 1000); } +static int logging_convert_pid_to_uid(int pid) +{ + char buf[LOGGING_BUF_MAX]; + char key[20]; + FILE *fp = NULL; + int uid = -1; + + if (pid == PID_FOR_ROOT) + return UID_FOR_ROOT; + + snprintf(buf, LOGGING_BUF_MAX, "/proc/%d/status", pid); + fp = fopen(buf, "r"); + if (fp == NULL) { + _E("Fail to open status file"); + return -1; + } + + while (fgets(buf, LOGGING_BUF_MAX, fp) != NULL) { + sscanf(buf, "%s %d", key, &uid); + if (!strncmp(key, "Uid:", sizeof("Uid:") + 1)) { + fclose(fp); + return uid; + } + } + + fclose(fp); + return -1; +} + static struct logging_module *logging_find_module(char *name) { int i; @@ -620,36 +650,12 @@ int logging_operate(int uid, char *name, char *appid, char *pkgid, time_t time, int logging_write(int pid, char *name, char *appid, char *pkgid, time_t time, char *data) { - FILE *fp = NULL; - char buf[LOGGING_BUF_MAX]; - char key[20]; - int uid = -1; - int val; - - if (pid == PID_FOR_ROOT) - return logging_operate(UID_FOR_ROOT, name, appid, pkgid, time, data, INSERT); + int uid = logging_convert_pid_to_uid(pid); - snprintf(buf, LOGGING_BUF_MAX, "/proc/%d/status", pid); - fp = fopen(buf, "r"); - if (fp == NULL) { - _E("Fail to open status file"); + if (uid < 0) { + _E("Fail to get uid"); return RESOURCED_ERROR_FAIL; } - - while (fgets(buf, LOGGING_BUF_MAX, fp) != NULL) { - sscanf(buf, "%s %d", key, &val); - if (!strncmp(key, "Uid:", sizeof("Uid:") + 1)) { - uid = val; - break; - } - } - fclose(fp); - - if (uid == -1) { - _E("There is no uid in the status file"); - return RESOURCED_ERROR_FAIL; - } - return logging_operate(uid, name, appid, pkgid, time, data, INSERT); } @@ -1067,6 +1073,88 @@ static int logging_check_storage_size(const char *db_path) return RESOURCED_ERROR_NONE; } +int logging_modify_appid(char *module_name, char *old_appid, char *new_appid, int pid) +{ + struct logging_module *module = NULL; + int uid = -1; + struct logging_db *db = NULL; + char query[LOGGING_BUF_MAX]; + int i; + struct logging_table_form *entry; + + if (!module_name || !old_appid || !new_appid || pid < 0) { + _E("Invalid parameter"); + return RESOURCED_ERROR_INVALID_PARAMETER; + } + + module = logging_find_module(module_name); + if (!module) { + _E("There is no %s module", module_name); + return RESOURCED_ERROR_NO_DATA; + } + + uid = logging_convert_pid_to_uid(pid); + if (uid < 0) { + _E("Fail to get uid"); + return RESOURCED_ERROR_FAIL; + } + + if (pthread_mutex_lock(&logging_update_mutex)) { + _E("Failed to lock mutex"); + return RESOURCED_ERROR_FAIL; + } + + /* Modify cache */ + if (!g_queue_is_empty(module->cache)) { + pthread_mutex_lock(&(module->cache_mutex)); + for (i = 0; i < g_queue_get_length(module->cache); i++) { + entry = (struct logging_table_form *)g_queue_peek_nth( + module->cache, i); + if (entry->uid == uid && !strncmp(entry->appid, old_appid, strlen(old_appid))) + snprintf(entry->appid, MAX_APPID_LENGTH, "%s", new_appid); + } + pthread_mutex_unlock(&(module->cache_mutex)); + } + + /* Modify DB */ + switch (module->db_type) { + case SYSTEM_DEFAULT: + case SYSTEM_OWN: + db = g_hash_table_lookup(module->db_list, GINT_TO_POINTER(UID_FOR_ROOT)); + break; + case USER_DEFAULT: + case USER_OWN: + db = g_hash_table_lookup(module->db_list, (gpointer)(&uid)); + break; + default: + _E("Unknown db_type"); + pthread_mutex_unlock(&logging_update_mutex); + return RESOURCED_ERROR_FAIL; + } + + if (!db) { + _E("Failed to get DB"); + pthread_mutex_unlock(&logging_update_mutex); + return RESOURCED_ERROR_NO_DATA; + } + + snprintf(query, LOGGING_BUF_MAX, UPDATE_APPID_QUERY, + module_name, new_appid, old_appid); + + if (sqlite3_exec(db->file, query, NULL, NULL, NULL) != SQLITE_OK) { + _E("Failed to apply query"); + pthread_mutex_unlock(&logging_update_mutex); + return RESOURCED_ERROR_DB_FAILED; + } + + if (pthread_mutex_unlock(&logging_update_mutex)) { + _E("Failed to unlock mutex"); + return RESOURCED_ERROR_FAIL; + } + + return RESOURCED_ERROR_NONE; +} + void logging_update(int force) { int i, ret; diff --git a/src/proc-stat/proc-main.c b/src/proc-stat/proc-main.c index 2fe03eff..903d0370 100644 --- a/src/proc-stat/proc-main.c +++ b/src/proc-stat/proc-main.c @@ -1331,6 +1331,7 @@ void proc_set_group(pid_t ownerpid, pid_t childpid, char *pkgname) int child_type = 0, child_state = 0; struct proc_app_info *pai, *owner; struct proc_status ps = {0}; + char group_info[512]; if (ownerpid <= 0 || childpid <= 0) return; @@ -1353,6 +1354,15 @@ void proc_set_group(pid_t ownerpid, pid_t childpid, char *pkgname) if (pkgname && pai) { /* + * After grouping, resourced considers child pai with parent pai + * Therefore, child appid in HEART-CPU DB should be changed + * to parent appid + */ + snprintf(group_info, sizeof(group_info), "%d %s %s", + childpid, pai->appid, owner->appid); + resourced_notify(RESOURCED_NOTIFIER_APP_GROUP, group_info); + + /* * when child application with appid has owner pai and ppi * check and remove them */ |