summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSemun Lee <sm79.lee@samsung.com>2017-03-04 14:38:23 +0900
committerSemun Lee <sm79.lee@samsung.com>2017-03-04 14:38:23 +0900
commit709ec1fb8525a1cc0aff632b4af0efc17d1c6c3e (patch)
tree6bcf4175e9e80bf790b197946ad0788a78a04398
parent787579c82fd411ee74ee2c76472decf2f36d72db (diff)
downloadlaunchpad-709ec1fb8525a1cc0aff632b4af0efc17d1c6c3e.tar.gz
launchpad-709ec1fb8525a1cc0aff632b4af0efc17d1c6c3e.tar.bz2
launchpad-709ec1fb8525a1cc0aff632b4af0efc17d1c6c3e.zip
Handle large app_pkt_t properly in send/recv
launchpad need to handle large data properly. This patch fixes to handle large data properly in send/recv. Change-Id: I3ca132bf82bbb389b6696e63ea53ebdc8d773131 Signed-off-by: Semun Lee <sm79.lee@samsung.com>
-rw-r--r--inc/launchpad_common.h3
-rwxr-xr-xsrc/launchpad.c2
-rw-r--r--src/launchpad_common.c96
-rw-r--r--src/launchpad_lib.c15
4 files changed, 60 insertions, 56 deletions
diff --git a/inc/launchpad_common.h b/inc/launchpad_common.h
index 93ba100..0d4ef6e 100644
--- a/inc/launchpad_common.h
+++ b/inc/launchpad_common.h
@@ -91,7 +91,8 @@ void _modify_bundle(bundle *kb, int caller_pid, appinfo_t *menu_info, int cmd);
int _send_cmd_to_amd(int cmd);
int _create_server_sock(const char *name);
-app_pkt_t *_recv_pkt_raw(int fd, int *clifd, struct ucred *cr);
+app_pkt_t *_recv_pkt_raw(int fd);
+app_pkt_t *_accept_recv_pkt_raw(int fd, int *clifd, struct ucred *cr);
int _send_pkt_raw(int client_fd, app_pkt_t *pkt);
int _connect_to_launchpad(int type, int id);
void _set_sock_option(int fd, int cli);
diff --git a/src/launchpad.c b/src/launchpad.c
index 06fa044..4087450 100755
--- a/src/launchpad.c
+++ b/src/launchpad.c
@@ -1264,7 +1264,7 @@ static gboolean __handle_launch_event(gpointer data)
int ret;
traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "LAUNCHPAD:LAUNCH");
- pkt = _recv_pkt_raw(fd, &clifd, &cr);
+ pkt = _accept_recv_pkt_raw(fd, &clifd, &cr);
if (!pkt) {
_E("packet is NULL");
goto end;
diff --git a/src/launchpad_common.c b/src/launchpad_common.c
index a92e5b6..ae4f546 100644
--- a/src/launchpad_common.c
+++ b/src/launchpad_common.c
@@ -313,48 +313,25 @@ int _create_server_sock(const char *name)
return fd;
}
-app_pkt_t *_recv_pkt_raw(int fd, int *clifd, struct ucred *cr)
+app_pkt_t *_recv_pkt_raw(int fd)
{
int len;
int ret;
- struct sockaddr_un aul_addr = { 0, };
- int sun_size;
- app_pkt_t *pkt = NULL;
- int cl = sizeof(struct ucred);
unsigned char buf[AUL_SOCK_MAXBUFF];
+ app_pkt_t *pkt;
int cmd;
int datalen;
int opt;
- sun_size = sizeof(struct sockaddr_un);
-
- *clifd = accept(fd, (struct sockaddr *)&aul_addr,
- (socklen_t *) &sun_size);
- if (*clifd == -1) {
- if (errno != EINTR)
- _E("accept error");
- return NULL;
- }
-
- if (getsockopt(*clifd, SOL_SOCKET, SO_PEERCRED, cr,
- (socklen_t *) &cl) < 0) {
- _E("peer information error");
- close(*clifd);
- return NULL;
- }
-
- _set_sock_option(*clifd, 1);
-
retry_recv:
/* receive header(cmd, datalen) */
- len = recv(*clifd, buf, AUL_PKT_HEADER_SIZE, 0);
+ len = recv(fd, buf, AUL_PKT_HEADER_SIZE, 0);
if (len < 0)
if (errno == EINTR)
goto retry_recv;
if (len < AUL_PKT_HEADER_SIZE) {
_E("recv error");
- close(*clifd);
return NULL;
}
memcpy(&cmd, buf, sizeof(int));
@@ -364,7 +341,7 @@ retry_recv:
/* allocate for a null byte */
pkt = (app_pkt_t *)calloc(1, AUL_PKT_HEADER_SIZE + datalen + 1);
if (pkt == NULL) {
- close(*clifd);
+ _E("failed to alloc app_pkt_t");
return NULL;
}
pkt->cmd = cmd;
@@ -373,11 +350,10 @@ retry_recv:
len = 0;
while (len != pkt->len) {
- ret = recv(*clifd, pkt->data + len, pkt->len - len, 0);
+ ret = recv(fd, pkt->data + len, pkt->len - len, 0);
if (ret < 0) {
_E("recv error %d %d", len, pkt->len);
free(pkt);
- close(*clifd);
return NULL;
}
len += ret;
@@ -387,33 +363,71 @@ retry_recv:
return pkt;
}
+app_pkt_t *_accept_recv_pkt_raw(int fd, int *clifd, struct ucred *cr)
+{
+ struct sockaddr_un aul_addr = { 0, };
+ int sun_size;
+ app_pkt_t *pkt;
+ int newfd;
+ int cl = sizeof(struct ucred);
+
+ sun_size = sizeof(struct sockaddr_un);
+
+ newfd = accept(fd, (struct sockaddr *)&aul_addr,
+ (socklen_t *) &sun_size);
+ if (newfd == -1) {
+ if (errno != EINTR)
+ _E("accept error");
+ return NULL;
+ }
+
+ if (getsockopt(newfd, SOL_SOCKET, SO_PEERCRED, cr,
+ (socklen_t *) &cl) < 0) {
+ _E("peer information error");
+ close(newfd);
+ return NULL;
+ }
+
+ _set_sock_option(newfd, 1);
+
+ pkt = _recv_pkt_raw(newfd);
+ if (pkt == NULL) {
+ _E("failed to receive pkt from client");
+ close(newfd);
+ return NULL;
+ }
+
+ *clifd = newfd;
+ return pkt;
+}
+
int _send_pkt_raw(int client_fd, app_pkt_t *pkt)
{
int send_ret = 0;
int pkt_size = 0;
+ int sent = 0;
if (client_fd == -1 || pkt == NULL) {
_E("arguments error!");
- goto error;
+ return -1;
}
pkt_size = AUL_PKT_HEADER_SIZE + pkt->len;
- send_ret = send(client_fd, pkt, pkt_size, MSG_NOSIGNAL);
- _D("send(%d) : %d / %d", client_fd, send_ret, pkt_size);
+ while (sent != pkt_size) {
+ send_ret = send(client_fd, (char *)pkt + sent,
+ pkt_size - sent, MSG_NOSIGNAL);
+ if (send_ret == -1) {
+ _E("send error! (%d)", errno);
+ return -1;
+ }
- if (send_ret == -1) {
- _E("send error!");
- goto error;
- } else if (send_ret != pkt_size) {
- _E("send byte fail!");
- goto error;
+ sent += send_ret;
+ _D("send(%d: ret: %d) : %d / %d",
+ client_fd, send_ret, sent, pkt_size);
}
return 0;
-
-error:
- return -1;
}
appinfo_t *_appinfo_create(bundle *kb)
diff --git a/src/launchpad_lib.c b/src/launchpad_lib.c
index 17553ba..70a600e 100644
--- a/src/launchpad_lib.c
+++ b/src/launchpad_lib.c
@@ -266,25 +266,14 @@ static int __candidate_process_launchpad_main_loop(app_pkt_t *pkt,
static void __receiver_cb(int fd)
{
int ret = -1;
- int recv_ret;
app_pkt_t *pkt;
_D("[candidate] ECORE_FD_READ");
- pkt = (app_pkt_t *)malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
+ pkt = _recv_pkt_raw(fd);
if (!pkt) {
- _D("[candidate] out of memory1");
+ _D("[candidate] _recv_pkt_raw error!");
exit(-1);
}
- memset(pkt, 0, AUL_SOCK_MAXBUFF);
-
- recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0);
- if (recv_ret == -1) {
- _D("[condidate] recv error!");
- close(fd);
- free(pkt);
- exit(-1);
- }
- _D("[candidate] recv_ret: %d, pkt->len: %d", recv_ret, pkt->len);
__loader_adapter->remove_fd(__loader_user_data, fd);
close(fd);