From: Jongkyu Koo Date: Thu, 12 Jan 2017 07:48:22 +0000 (+0900) Subject: move inotify files to home/owner/data X-Git-Tag: accepted/tizen/common/20170113.183907^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=99231fb43291fc3f1d3ac381f2eb302431506382;p=platform%2Fcore%2Fpim%2Fcontacts-service.git move inotify files to home/owner/data Change-Id: I37e429f5def2bf086e725956fe128a064b55064c Signed-off-by: Jongkyu Koo (cherry picked from commit 8ee77213bddb02d1e480da8b49631b44f86b341a) --- diff --git a/common/ctsvc_inotify.c b/common/ctsvc_inotify.c index cca2ff6..4e05c36 100644 --- a/common/ctsvc_inotify.c +++ b/common/ctsvc_inotify.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "contacts.h" @@ -580,14 +581,31 @@ void ctsvc_inotify_close(void) } } +static const char* __ctsvc_inotify_get_username(uid_t uid) +{ + struct passwd pwd; + struct passwd *pwd_result; + char tmp[CTSVC_STR_SHORT_LEN]; + + int ret = getpwuid_r(uid, &pwd, tmp, sizeof(tmp), &pwd_result); + if (ret != 0 || pwd_result == NULL) { + ERR("getpwuid_r() fail"); + return ""; + } + + return SAFE_STRDUP(pwd.pw_name); +} + + char* ctsvc_inotify_makepath(const char *file) { RETV_IF(NULL == file, NULL); - static int user_id_max = 10; + static int user_name_max = 32; int path_len = 0; char *path = NULL; uid_t uid = getuid(); + const char *user_name = NULL; #ifdef _CONTACTS_IPC_CLIENT if (ctsvc_client_is_in_system_session()) { @@ -596,15 +614,23 @@ char* ctsvc_inotify_makepath(const char *file) } #endif - path_len = strlen(CTSVC_NOTI_PATH) + user_id_max + strlen(file) + 1; + path_len = strlen(CTSVC_NOTI_PATH) + user_name_max + strlen(file) + 1; path = calloc(1, path_len); if (NULL == path) { ERR("calloc() fail"); return NULL; } - snprintf(path, path_len, CTSVC_NOTI_PATH"/%s", uid, file); - DBG("%s", path); + user_name = __ctsvc_inotify_get_username(uid); + if (user_name) { + snprintf(path, path_len, CTSVC_NOTI_PATH"/%s", user_name, file); + } else { + ERR("__ctsvc_inotify_get_username() fail"); + free(path); + return NULL; + } + + free(user_name); return path; } diff --git a/common/ctsvc_notify.h b/common/ctsvc_notify.h index a14b9ba..ac83573 100644 --- a/common/ctsvc_notify.h +++ b/common/ctsvc_notify.h @@ -31,7 +31,7 @@ #define CTS_LOGO_IMAGE_LOCATION tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/img/logo") #define CTSVC_CONTACT_IMG_FULL_LOCATION tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/img/contact") -#define CTSVC_NOTI_PATH "/run/user_ext/%d/contacts-svc" +#define CTSVC_NOTI_PATH "/opt/usr/home/%s/data/contacts-svc" #define CTSVC_NOTI_IPC_READY ".CONTACTS_SVC_IPC_READY" #define CTSVC_NOTI_ADDRESSBOOK_CHANGED ".CONTACTS_SVC_AB_CHANGED" #define CTSVC_NOTI_GROUP_CHANGED ".CONTACTS_SVC_GROUP_CHANGED" diff --git a/packaging/contacts-service.spec b/packaging/contacts-service.spec index b9ea8cf..317a292 100644 --- a/packaging/contacts-service.spec +++ b/packaging/contacts-service.spec @@ -1,6 +1,6 @@ Name: contacts-service Summary: Contacts Service -Version: 0.13.69 +Version: 0.13.70 Release: 0 Group: Social & Content/Service License: Apache-2.0 diff --git a/server/ctsvc_server.c b/server/ctsvc_server.c index 6cbdec3..13fb495 100644 --- a/server/ctsvc_server.c +++ b/server/ctsvc_server.c @@ -314,22 +314,10 @@ void __ctsvc_create_noti_file_set_permission(const char *file, mode_t mode) free(path); } - -void __ctsvc_create_noti_rep_set_permission(mode_t mode) -{ - char path[CTSVC_PATH_MAX_LEN] = {0}; - snprintf(path, CTSVC_PATH_MAX_LEN, CTSVC_NOTI_PATH, getuid()); - - if (-1 == access(path, F_OK)) - mkdir(path, mode); -} - - int main(int argc, char *argv[]) { CTS_FN_CALL; INFO("Start contacts-service"); - setenv("GCOV_PREFIX", "/tmp/server", 1); int ret; if (getuid() == 0) { /* root */ @@ -352,7 +340,6 @@ int main(int argc, char *argv[]) __ctsvc_create_rep_set_permission(CTS_LOGO_IMAGE_LOCATION, 0750); __ctsvc_create_rep_set_permission(CTSVC_CONTACT_IMG_FULL_LOCATION, 0750); - __ctsvc_create_noti_rep_set_permission(0755); __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_IPC_READY, CTS_SECURITY_DEFAULT_PERMISSION); __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_ADDRESSBOOK_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_GROUP_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION);