Add fd passing feature for message-port 56/55156/8 submit/tizen/20151230.014719
authorHyunho Kang <hhstark.kang@samsung.com>
Tue, 29 Dec 2015 02:26:34 +0000 (11:26 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Wed, 30 Dec 2015 00:12:21 +0000 (09:12 +0900)
Change-Id: I3cb5877eb96b2cd2be4c8a6959f7937a0d1c27c1
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
include/aul.h
include/aul_cmd.h
src/aul_sock.c
src/launch.c

index 125287e..b4a8d0e 100644 (file)
@@ -1897,7 +1897,10 @@ void aul_app_group_get_idle_pids(int *cnt, int **pids);
  * This API is only for Appfw internally.
  */
 int aul_request_data_control_socket_pair(bundle *b, int *fd);
-
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_request_message_port_socket_pair(int *fd);
 /*
  * This API is only for Appfw internally.
  */
index ef5d0ba..504aa5b 100644 (file)
@@ -57,11 +57,16 @@ enum app_cmd {
        APP_GROUP_LOWER,
        APP_GROUP_CLEAR_TOP,
        APP_GET_STATUS,
-       APP_GET_SOCKET_PAIR,
        APP_ADD_LOADER,
        APP_REMOVE_LOADER,
        APP_GET_PID,
 
+       /* for data-control */
+       APP_GET_DC_SOCKET_PAIR,
+
+       /* for message-port */
+       APP_GET_MP_SOCKET_PAIR,
+
        /* for special purpose */
        AMD_RELOAD_APPINFO,
        /* reserved for AMD Agent */
index 21929d6..c7944d4 100644 (file)
@@ -502,7 +502,6 @@ static int __get_descriptors(struct cmsghdr *cmsg, struct msghdr *msg, int *fds,
 static int __recv_message(int sock, struct iovec *vec, int vec_max_size, int *vec_size,
                int *fds, int *nr_fds)
 {
-
        char buff[CMSG_SPACE(sizeof(int) * MAX_NR_OF_DESCRIPTORS) + CMSG_SPACE(50)] = {0};
        struct msghdr msg = {0};
        struct cmsghdr *cmsg = NULL;
@@ -545,12 +544,44 @@ static int __recv_message(int sock, struct iovec *vec, int vec_max_size, int *ve
        return ret;
 }
 
+int __recv_socket_fd(int fd, int cmd, int *ret_fd)
+{
+       int fds[2] = {0,};
+       char recv_buff[1024];
+       struct iovec vec[3];
+       int ret = 0;
+       int vec_len = 0;
+       int fds_len = 0;
+
+       vec[0].iov_base = recv_buff;
+       vec[0].iov_len = sizeof(recv_buff);
+       ret = __recv_message(fd, vec, 1, &vec_len, fds, &fds_len);
+       if (ret < 0) {
+               _E("Error[%d]. while receiving message\n", -ret);
+               if (fds_len > 0)
+                       close(fds[0]);
+               return -ECOMM;
+       }
+
+       if (fds_len > 0) {
+               if (cmd == APP_GET_DC_SOCKET_PAIR) {
+                       _D("fds : %d", fds[0]);
+                       ret_fd[0] = fds[0];
+               } else if (cmd == APP_GET_MP_SOCKET_PAIR) {
+                       _D("mp fds : %d %d", fds[0], fds[1]);
+                       ret_fd[0] = fds[0];
+                       ret_fd[1] = fds[1];
+               }
+       }
+       return 0;
+}
+
 int aul_sock_send_raw_with_fd_reply(int pid, uid_t uid, int cmd, unsigned char *kb_data, int datalen, int *ret_fd)
 {
        int fd;
        int len;
-       int ret;
        int res = 0;
+       int ret = 0;
        app_pkt_t *pkt = NULL;
 
        if (kb_data == NULL || datalen > AUL_SOCK_MAXBUFF - 8) {
@@ -617,29 +648,9 @@ int aul_sock_send_raw_with_fd_reply(int pid, uid_t uid, int cmd, unsigned char *
        }
 
 retry_recv:
-       if (cmd == APP_GET_SOCKET_PAIR) {
-               char recv_buff[1024];
-               struct iovec vec[3];
-               int ret = 0;
-               int vec_len = 0;
-               int fds_len = 0;
-               int fds[1] = {0};
-
-               vec[0].iov_base = recv_buff;
-               vec[0].iov_len = 1024;
-               ret = __recv_message(fd, vec, 1, &vec_len, fds, &fds_len);
-               if (ret < 0) {
-                       _E("Error[%d]. while receiving message\n", -ret);
-                       if (fds_len > 0)
-                               close(fds[0]);
-                       return -ECOMM;
-               } else
-                       recv_buff[ret] = '\0';
 
-               if (fds_len > 0) {
-                       _E("fds : %d", fds[0]);
-                       ret_fd[0] = fds[0];
-               }
+       if (cmd == APP_GET_DC_SOCKET_PAIR || APP_GET_MP_SOCKET_PAIR) {
+               res = __recv_socket_fd(fd, cmd, ret_fd);
        } else {
                len = recv(fd, &res, sizeof(int), 0);
                if (len == -1) {
index 5bf2a79..f1e01e6 100644 (file)
@@ -590,7 +590,12 @@ API void aul_finalize()
 
 API int aul_request_data_control_socket_pair(bundle *kb, int *fd)
 {
-       return app_request_to_launchpad_with_fd(APP_GET_SOCKET_PAIR, NULL, kb, fd, getuid());
+       return app_request_to_launchpad_with_fd(APP_GET_DC_SOCKET_PAIR, NULL, kb, fd, getuid());
+}
+
+API int aul_request_message_port_socket_pair(int *fd)
+{
+       return app_request_to_launchpad_with_fd(APP_GET_MP_SOCKET_PAIR, NULL, NULL, fd, getuid());
 }
 
 API int aul_launch_app(const char *appid, bundle *kb)