From: Jongkyu Koo Date: Thu, 8 Dec 2016 11:42:20 +0000 (+0900) Subject: change inotify file path for interfacing with system session X-Git-Tag: accepted/tizen/3.0/common/20161209.161230^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4d5d3e1bf8322a1a16f8c2862645e73940c60548;p=platform%2Fcore%2Fpim%2Fcontacts-service.git change inotify file path for interfacing with system session Change-Id: I47899e88b255eb5e547907b7b26542057dbf5486 Signed-off-by: Jongkyu Koo --- diff --git a/client/ctsvc_client_ipc.c b/client/ctsvc_client_ipc.c index c286a11..eee45d0 100644 --- a/client/ctsvc_client_ipc.c +++ b/client/ctsvc_client_ipc.c @@ -91,10 +91,12 @@ bool ctsvc_ipc_is_busy() static int _ctsvc_ipc_create(pims_ipc_h *p_ipc) { char sock_file[CTSVC_PATH_MAX_LEN] = {0}; - uid_t uid = 0; + uid_t uid = getuid(); - if (CONTACTS_ERROR_NONE != ctsvc_client_get_uid(&uid)) - return CONTACTS_ERROR_SYSTEM; + if (ctsvc_client_is_in_system_session()) { + if (CONTACTS_ERROR_NONE != ctsvc_client_get_active_uid(&uid)) + return CONTACTS_ERROR_SYSTEM; + } snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/.%s", uid, CTSVC_IPC_SERVICE); diff --git a/client/ctsvc_client_noti.c b/client/ctsvc_client_noti.c index d23b19b..c7a7bbd 100644 --- a/client/ctsvc_client_noti.c +++ b/client/ctsvc_client_noti.c @@ -122,10 +122,12 @@ int ctsvc_ipc_create_for_change_subscription() if (NULL == __ipc) { char sock_file[CTSVC_PATH_MAX_LEN] = {0}; - uid_t uid = 0; + uid_t uid = getuid(); - if (CONTACTS_ERROR_NONE != ctsvc_client_get_uid(&uid)) - return CONTACTS_ERROR_SYSTEM; + if (ctsvc_client_is_in_system_session()) { + if (CONTACTS_ERROR_NONE != ctsvc_client_get_active_uid(&uid)) + return CONTACTS_ERROR_SYSTEM; + } snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/.%s_for_subscribe", uid, CTSVC_IPC_SERVICE); @@ -155,10 +157,12 @@ int ctsvc_ipc_recover_for_change_subscription() pims_ipc_destroy_for_subscribe(__ipc); char sock_file[CTSVC_PATH_MAX_LEN] = {0}; - uid_t uid = 0; + uid_t uid = getuid(); - if (CONTACTS_ERROR_NONE != ctsvc_client_get_uid(&uid)) - return CONTACTS_ERROR_SYSTEM; + if (ctsvc_client_is_in_system_session()) { + if (CONTACTS_ERROR_NONE != ctsvc_client_get_active_uid(&uid)) + return CONTACTS_ERROR_SYSTEM; + } snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/.%s_for_subscribe", uid, CTSVC_IPC_SERVICE); diff --git a/client/ctsvc_client_utils.c b/client/ctsvc_client_utils.c index d065131..561adc8 100644 --- a/client/ctsvc_client_utils.c +++ b/client/ctsvc_client_utils.c @@ -37,37 +37,40 @@ inline unsigned int ctsvc_client_get_tid() return (unsigned int)syscall(SYS_gettid); } -int ctsvc_client_get_uid(uid_t *uid) +bool ctsvc_client_is_in_system_session() { - RETV_IF(NULL == uid, CONTACTS_ERROR_INVALID_PARAMETER); - int ret = 0; - uid_t *active_user_list = NULL; char *slice = NULL; - *uid = getuid(); ret = sd_pid_get_slice(getpid(), &slice); if (0 <= ret && slice) { if (STRING_EQUAL == strncmp(slice, CTSVC_SYSTEM_SLICE, strlen(CTSVC_SYSTEM_SLICE))) { - ret = sd_get_active_uids(&active_user_list); - /* the number of active users is 1 in tizen3.0 */ - if (1 == ret && active_user_list) { - *uid = active_user_list[0]; - INFO("uid = %d", *uid); - } else { - ERR("sd_get_active_uids() Fail(%d)", ret); - free(active_user_list); - free(slice); - return CONTACTS_ERROR_SYSTEM; - } - free(active_user_list); + free(slice); + return TRUE; } - free(slice); } else { ERR("sd_pid_get_slice() Fail(%d)", ret); } - INFO("getuid() = %d, uid = %d", getuid(), *uid); - return CONTACTS_ERROR_NONE; + free(slice); + return FALSE; } +int ctsvc_client_get_active_uid(uid_t *uid) +{ + int active_user_count = 0; + uid_t *active_user_list = NULL; + + active_user_count = sd_get_active_uids(&active_user_list); + /* the number of active users is 1 in tizen3.0 */ + if (1 == active_user_count && active_user_list) { + *uid = active_user_list[0]; + INFO("active uid = %d", *uid); + } else { + ERR("sd_get_active_uids() Fail(%d)", active_user_count); + free(active_user_list); + return CONTACTS_ERROR_SYSTEM; + } + + return CONTACTS_ERROR_NONE; +} diff --git a/client/ctsvc_client_utils.h b/client/ctsvc_client_utils.h index 28d9603..b8861f0 100644 --- a/client/ctsvc_client_utils.h +++ b/client/ctsvc_client_utils.h @@ -22,7 +22,8 @@ unsigned int ctsvc_client_get_pid(); unsigned int ctsvc_client_get_tid(); -int ctsvc_client_get_uid(uid_t *uid); +bool ctsvc_client_is_in_system_session(); +int ctsvc_client_get_active_uid(uid_t *uid); #endif /* __CTSVC_CLIENT_UTILS_H__ */ diff --git a/common/ctsvc_inotify.c b/common/ctsvc_inotify.c index 0d2dd31..9aa31d0 100644 --- a/common/ctsvc_inotify.c +++ b/common/ctsvc_inotify.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "contacts.h" @@ -27,11 +28,13 @@ #include "ctsvc_notify.h" #include "ctsvc_view.h" #include "ctsvc_handle.h" +#include "ctsvc_inotify.h" #include #ifdef _CONTACTS_IPC_CLIENT #include "ctsvc_client_ipc.h" +#include "ctsvc_client_utils.h" #endif typedef struct { @@ -202,78 +205,118 @@ static inline int __ctsvc_inotify_watch(int fd, const char *notipath) return CONTACTS_ERROR_NONE; } -static inline const char* __ctsvc_noti_get_file_path(const char *view_uri) +static int __ctsvc_noti_get_file_path(const char *view_uri, char **path) { ctsvc_record_type_e match = ctsvc_view_get_record_type(view_uri); + char *file = NULL; + switch ((int)match) { case CTSVC_RECORD_ADDRESSBOOK: - return CTSVC_NOTI_ADDRESSBOOK_CHANGED; + file = CTSVC_NOTI_ADDRESSBOOK_CHANGED; + break; case CTSVC_RECORD_GROUP: - return CTSVC_NOTI_GROUP_CHANGED; + file = CTSVC_NOTI_GROUP_CHANGED; + break; case CTSVC_RECORD_PERSON: - return CTSVC_NOTI_PERSON_CHANGED; + file = CTSVC_NOTI_PERSON_CHANGED; + break; case CTSVC_RECORD_CONTACT: case CTSVC_RECORD_SIMPLE_CONTACT: - return CTSVC_NOTI_CONTACT_CHANGED; + file = CTSVC_NOTI_CONTACT_CHANGED; + break; case CTSVC_RECORD_MY_PROFILE: - return CTSVC_NOTI_MY_PROFILE_CHANGED; + file = CTSVC_NOTI_MY_PROFILE_CHANGED; + break; case CTSVC_RECORD_NAME: - return CTSVC_NOTI_NAME_CHANGED; + file = CTSVC_NOTI_NAME_CHANGED; + break; case CTSVC_RECORD_COMPANY: - return CTSVC_NOTI_COMPANY_CHANGED; + file = CTSVC_NOTI_COMPANY_CHANGED; + break; case CTSVC_RECORD_NOTE: - return CTSVC_NOTI_NOTE_CHANGED; + file = CTSVC_NOTI_NOTE_CHANGED; + break; case CTSVC_RECORD_NUMBER: - return CTSVC_NOTI_NUMBER_CHANGED; + file = CTSVC_NOTI_NUMBER_CHANGED; + break; case CTSVC_RECORD_EMAIL: - return CTSVC_NOTI_EMAIL_CHANGED; + file = CTSVC_NOTI_EMAIL_CHANGED; + break; case CTSVC_RECORD_URL: - return CTSVC_NOTI_URL_CHANGED; + file = CTSVC_NOTI_URL_CHANGED; + break; case CTSVC_RECORD_EVENT: - return CTSVC_NOTI_EVENT_CHANGED; + file = CTSVC_NOTI_EVENT_CHANGED; + break; case CTSVC_RECORD_NICKNAME: - return CTSVC_NOTI_NICKNAME_CHANGED; + file = CTSVC_NOTI_NICKNAME_CHANGED; + break; case CTSVC_RECORD_ADDRESS: - return CTSVC_NOTI_ADDRESS_CHANGED; + file = CTSVC_NOTI_ADDRESS_CHANGED; + break; case CTSVC_RECORD_MESSENGER: - return CTSVC_NOTI_MESSENGER_CHANGED; + file = CTSVC_NOTI_MESSENGER_CHANGED; + break; case CTSVC_RECORD_GROUP_RELATION: - return CTSVC_NOTI_GROUP_RELATION_CHANGED; + file = CTSVC_NOTI_GROUP_RELATION_CHANGED; + break; case CTSVC_RECORD_ACTIVITY: - return CTSVC_NOTI_ACTIVITY_CHANGED; + file = CTSVC_NOTI_ACTIVITY_CHANGED; + break; case CTSVC_RECORD_ACTIVITY_PHOTO: - return CTSVC_NOTI_ACTIVITY_PHOTO_CHANGED; + file = CTSVC_NOTI_ACTIVITY_PHOTO_CHANGED; + break; case CTSVC_RECORD_PROFILE: - return CTSVC_NOTI_PROFILE_CHANGED; + file = CTSVC_NOTI_PROFILE_CHANGED; + break; case CTSVC_RECORD_RELATIONSHIP: - return CTSVC_NOTI_RELATIONSHIP_CHANGED; + file = CTSVC_NOTI_RELATIONSHIP_CHANGED; + break; case CTSVC_RECORD_IMAGE: - return CTSVC_NOTI_IMAGE_CHANGED; + file = CTSVC_NOTI_IMAGE_CHANGED; + break; case CTSVC_RECORD_EXTENSION: - return CTSVC_NOTI_DATA_CHANGED; + file = CTSVC_NOTI_DATA_CHANGED; + break; case CTSVC_RECORD_PHONELOG: - return CTSVC_NOTI_PHONELOG_CHANGED; + file = CTSVC_NOTI_PHONELOG_CHANGED; + break; case CTSVC_RECORD_SPEEDDIAL: - return CTSVC_NOTI_SPEEDDIAL_CHANGED; + file = CTSVC_NOTI_SPEEDDIAL_CHANGED; + break; case CTSVC_RECORD_SDN: - return CTSVC_NOTI_SDN_CHANGED; + file = CTSVC_NOTI_SDN_CHANGED; + break; case CTSVC_RECORD_SIP: - return CTSVC_NOTI_SIP_CHANGED; + file = CTSVC_NOTI_SIP_CHANGED; + break; case CTSVC_RECORD_RESULT: default: /* LCOV_EXCL_START */ ERR("The type(%s) is not supported", view_uri); - return NULL; + return CONTACTS_ERROR_INVALID_PARAMETER; /* LCOV_EXCL_STOP */ } - return NULL; + + *path = ctsvc_inotify_makepath(file); + if (NULL == *path) { + ERR("ctsvc_inotify_makepath() fail"); + return CONTACTS_ERROR_SYSTEM; + } + + return CONTACTS_ERROR_NONE; } int ctsvc_inotify_subscribe_ipc_ready(void (*cb)(void *), void *user_data) { - const char *noti_path = CTSVC_NOTI_IPC_READY; + char *noti_path = ctsvc_inotify_makepath(CTSVC_NOTI_IPC_READY); struct socket_init_noti_info *noti_info = NULL; + if (NULL == noti_path) { + ERR("ctsvc_inotify_makepath() fail"); + return CONTACTS_ERROR_SYSTEM; + } + if (NULL == _ctsvc_socket_init_noti_table) _ctsvc_socket_init_noti_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); else @@ -284,6 +327,7 @@ int ctsvc_inotify_subscribe_ipc_ready(void (*cb)(void *), void *user_data) if (-1 == wd) { /* LCOV_EXCL_START */ ERR("__ctsvc_inotify_get_wd() Fail(noti_path=%s, errno : %d)", noti_path, errno); + free(noti_path); if (errno == EACCES) return CONTACTS_ERROR_PERMISSION_DENIED; return CONTACTS_ERROR_SYSTEM; @@ -294,6 +338,7 @@ int ctsvc_inotify_subscribe_ipc_ready(void (*cb)(void *), void *user_data) if (CONTACTS_ERROR_NONE != ret) { /* LCOV_EXCL_START */ ERR("__ctsvc_inotify_watch() Fail"); + free(noti_path); return ret; /* LCOV_EXCL_STOP */ } @@ -302,6 +347,7 @@ int ctsvc_inotify_subscribe_ipc_ready(void (*cb)(void *), void *user_data) if (NULL == noti_info) { /* LCOV_EXCL_START */ ERR("calloc() return NULL"); + free(noti_path); return ret; /* LCOV_EXCL_STOP */ } @@ -309,7 +355,7 @@ int ctsvc_inotify_subscribe_ipc_ready(void (*cb)(void *), void *user_data) noti_info->wd = wd; noti_info->cb = cb; noti_info->cb_data = user_data; - g_hash_table_insert(_ctsvc_socket_init_noti_table, strdup(noti_path), noti_info); + g_hash_table_insert(_ctsvc_socket_init_noti_table, noti_path, noti_info); } noti_info->subscribe_count++; return CONTACTS_ERROR_NONE; @@ -317,15 +363,21 @@ int ctsvc_inotify_subscribe_ipc_ready(void (*cb)(void *), void *user_data) int ctsvc_inotify_unsubscribe_ipc_ready() { - const char *noti_path = CTSVC_NOTI_IPC_READY; + RETV_IF(NULL == _ctsvc_socket_init_noti_table, CONTACTS_ERROR_INVALID_PARAMETER); + + char *noti_path = ctsvc_inotify_makepath(CTSVC_NOTI_IPC_READY); struct socket_init_noti_info *noti_info = NULL; - RETV_IF(NULL == _ctsvc_socket_init_noti_table, CONTACTS_ERROR_INVALID_PARAMETER); + if (NULL == noti_path) { + ERR("ctsvc_inotify_makepath() fail"); + return CONTACTS_ERROR_SYSTEM; + } noti_info = g_hash_table_lookup(_ctsvc_socket_init_noti_table, noti_path); if (NULL == noti_info) { /* LCOV_EXCL_START */ ERR("g_hash_table_lookup() return NULL"); + free(noti_path); return CONTACTS_ERROR_INVALID_PARAMETER; /* LCOV_EXCL_STOP */ } @@ -339,29 +391,33 @@ int ctsvc_inotify_unsubscribe_ipc_ready() noti_info->subscribe_count--; } + free(noti_path); return CONTACTS_ERROR_NONE; } -int ctsvc_inotify_subscribe(const char *view_uri, void *cb, void *data) +int ctsvc_inotify_subscribe(const char *view_uri, contacts_db_changed_cb cb, void *data) { int ret, wd; noti_info *noti, *same_noti = NULL; GSList *it; - const char *path; + char *path = NULL; RETV_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER); RETVM_IF(__inoti_fd < 0, CONTACTS_ERROR_SYSTEM, "__inoti_fd(%d) is invalid", __inoti_fd); - path = __ctsvc_noti_get_file_path(view_uri); - RETVM_IF(NULL == path, CONTACTS_ERROR_INVALID_PARAMETER, - "__ctsvc_noti_get_file_path(%s) Fail", view_uri); + ret = __ctsvc_noti_get_file_path(view_uri, &path); + if (CONTACTS_ERROR_NONE != ret) { + ERR("__ctsvc_noti_get_file_path() fail(%d)", ret); + return ret; + } wd = __ctsvc_inotify_get_wd(__inoti_fd, path); if (-1 == wd) { /* LCOV_EXCL_START */ ERR("__ctsvc_inotify_get_wd() Fail(errno : %d)", errno); + free(path); if (errno == EACCES) return CONTACTS_ERROR_PERMISSION_DENIED; return CONTACTS_ERROR_SYSTEM; @@ -385,11 +441,13 @@ int ctsvc_inotify_subscribe(const char *view_uri, void *cb, void *data) __ctsvc_inotify_watch(__inoti_fd, path); /* LCOV_EXCL_START */ ERR("The same callback(%s) is already exist", view_uri); + free(path); return CONTACTS_ERROR_INVALID_PARAMETER; /* LCOV_EXCL_STOP */ } ret = __ctsvc_inotify_watch(__inoti_fd, path); + free(path); RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "__ctsvc_inotify_watch() Fail"); noti = calloc(1, sizeof(noti_info)); @@ -439,23 +497,26 @@ static inline int __ctsvc_del_noti(GSList **noti_list, int wd, const char *view_ return remain_cnt; } -int ctsvc_inotify_unsubscribe(const char *view_uri, void *cb, void *user_data) +int ctsvc_inotify_unsubscribe(const char *view_uri, contacts_db_changed_cb cb, void *user_data) { int ret, wd; - const char *path; + char *path = NULL; RETV_IF(NULL == cb, CONTACTS_ERROR_INVALID_PARAMETER); RETVM_IF(__inoti_fd < 0, CONTACTS_ERROR_SYSTEM, "System : __inoti_fd(%d) is invalid", __inoti_fd); - path = __ctsvc_noti_get_file_path(view_uri); - RETVM_IF(NULL == path, CONTACTS_ERROR_INVALID_PARAMETER, - "__ctsvc_noti_get_file_path(%s) Fail", view_uri); + ret = __ctsvc_noti_get_file_path(view_uri, &path); + if (CONTACTS_ERROR_NONE != ret) { + ERR("__ctsvc_noti_get_file_path() fail(%d)", ret); + return ret; + } wd = __ctsvc_inotify_get_wd(__inoti_fd, path); if (-1 == wd) { /* LCOV_EXCL_START */ ERR("__ctsvc_inotify_get_wd() Fail(errno : %d)", errno); + free(path); if (errno == EACCES) return CONTACTS_ERROR_PERMISSION_DENIED; return CONTACTS_ERROR_SYSTEM; @@ -465,10 +526,14 @@ int ctsvc_inotify_unsubscribe(const char *view_uri, void *cb, void *user_data) ret = __ctsvc_del_noti(&__noti_list, wd, view_uri, cb, user_data); WARN_IF(ret < CONTACTS_ERROR_NONE, "__ctsvc_del_noti() Fail(%d)", ret); - if (0 == ret) + if (0 == ret) { + free(path); return inotify_rm_watch(__inoti_fd, wd); + } - return __ctsvc_inotify_watch(__inoti_fd, path); + ret = __ctsvc_inotify_watch(__inoti_fd, path); + free(path); + return ret; } static void __clear_nslot_list(gpointer data, gpointer user_data) @@ -514,3 +579,48 @@ 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 pwd.pw_name; +} + +char* ctsvc_inotify_makepath(const char *file) +{ + RETV_IF(NULL == file, NULL); + + 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()) { + if (CONTACTS_ERROR_NONE != ctsvc_client_get_active_uid(&uid)) + return NULL; + } +#endif + + 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; + } + + user_name = __ctsvc_inotify_get_username(uid); + snprintf(path, path_len, CTSVC_NOTI_PATH"/%s", user_name, file); + DBG("%s", path); + return path; +} + diff --git a/common/ctsvc_inotify.h b/common/ctsvc_inotify.h index c4d0b32..fca7543 100644 --- a/common/ctsvc_inotify.h +++ b/common/ctsvc_inotify.h @@ -28,5 +28,6 @@ int ctsvc_inotify_unsubscribe(const char *view_uri, contacts_db_changed_cb cb, v int ctsvc_inotify_subscribe_ipc_ready(void (*cb)(void *), void *user_data); int ctsvc_inotify_unsubscribe_ipc_ready(); +char* ctsvc_inotify_makepath(const char *file); #endif /* __CTSVC_INOTIFY_H__ */ diff --git a/common/ctsvc_notify.h b/common/ctsvc_notify.h index 9422820..ac83573 100644 --- a/common/ctsvc_notify.h +++ b/common/ctsvc_notify.h @@ -24,40 +24,41 @@ #define CTSVC_VCARD_IMAGE_LOCATION tzplatform_mkpath(TZ_USER_SHARE, "vcard") #define DATA_REPERTORY tzplatform_getenv(TZ_USER_DATA) -#define CTSVC_NOTI_REPERTORY tzplatform_mkpath(TZ_USER_DATA, "contacts-svc") -#define CTSVC_NOTI_IMG_REPERTORY tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/img/") +#define CTSVC_DATA_REPERTORY tzplatform_mkpath(TZ_USER_DATA, "contacts-svc") +#define CTSVC_IMG_REPERTORY tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/img/") #define CTS_MY_IMAGE_LOCATION tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/img/my") #define CTS_GROUP_IMAGE_LOCATION tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/img/group") #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_IPC_READY tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_IPC_READY") -#define CTSVC_NOTI_ADDRESSBOOK_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_AB_CHANGED") -#define CTSVC_NOTI_GROUP_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_GROUP_CHANGED") -#define CTSVC_NOTI_PERSON_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_PERSON_CHANGED") -#define CTSVC_NOTI_CONTACT_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_DB_CHANGED") -#define CTSVC_NOTI_MY_PROFILE_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_MY_PROFILE_CHANGED") -#define CTSVC_NOTI_NAME_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_NAME_CHANGED") -#define CTSVC_NOTI_NUMBER_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_NUMBER_CHANGED") -#define CTSVC_NOTI_EMAIL_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_EMAIL_CHANGED") -#define CTSVC_NOTI_EVENT_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_EVENT_CHANGED") -#define CTSVC_NOTI_URL_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_URL_CHANGED") -#define CTSVC_NOTI_GROUP_RELATION_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_GROUP_RELATION_CHANGED") -#define CTSVC_NOTI_ADDRESS_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_ADDRESS_CHANGED") -#define CTSVC_NOTI_NOTE_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_NOTE_CHANGED") -#define CTSVC_NOTI_COMPANY_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_COMPANY_CHANGED") -#define CTSVC_NOTI_RELATIONSHIP_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_RELATIONSHIP_CHANGED") -#define CTSVC_NOTI_IMAGE_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_IMAGE_CHANGED") -#define CTSVC_NOTI_NICKNAME_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_NICKNAME_CHANGED") -#define CTSVC_NOTI_MESSENGER_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_MESSENGER_CHANGED") -#define CTSVC_NOTI_DATA_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_DATA_CHANGED") -#define CTSVC_NOTI_SDN_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_SDN_CHANGED") -#define CTSVC_NOTI_PROFILE_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_PROFILE_CHANGED") -#define CTSVC_NOTI_ACTIVITY_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_ACTIVITY_CHANGED") -#define CTSVC_NOTI_ACTIVITY_PHOTO_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_ACTIVITY_PHOTO_CHANGED") -#define CTSVC_NOTI_PHONELOG_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_PLOG_CHANGED") -#define CTSVC_NOTI_SPEEDDIAL_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_SPEED_CHANGED") -#define CTSVC_NOTI_SIP_CHANGED tzplatform_mkpath(TZ_USER_DATA, "contacts-svc/.CONTACTS_SVC_SIP_CHANGED") +#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" +#define CTSVC_NOTI_PERSON_CHANGED ".CONTACTS_SVC_PERSON_CHANGED" +#define CTSVC_NOTI_CONTACT_CHANGED ".CONTACTS_SVC_DB_CHANGED" +#define CTSVC_NOTI_MY_PROFILE_CHANGED ".CONTACTS_SVC_MY_PROFILE_CHANGED" +#define CTSVC_NOTI_NAME_CHANGED ".CONTACTS_SVC_NAME_CHANGED" +#define CTSVC_NOTI_NUMBER_CHANGED ".CONTACTS_SVC_NUMBER_CHANGED" +#define CTSVC_NOTI_EMAIL_CHANGED ".CONTACTS_SVC_EMAIL_CHANGED" +#define CTSVC_NOTI_EVENT_CHANGED ".CONTACTS_SVC_EVENT_CHANGED" +#define CTSVC_NOTI_URL_CHANGED ".CONTACTS_SVC_URL_CHANGED" +#define CTSVC_NOTI_GROUP_RELATION_CHANGED ".CONTACTS_SVC_GROUP_RELATION_CHANGED" +#define CTSVC_NOTI_ADDRESS_CHANGED ".CONTACTS_SVC_ADDRESS_CHANGED" +#define CTSVC_NOTI_NOTE_CHANGED ".CONTACTS_SVC_NOTE_CHANGED" +#define CTSVC_NOTI_COMPANY_CHANGED ".CONTACTS_SVC_COMPANY_CHANGED" +#define CTSVC_NOTI_RELATIONSHIP_CHANGED ".CONTACTS_SVC_RELATIONSHIP_CHANGED" +#define CTSVC_NOTI_IMAGE_CHANGED ".CONTACTS_SVC_IMAGE_CHANGED" +#define CTSVC_NOTI_NICKNAME_CHANGED ".CONTACTS_SVC_NICKNAME_CHANGED" +#define CTSVC_NOTI_MESSENGER_CHANGED ".CONTACTS_SVC_MESSENGER_CHANGED" +#define CTSVC_NOTI_DATA_CHANGED ".CONTACTS_SVC_DATA_CHANGED" +#define CTSVC_NOTI_SDN_CHANGED ".CONTACTS_SVC_SDN_CHANGED" +#define CTSVC_NOTI_PROFILE_CHANGED ".CONTACTS_SVC_PROFILE_CHANGED" +#define CTSVC_NOTI_ACTIVITY_CHANGED ".CONTACTS_SVC_ACTIVITY_CHANGED" +#define CTSVC_NOTI_ACTIVITY_PHOTO_CHANGED ".CONTACTS_SVC_ACTIVITY_PHOTO_CHANGED" +#define CTSVC_NOTI_PHONELOG_CHANGED ".CONTACTS_SVC_PLOG_CHANGED" +#define CTSVC_NOTI_SPEEDDIAL_CHANGED ".CONTACTS_SVC_SPEED_CHANGED" +#define CTSVC_NOTI_SIP_CHANGED ".CONTACTS_SVC_SIP_CHANGED" #define CTSVC_SETTING_DISPLAY_ORDER_CHANGED "contacts.setting.display_order" #define CTSVC_SETTING_SORTING_ORDER_CHANGED "contacts.setting.sorting_order" diff --git a/common/ctsvc_socket.c b/common/ctsvc_socket.c index 593adbe..201439f 100644 --- a/common/ctsvc_socket.c +++ b/common/ctsvc_socket.c @@ -36,6 +36,7 @@ int ctsvc_socket_init(void) { int ret; struct sockaddr_un caddr; + uid_t uid = getuid(); if (0 < __ctsvc_conn_refcnt) { __ctsvc_conn_refcnt++; @@ -43,16 +44,16 @@ int ctsvc_socket_init(void) } char sock_file[CTSVC_PATH_MAX_LEN] = {0}; -#ifdef _CONTACTS_IPC_CLIENT - uid_t uid = 0; - if (CONTACTS_ERROR_NONE != ctsvc_client_get_uid(&uid)) - return CONTACTS_ERROR_SYSTEM; +#ifdef _CONTACTS_IPC_CLIENT + if (ctsvc_client_is_in_system_session()) { + if (CONTACTS_ERROR_NONE != ctsvc_client_get_active_uid(&uid)) + return CONTACTS_ERROR_SYSTEM; + } +#endif snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/%s", uid, CTSVC_SOCKET_FILE); -#else - snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/%s", getuid(), CTSVC_SOCKET_FILE); -#endif + bzero(&caddr, sizeof(caddr)); caddr.sun_family = AF_UNIX; snprintf(caddr.sun_path, sizeof(caddr.sun_path), "%s", sock_file); diff --git a/packaging/contacts-service.spec b/packaging/contacts-service.spec index c39b34e..23785af 100644 --- a/packaging/contacts-service.spec +++ b/packaging/contacts-service.spec @@ -1,6 +1,6 @@ Name: contacts-service Summary: Contacts Service -Version: 0.13.61 +Version: 0.13.62 Release: 0 Group: Social & Content/Service License: Apache-2.0 diff --git a/server/ctsvc_notification.c b/server/ctsvc_notification.c index 399d6aa..bd0f529 100644 --- a/server/ctsvc_notification.c +++ b/server/ctsvc_notification.c @@ -24,6 +24,7 @@ #include "contacts_db_status.h" #include "ctsvc_internal.h" #include "ctsvc_notify.h" +#include "ctsvc_inotify.h" #include "ctsvc_notification.h" static TLS bool contact_change = false; @@ -55,16 +56,27 @@ static TLS bool sip_change = false; void ctsvc_noti_publish_socket_initialize(void) { - int fd = open(CTSVC_NOTI_IPC_READY, O_TRUNC | O_RDWR); - + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_IPC_READY); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) close(fd); } static inline void __ctsvc_noti_publish_contact_change(void) { - int fd = open(CTSVC_NOTI_CONTACT_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_CONTACT_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); contact_change = false; @@ -73,7 +85,14 @@ static inline void __ctsvc_noti_publish_contact_change(void) static inline void __ctsvc_noti_publish_my_profile_change(void) { - int fd = open(CTSVC_NOTI_MY_PROFILE_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_MY_PROFILE_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); my_profile_change = false; @@ -82,7 +101,14 @@ static inline void __ctsvc_noti_publish_my_profile_change(void) static inline void __ctsvc_noti_publish_phonelog_change(void) { - int fd = open(CTSVC_NOTI_PHONELOG_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_PHONELOG_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); phonelog_change = false; @@ -91,7 +117,14 @@ static inline void __ctsvc_noti_publish_phonelog_change(void) static inline void __ctsvc_noti_publish_speed_change(void) { - int fd = open(CTSVC_NOTI_SPEEDDIAL_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_SPEEDDIAL_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); speed_change = false; @@ -100,7 +133,14 @@ static inline void __ctsvc_noti_publish_speed_change(void) static inline void __ctsvc_noti_publish_addressbook_change(void) { - int fd = open(CTSVC_NOTI_ADDRESSBOOK_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_ADDRESSBOOK_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); addressbook_change = false; @@ -109,7 +149,14 @@ static inline void __ctsvc_noti_publish_addressbook_change(void) static inline void __ctsvc_noti_publish_group_change(void) { - int fd = open(CTSVC_NOTI_GROUP_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_GROUP_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); group_change = false; @@ -118,7 +165,14 @@ static inline void __ctsvc_noti_publish_group_change(void) static inline void __ctsvc_noti_publish_group_rel_change(void) { - int fd = open(CTSVC_NOTI_GROUP_RELATION_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_GROUP_RELATION_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); group_rel_change = false; @@ -127,7 +181,14 @@ static inline void __ctsvc_noti_publish_group_rel_change(void) static inline void __ctsvc_noti_publish_person_change(void) { - int fd = open(CTSVC_NOTI_PERSON_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_PERSON_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); person_change = false; @@ -136,7 +197,14 @@ static inline void __ctsvc_noti_publish_person_change(void) static inline void __ctsvc_noti_publish_name_change(void) { - int fd = open(CTSVC_NOTI_NAME_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_NAME_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); name_change = false; @@ -145,7 +213,14 @@ static inline void __ctsvc_noti_publish_name_change(void) static inline void __ctsvc_noti_publish_number_change(void) { - int fd = open(CTSVC_NOTI_NUMBER_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_NUMBER_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); number_change = false; @@ -154,7 +229,14 @@ static inline void __ctsvc_noti_publish_number_change(void) static inline void __ctsvc_noti_publish_email_change(void) { - int fd = open(CTSVC_NOTI_EMAIL_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_EMAIL_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); email_change = false; @@ -163,7 +245,14 @@ static inline void __ctsvc_noti_publish_email_change(void) static inline void __ctsvc_noti_publish_event_change(void) { - int fd = open(CTSVC_NOTI_EVENT_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_EVENT_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); event_change = false; @@ -172,7 +261,14 @@ static inline void __ctsvc_noti_publish_event_change(void) static inline void __ctsvc_noti_publish_url_change(void) { - int fd = open(CTSVC_NOTI_URL_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_URL_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); url_change = false; @@ -181,7 +277,14 @@ static inline void __ctsvc_noti_publish_url_change(void) static inline void __ctsvc_noti_publish_address_change(void) { - int fd = open(CTSVC_NOTI_ADDRESS_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_ADDRESS_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); address_change = false; @@ -190,7 +293,14 @@ static inline void __ctsvc_noti_publish_address_change(void) static inline void __ctsvc_noti_publish_note_change(void) { - int fd = open(CTSVC_NOTI_NOTE_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_NOTE_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); note_change = false; @@ -199,7 +309,14 @@ static inline void __ctsvc_noti_publish_note_change(void) static inline void __ctsvc_noti_publish_company_change(void) { - int fd = open(CTSVC_NOTI_COMPANY_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_COMPANY_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); company_change = false; @@ -208,7 +325,14 @@ static inline void __ctsvc_noti_publish_company_change(void) static inline void __ctsvc_noti_publish_relationship_change(void) { - int fd = open(CTSVC_NOTI_RELATIONSHIP_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_RELATIONSHIP_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); relationship_change = false; @@ -217,7 +341,14 @@ static inline void __ctsvc_noti_publish_relationship_change(void) static inline void __ctsvc_noti_publish_image_change(void) { - int fd = open(CTSVC_NOTI_IMAGE_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_IMAGE_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); image_change = false; @@ -226,7 +357,14 @@ static inline void __ctsvc_noti_publish_image_change(void) static inline void __ctsvc_noti_publish_nickname_change(void) { - int fd = open(CTSVC_NOTI_NICKNAME_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_NICKNAME_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); nickname_change = false; @@ -235,7 +373,14 @@ static inline void __ctsvc_noti_publish_nickname_change(void) static inline void __ctsvc_noti_publish_messenger_change(void) { - int fd = open(CTSVC_NOTI_MESSENGER_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_MESSENGER_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); messenger_change = false; @@ -244,7 +389,14 @@ static inline void __ctsvc_noti_publish_messenger_change(void) static inline void __ctsvc_noti_publish_data_change(void) { - int fd = open(CTSVC_NOTI_DATA_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_DATA_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); data_change = false; @@ -253,7 +405,14 @@ static inline void __ctsvc_noti_publish_data_change(void) static inline void __ctsvc_noti_publish_sdn_change(void) { - int fd = open(CTSVC_NOTI_SDN_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_SDN_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); sdn_change = false; @@ -262,7 +421,14 @@ static inline void __ctsvc_noti_publish_sdn_change(void) static inline void __ctsvc_noti_publish_profile_change(void) { - int fd = open(CTSVC_NOTI_PROFILE_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_PROFILE_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); profile_change = false; @@ -271,7 +437,14 @@ static inline void __ctsvc_noti_publish_profile_change(void) static inline void __ctsvc_noti_publish_activity_change(void) { - int fd = open(CTSVC_NOTI_ACTIVITY_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_ACTIVITY_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); activity_change = false; @@ -280,7 +453,14 @@ static inline void __ctsvc_noti_publish_activity_change(void) static inline void __ctsvc_noti_publish_activity_photo_change(void) { - int fd = open(CTSVC_NOTI_ACTIVITY_PHOTO_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_ACTIVITY_PHOTO_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); activity_photo_change = false; @@ -289,7 +469,14 @@ static inline void __ctsvc_noti_publish_activity_photo_change(void) static inline void __ctsvc_noti_publish_sip_change(void) { - int fd = open(CTSVC_NOTI_SIP_CHANGED, O_TRUNC | O_RDWR); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_SIP_CHANGED); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + + int fd = open(path, O_TRUNC | O_RDWR); + free(path); if (0 <= fd) { close(fd); sip_change = false; diff --git a/server/ctsvc_server.c b/server/ctsvc_server.c index d180af2..1fe2d14 100644 --- a/server/ctsvc_server.c +++ b/server/ctsvc_server.c @@ -43,6 +43,7 @@ #include "ctsvc_ipc_server.h" #include "ctsvc_ipc_server2.h" #include "ctsvc_notify.h" +#include "ctsvc_inotify.h" #define CTSVC_TIMEOUT_FOR_DEFAULT 0 @@ -291,19 +292,38 @@ int ctsvc_server_get_timeout_sec(void) return ctsvc_timeout_sec; } -void ctsvc_create_file_set_permission(const char *file, mode_t mode) +void __ctsvc_create_rep_set_permission(const char *directory, mode_t mode) +{ + if (-1 == access(directory, F_OK)) + mkdir(directory, mode); +} + +void __ctsvc_create_noti_file_set_permission(const char *file, mode_t mode) { int fd; - fd = creat(file, mode); - if (0 <= fd) + char* path = ctsvc_inotify_makepath(file); + if (NULL == path) { + ERR("ctsvc_inotify_makepath() fail"); + return; + } + fd = creat(path, mode); + if (0 <= fd) { close(fd); + chmod(path, 0644); + } + free(path); } -void ctsvc_create_rep_set_permission(const char *directory, mode_t mode) +/* +void __ctsvc_create_noti_rep_set_permission(mode_t mode) { - if (-1 == access(directory, F_OK)) - mkdir(directory, 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[]) { @@ -323,42 +343,43 @@ int main(int argc, char *argv[]) ctsvc_server_check_schema(); - ctsvc_create_rep_set_permission(DATA_REPERTORY, 0755); - ctsvc_create_rep_set_permission(CTSVC_NOTI_REPERTORY, 0775); - ctsvc_create_rep_set_permission(CTSVC_NOTI_IMG_REPERTORY, 0750); - ctsvc_create_rep_set_permission(CTSVC_VCARD_IMAGE_LOCATION, 0770); - ctsvc_create_rep_set_permission(CTS_MY_IMAGE_LOCATION, 0750); - ctsvc_create_rep_set_permission(CTS_GROUP_IMAGE_LOCATION, 0750); - ctsvc_create_rep_set_permission(CTS_LOGO_IMAGE_LOCATION, 0750); - ctsvc_create_rep_set_permission(CTSVC_CONTACT_IMG_FULL_LOCATION, 0750); - - ctsvc_create_file_set_permission(CTSVC_NOTI_IPC_READY, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_ADDRESSBOOK_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_GROUP_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_PERSON_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_CONTACT_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_MY_PROFILE_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_NAME_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_NUMBER_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_EMAIL_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_EVENT_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_URL_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_GROUP_RELATION_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_ADDRESS_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_NOTE_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_COMPANY_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_RELATIONSHIP_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_IMAGE_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_NICKNAME_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_MESSENGER_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_DATA_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_SDN_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_PROFILE_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_ACTIVITY_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_ACTIVITY_PHOTO_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_PHONELOG_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_SPEEDDIAL_CHANGED, 0660); - ctsvc_create_file_set_permission(CTSVC_NOTI_SIP_CHANGED, 0660); + __ctsvc_create_rep_set_permission(DATA_REPERTORY, 0755); + __ctsvc_create_rep_set_permission(CTSVC_DATA_REPERTORY, 0775); + __ctsvc_create_rep_set_permission(CTSVC_IMG_REPERTORY, 0750); + __ctsvc_create_rep_set_permission(CTSVC_VCARD_IMAGE_LOCATION, 0770); + __ctsvc_create_rep_set_permission(CTS_MY_IMAGE_LOCATION, 0750); + __ctsvc_create_rep_set_permission(CTS_GROUP_IMAGE_LOCATION, 0750); + __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(0744); + __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); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_PERSON_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_CONTACT_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_MY_PROFILE_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_NAME_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_NUMBER_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_EMAIL_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_EVENT_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_URL_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_GROUP_RELATION_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_ADDRESS_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_NOTE_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_COMPANY_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_RELATIONSHIP_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_IMAGE_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_NICKNAME_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_MESSENGER_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_DATA_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_SDN_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_PROFILE_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_ACTIVITY_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_ACTIVITY_PHOTO_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_PHONELOG_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_SPEEDDIAL_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); + __ctsvc_create_noti_file_set_permission(CTSVC_NOTI_SIP_CHANGED, CTS_SECURITY_DEFAULT_PERMISSION); /* update DB for compatability */ ctsvc_server_db_update(); diff --git a/server/ctsvc_server_sqlite.c b/server/ctsvc_server_sqlite.c index f456762..089b166 100644 --- a/server/ctsvc_server_sqlite.c +++ b/server/ctsvc_server_sqlite.c @@ -26,6 +26,7 @@ #include "ctsvc_db_schema.h" #include "ctsvc_db_sqlite.h" #include "ctsvc_notify.h" +#include "ctsvc_inotify.h" #include "ctsvc_server_setting.h" #include "ctsvc_normalize.h" #include "ctsvc_localize.h" @@ -518,12 +519,25 @@ int ctsvc_server_update_collation() ret = ctsvc_server_end_trans(true); if (CONTACTS_ERROR_NONE == ret) { int fd; - fd = open(CTSVC_NOTI_CONTACT_CHANGED, O_TRUNC | O_RDWR); - if (0 <= fd) - close(fd); - fd = open(CTSVC_NOTI_PERSON_CHANGED, O_TRUNC | O_RDWR); - if (0 <= fd) - close(fd); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_CONTACT_CHANGED); + if (NULL != path) { + fd = open(path, O_TRUNC | O_RDWR); + if (0 <= fd) + close(fd); + } else { + ERR("ctsvc_inotify_makepath() fail"); + } + free(path); + + path = ctsvc_inotify_makepath(CTSVC_NOTI_PERSON_CHANGED); + if (NULL != path) { + fd = open(path, O_TRUNC | O_RDWR); + if (0 <= fd) + close(fd); + } else { + ERR("ctsvc_inotify_makepath() fail"); + } + free(path); } ctsvc_server_db_close(); @@ -846,12 +860,25 @@ DATA_FREE: ret = ctsvc_server_end_trans(true); if (CONTACTS_ERROR_NONE == ret) { int fd; - fd = open(CTSVC_NOTI_CONTACT_CHANGED, O_TRUNC | O_RDWR); - if (0 <= fd) - close(fd); - fd = open(CTSVC_NOTI_PERSON_CHANGED, O_TRUNC | O_RDWR); - if (0 <= fd) - close(fd); + char *path = ctsvc_inotify_makepath(CTSVC_NOTI_CONTACT_CHANGED); + if (NULL != path) { + fd = open(path, O_TRUNC | O_RDWR); + if (0 <= fd) + close(fd); + } else { + ERR("ctsvc_inotify_makepath() fail"); + } + free(path); + + path = ctsvc_inotify_makepath(CTSVC_NOTI_PERSON_CHANGED); + if (NULL != path) { + fd = open(path, O_TRUNC | O_RDWR); + if (0 <= fd) + close(fd); + } else { + ERR("ctsvc_inotify_makepath() fail"); + } + free(path); } } else { ctsvc_server_end_trans(false); diff --git a/server/db/ctsvc_db_utils.c b/server/db/ctsvc_db_utils.c index d116f6c..3e48723 100644 --- a/server/db/ctsvc_db_utils.c +++ b/server/db/ctsvc_db_utils.c @@ -220,7 +220,7 @@ static inline bool _ctsvc_check_available_image_space(int need_size) struct statfs buf; long long size; - ret = statfs(CTSVC_NOTI_IMG_REPERTORY, &buf); + ret = statfs(CTSVC_IMG_REPERTORY, &buf); RETVM_IF(ret != 0, false, "statfs() Fail(%d)", ret); size = (long long)buf.f_bavail * (buf.f_bsize);