Fix socket path for multi-user 17/38617/4 submit/tizen/20150429.040816
authorSunggoo Kim <sung.goo.kim@samsung.com>
Thu, 23 Apr 2015 06:40:09 +0000 (15:40 +0900)
committerSunggoo Kim <sung.goo.kim@samsung.com>
Thu, 23 Apr 2015 07:46:28 +0000 (16:46 +0900)
Change-Id: I5dfa8f78e4f1c5ea0864c6c953d8849f758c4f5a

client/ctsvc_client_ipc.c
common/ctsvc_socket.c
common/ctsvc_socket.h
common/ctsvc_struct.h
server/ctsvc_server.c
server/ctsvc_server_socket.c

index c411ec7..f75d56d 100644 (file)
@@ -47,7 +47,9 @@ int ctsvc_ipc_connect_on_thread(void)
 
        // ipc create
        if (__contacts_ipc == NULL) {
-               __contacts_ipc = pims_ipc_create(CTSVC_IPC_SOCKET_PATH);
+               char sock_file[CTSVC_PATH_MAX_LEN] = {0};
+               snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/.%s", getuid(), CTSVC_IPC_SERVICE);
+               __contacts_ipc = pims_ipc_create(sock_file);
                if (__contacts_ipc == NULL) {
                        if (errno == EACCES) {
                                CTS_ERR("pims_ipc_create() Failed(%d)", CONTACTS_ERROR_PERMISSION_DENIED);
@@ -162,7 +164,9 @@ int ctsvc_ipc_connect(void)
 
        // ipc create
        if (__contacts_global_ipc == NULL) {
-               __contacts_global_ipc = pims_ipc_create(CTSVC_IPC_SOCKET_PATH);
+               char sock_file[CTSVC_PATH_MAX_LEN] = {0};
+               snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/.%s", getuid(), CTSVC_IPC_SERVICE);
+               __contacts_global_ipc = pims_ipc_create(sock_file);
                if (__contacts_global_ipc == NULL) {
                        if (errno == EACCES) {
                                CTS_ERR("[GLOBAL_IPC_CHANNEL] pims_ipc_create() Failed(%d)", CONTACTS_ERROR_PERMISSION_DENIED);
index 53ecb81..ea369aa 100644 (file)
@@ -41,9 +41,12 @@ int ctsvc_socket_init(void)
                return  CONTACTS_ERROR_NONE;
        }
 
+       char sock_file[CTSVC_PATH_MAX_LEN] = {0};
+       snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/%s", getuid(), CTSVC_SOCKET_FILE);
+
        bzero(&caddr, sizeof(caddr));
        caddr.sun_family = AF_UNIX;
-       snprintf(caddr.sun_path, sizeof(caddr.sun_path), "%s", CTSVC_SOCKET_PATH);
+       snprintf(caddr.sun_path, sizeof(caddr.sun_path), "%s", sock_file);
 
        __ctsvc_sockfd = socket(PF_UNIX, SOCK_STREAM, 0);
        RETVM_IF(-1 == __ctsvc_sockfd, CONTACTS_ERROR_IPC,
index ad38a33..8318963 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "contacts.h"
 
-#define CTSVC_SOCKET_PATH "/tmp/.contacts-svc.sock"
+#define CTSVC_SOCKET_FILE ".contacts-svc.sock"
 #define CTSVC_SOCKET_MSG_SIZE 1024
 
 // for use current contacts-svc-helper daemon
index 20d5961..dc41d0c 100644 (file)
@@ -32,6 +32,9 @@
 
 #include "contacts_views.h"
 
+#define CTSVC_SOCK_PATH "/run/user/%d"
+#define CTSVC_PATH_MAX_LEN 1024
+
 #define CTSVC_IMG_FULL_PATH_SIZE_MAX 1024              // current max length file path is 256
 #define CTSVC_IMG_FULL_LOCATION tzplatform_mkpath(TZ_USER_DATA,"contacts-svc/img")
 #define CTSVC_CONTACT_IMG_FULL_LOCATION tzplatform_mkpath(TZ_USER_DATA,"contacts-svc/img/contact")
index fca5a75..b964575 100755 (executable)
 static int __server_main(void)
 {
        int ret;
-       pims_ipc_svc_init(CTSVC_IPC_SOCKET_PATH, CTS_SECURITY_FILE_GROUP, 0777);
+
+       char sock_file[CTSVC_PATH_MAX_LEN] = {0};
+       snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/.%s", getuid(), CTSVC_IPC_SERVICE);
+       pims_ipc_svc_init(sock_file, CTS_SECURITY_FILE_GROUP, 0777);
 
        do {
                // register handle functions
index 64d0e0f..f998fdb 100644 (file)
@@ -456,11 +456,13 @@ int ctsvc_server_socket_init(void)
        _ctsvc_server_initialize_cynara();
 #endif
 
-       unlink(CTSVC_SOCKET_PATH);
+       char sock_file[CTSVC_PATH_MAX_LEN] = {0};
+       snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/%s", getuid(), CTSVC_SOCKET_FILE);
+       unlink(sock_file);
 
        bzero(&addr, sizeof(addr));
        addr.sun_family = AF_UNIX;
-       snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", CTSVC_SOCKET_PATH);
+       snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", sock_file);
 
        sockfd = socket(PF_UNIX, SOCK_STREAM, 0);
        RETVM_IF(-1 == sockfd, CONTACTS_ERROR_SYSTEM, "socket() Failed(errno = %d)", errno);
@@ -468,13 +470,13 @@ int ctsvc_server_socket_init(void)
        ret = bind(sockfd, (struct sockaddr *)&addr, sizeof(addr));
        RETVM_IF(-1 == ret, CONTACTS_ERROR_SYSTEM, "bind() Failed(errno = %d)", errno);
 
-       ret = chown(CTSVC_SOCKET_PATH, getuid(), CTS_SECURITY_FILE_GROUP);
+       ret = chown(sock_file, getuid(), CTS_SECURITY_FILE_GROUP);
        if (0 != ret)
-               CTS_ERR("chown(%s) Failed(%d)", CTSVC_SOCKET_PATH, ret);
+               CTS_ERR("chown(%s) Failed(%d)", sock_file, ret);
 
-       ret = chmod(CTSVC_SOCKET_PATH, CTS_SECURITY_DEFAULT_PERMISSION);
+       ret = chmod(sock_file, CTS_SECURITY_DEFAULT_PERMISSION);
        if (0 != ret)
-               CTS_ERR("chmod(%s) Failed(%d)", CTSVC_SOCKET_PATH, ret);
+               CTS_ERR("chmod(%s) Failed(%d)", sock_file, ret);
 
        ret = listen(sockfd, 30);
        if (-1 == ret) {