diff options
author | Hyunho Kang <hhstark.kang@samsung.com> | 2015-12-29 11:26:34 +0900 |
---|---|---|
committer | Hyunho Kang <hhstark.kang@samsung.com> | 2015-12-30 09:12:21 +0900 |
commit | 748c2b68c1ee16bfc9e13e187d0b608269d67362 (patch) | |
tree | 64e1188fd1a7edbe99ac768308f6883aa5b695ca | |
parent | d0afa4f141825fe0b6b426e9cdceb3efefded1ec (diff) | |
download | aul-1-748c2b68c1ee16bfc9e13e187d0b608269d67362.tar.gz aul-1-748c2b68c1ee16bfc9e13e187d0b608269d67362.tar.bz2 aul-1-748c2b68c1ee16bfc9e13e187d0b608269d67362.zip |
Add fd passing feature for message-portsubmit/tizen/20151230.014719
Change-Id: I3cb5877eb96b2cd2be4c8a6959f7937a0d1c27c1
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
-rw-r--r-- | include/aul.h | 5 | ||||
-rw-r--r-- | include/aul_cmd.h | 7 | ||||
-rw-r--r-- | src/aul_sock.c | 59 | ||||
-rw-r--r-- | src/launch.c | 7 |
4 files changed, 51 insertions, 27 deletions
diff --git a/include/aul.h b/include/aul.h index 125287e1..b4a8d0e4 100644 --- a/include/aul.h +++ b/include/aul.h @@ -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. */ diff --git a/include/aul_cmd.h b/include/aul_cmd.h index ef5d0baa..504aa5b9 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -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 */ diff --git a/src/aul_sock.c b/src/aul_sock.c index 21929d6a..c7944d4e 100644 --- a/src/aul_sock.c +++ b/src/aul_sock.c @@ -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) { diff --git a/src/launch.c b/src/launch.c index 5bf2a79c..f1e01e6f 100644 --- a/src/launch.c +++ b/src/launch.c @@ -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) |