Use thread safe functions and fix return values 90/78090/5 accepted/tizen/ivi/20160705.044816 accepted/tizen/mobile/20160705.044829 accepted/tizen/tv/20160705.044818 accepted/tizen/wearable/20160705.044803 submit/tizen/20160704.121419
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 4 Jul 2016 08:32:33 +0000 (17:32 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Mon, 4 Jul 2016 10:30:59 +0000 (19:30 +0900)
Change-Id: Icba6fa52baae1c7acf3b85ca54117db4f784cffe
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/rua_stat.c
src/rua_util.c
test/rua-test.c

index 33fdc1e..f6304f4 100755 (executable)
@@ -31,6 +31,7 @@
 
 #include "rua_stat_internal.h"
 #include "rua_stat.h"
+#include "rua_util.h"
 
 int rua_stat_update_for_uid(char *caller, char *tag, uid_t uid)
 {
index e52ab3d..9945147 100644 (file)
 #include "rua_util.h"
 
 #define DBPATH_LEN_MAX 4096
+#define ERR_BUF_MAX 1024
 
 char *_rua_util_get_db_path(uid_t uid, char *db_name)
 {
-       struct group *grpinfo = NULL;
-       char db_path[DBPATH_LEN_MAX] = {0, };
-       struct passwd *userinfo = getpwuid(uid);
-       if (userinfo == NULL) {
-               LOGE("getpwuid(%d) returns NULL !", uid);
-               return NULL;
-       }
-       grpinfo = getgrnam("users");
-       if (grpinfo == NULL) {
-               LOGE("getgrnam(users) returns NULL !");
-               return NULL;
-       }
+       char db_path[DBPATH_LEN_MAX];
+       char *db_path_prefix;
+       int ret;
 
-       if (grpinfo->gr_gid != userinfo->pw_gid) {
-               LOGE("UID [%d] does not belong to 'users' group!", uid);
-               return NULL;
-       }
-       snprintf(db_path, sizeof(db_path), "%s/.applications/dbspace/%s", userinfo->pw_dir, db_name);
+       tzplatform_set_user(uid);
+       db_path_prefix = tzplatform_getenv(TZ_USER_DB);
+       tzplatform_reset_user();
+
+       snprintf(db_path, sizeof(db_path), "%s/%s", db_path_prefix, db_name);
        LOGD("db path %s", db_path);
-       return db_path;
+
+       return strdup(db_path);
 }
 
 int _rua_util_open_db(sqlite3 **db, int flags, uid_t uid, char *db_name)
 {
        int r;
        char *db_path = _rua_util_get_db_path(uid, db_name);
+       if (db_path == NULL) {
+               LOGE("out of memory _rua_util_get_db_path fail");
+               return -1;
+       }
+
        r = db_util_open_with_options(db_path, db, flags, NULL);
        if (r) {
                LOGE("db util open error(%d/%d/%d/%s)", r,
                        sqlite3_errcode(*db),
                        sqlite3_extended_errcode(*db),
                        sqlite3_errmsg(*db));
+               free(db_path);
                return -1;
        }
+
+       free(db_path);
        return r;
 }
 
index 8d217b3..6a9c754 100644 (file)
@@ -87,6 +87,8 @@ static int __update_stat()
 static int __rua_stat_tag_iter_cb(const char *rua_stat_tag, void *data)
 {
        printf("rua_stat_tag : %s \n", rua_stat_tag);
+
+       return 0;
 }
 
 static int __get_stat_tags()