Fix resolving ug library path 84/61784/5 accepted/tizen/common/20160311.203802 accepted/tizen/ivi/20160311.150323 accepted/tizen/mobile/20160311.143310 accepted/tizen/tv/20160311.144854 accepted/tizen/wearable/20160311.145702 submit/tizen/20160311.071153
authorSangyoon Jang <s89.jang@samsung.com>
Thu, 10 Mar 2016 11:57:22 +0000 (20:57 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Fri, 11 Mar 2016 04:37:39 +0000 (13:37 +0900)
Change-Id: I4b931c25c9de40dc964a0d24a9a4890c06846404
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
src/module.c

index 600075e..eecc9a8 100644 (file)
@@ -29,6 +29,7 @@
 #include <sys/types.h>
 
 #include <aul.h>
+#include <pkgmgr-info.h>
 
 #include "ug-module.h"
 #include "ug-dbg.h"
 #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;
 }