summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSangyoon Jang <s89.jang@samsung.com>2016-03-10 20:57:22 +0900
committerSangyoon Jang <s89.jang@samsung.com>2016-03-11 13:37:39 +0900
commitc048bc9706e1208d0889973bc424e1f323670316 (patch)
tree2dca91f4664b9b70311b44f4bdae7ef946479836 /src
parent4b7a384a10243a03c0e3086f58c51dc48f647825 (diff)
downloadui-gadget-1-c048bc9706e1208d0889973bc424e1f323670316.tar.gz
ui-gadget-1-c048bc9706e1208d0889973bc424e1f323670316.tar.bz2
ui-gadget-1-c048bc9706e1208d0889973bc424e1f323670316.zip
Change-Id: I4b931c25c9de40dc964a0d24a9a4890c06846404 Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/module.c105
1 files changed, 62 insertions, 43 deletions
diff --git a/src/module.c b/src/module.c
index 600075e..eecc9a8 100644
--- a/src/module.c
+++ b/src/module.c
@@ -29,6 +29,7 @@
#include <sys/types.h>
#include <aul.h>
+#include <pkgmgr-info.h>
#include "ug-module.h"
#include "ug-dbg.h"
@@ -41,17 +42,6 @@
#define MEM_ADDR_LEN 8
#define MEM_ADDR_TOT_LEN 17
-static int file_exist(const char *filename)
-{
- FILE *file;
- if ((file = fopen(filename, "r"))) {
- fclose(file);
- return 1;
- }
-
- return 0;
-}
-
static char *__ug_module_get_addr(const char *ug_name)
{
FILE *file;
@@ -110,60 +100,89 @@ func_out:
return NULL;
}
-static int __get_ug_info(const char* name, char** ug_file_path)
+static int __file_exist(const char *path)
+{
+ int ret;
+
+ ret = access(path, R_OK);
+ LOGD("ug_file(%s) check %s", path, ret ? "fail" : "ok");
+
+ return ret;
+}
+
+static int __get_ug_info(const char *name, char **ug_file_path)
{
char ug_file[PATH_MAX];
char app_id[NAME_MAX];
- char *path;
+ char *root_path;
+ char *res_path = NULL;
+ pkgmgrinfo_appinfo_h appinfo = NULL;
+ /* get path using name(file name) */
snprintf(ug_file, PATH_MAX, "%s/lib/libug-%s.so",
tzplatform_getenv(TZ_SYS_RO_UG), name);
- if (file_exist(ug_file)) {
- LOGD("ug_file(%s) check ok(%d)", ug_file, errno);
+ if (!__file_exist(ug_file))
goto out_func;
- } else {
- LOGD("ug_file(%s) check fail(%d)", ug_file, errno);
- }
snprintf(ug_file, PATH_MAX, "%s/lib/lib%s.so",
tzplatform_getenv(TZ_SYS_RO_UG), name);
- if (file_exist(ug_file)) {
- LOGD("ug_file(%s) check ok(%d)", ug_file, errno);
+ if (!__file_exist(ug_file))
goto out_func;
- } else {
- LOGD("ug_file(%s) check fail(%d)", ug_file, errno);
- }
- if (aul_get_app_shared_resource_path_by_appid(name, &path) == AUL_R_OK) {
- snprintf(ug_file, PATH_MAX, "%slib/ug/lib%s.so", path, name);
- free(path);
- if (file_exist(ug_file)) {
- LOGD("ug_file(%s) check ok(%d)", ug_file, errno);
- goto out_func;
- } else {
- LOGD("ug_file(%s) check fail(%d)", ug_file, errno);
- }
+ /* get path using appid */
+ if (aul_app_get_appid_bypid(getpid(), app_id, sizeof(app_id))) {
+ LOGE("failed to get appid");
+ return -1;
}
+ snprintf(ug_file, PATH_MAX, "%s/lib/libug-%s.so",
+ tzplatform_getenv(TZ_SYS_RO_UG), app_id);
+ if (!__file_exist(ug_file))
+ goto out_func;
+ snprintf(ug_file, PATH_MAX, "%s/lib/lib%s.so",
+ tzplatform_getenv(TZ_SYS_RO_UG), app_id);
+ if (!__file_exist(ug_file))
+ goto out_func;
- if (aul_app_get_appid_bypid_for_uid(getpid(), app_id,
- sizeof(app_id), getuid()) != AUL_R_OK)
+ /* get path using appid and root path */
+ if (pkgmgrinfo_appinfo_get_usr_appinfo(app_id, getuid(), &appinfo)) {
+ LOGE("failed to get app info");
return -1;
-
- if (strncmp(name, app_id, sizeof(app_id)))
+ }
+ if (pkgmgrinfo_appinfo_get_root_path(appinfo, &root_path)) {
+ LOGE("failed to get app root path");
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
return -1;
-
- snprintf(ug_file, PATH_MAX, "%slib/ug/lib-ug%s.so",
- aul_get_app_root_path(), name);
- if (file_exist(ug_file)) {
- LOGD("ug_file(%s) check ok(%d)", ug_file, errno);
+ }
+ snprintf(ug_file, PATH_MAX, "%s/lib/ug/libug-%s.so", root_path, app_id);
+ if (!__file_exist(ug_file))
goto out_func;
- } else {
- LOGD("ug_file(%s) check fail(%d)", ug_file, errno);
+ snprintf(ug_file, PATH_MAX, "%s/lib/ug/lib%s.so", root_path, app_id);
+ if (!__file_exist(ug_file))
+ goto out_func;
+
+ /* get path using name and shared resource path.
+ * in this case, we need to get other package's ug library
+ * and the 'name' should be ug's appid.
+ */
+ if (aul_get_app_shared_resource_path_by_appid(name, &res_path)) {
+ LOGE("failed to get shared resource path");
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
+ return -1;
}
+ snprintf(ug_file, PATH_MAX, "%s/lib/ug/libug-%s.so", res_path, name);
+ if (!__file_exist(ug_file))
+ goto out_func;
+ snprintf(ug_file, PATH_MAX, "%s/lib/ug/lib-%s.so", res_path, name);
+ if (!__file_exist(ug_file))
+ goto out_func;
out_func:
if ((strlen(ug_file) > 0) && (ug_file_path))
*ug_file_path = strdup(ug_file);
+ free(res_path);
+ if (appinfo)
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
+
return 0;
}