<div dir="ltr">Tested this and it seems to fix my communication issue. Thanks.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 17, 2015 at 6:45 AM, Andrey Vagin <span dir="ltr">&lt;<a href="mailto:avagin@openvz.org" target="_blank">avagin@openvz.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Currently we use a static buffer, but it is too small.<br>
<br>
Error (cr-service.c:58): Failed unpacking request: Success<br>
Error (cr-service.c:694): Can&#39;t recv request: Success<br>
data too short after length-prefix of 1217<br>
<br>
v2: use recv instead on recvmsg<br>
<br>
Reported-by: Ross Boucher &lt;<a href="mailto:rboucher@gmail.com">rboucher@gmail.com</a>&gt;<br>
Cc: Ross Boucher &lt;<a href="mailto:rboucher@gmail.com">rboucher@gmail.com</a>&gt;<br>
Signed-off-by: Andrey Vagin &lt;<a href="mailto:avagin@openvz.org">avagin@openvz.org</a>&gt;<br>
---<br>
 cr-service.c               | 23 +++++++++++++++++------<br>
 include/cr-service-const.h |  1 -<br>
 lib/criu.c                 | 19 +++++++++++++++----<br>
 3 files changed, 32 insertions(+), 11 deletions(-)<br>
<br>
diff --git a/cr-service.c b/cr-service.c<br>
index 0f0e2e2..2173376 100644<br>
--- a/cr-service.c<br>
+++ b/cr-service.c<br>
@@ -7,6 +7,7 @@<br>
 #include &lt;stdlib.h&gt;<br>
 #include &lt;errno.h&gt;<br>
 #include &lt;string.h&gt;<br>
+#include &lt;alloca.h&gt;<br>
 #include &lt;sys/types.h&gt;<br>
 #include &lt;sys/socket.h&gt;<br>
 #include &lt;sys/un.h&gt;<br>
@@ -36,12 +37,20 @@<br>
<br>
 unsigned int service_sk_ino = -1;<br>
<br>
-static int recv_criu_msg(int socket_fd, CriuReq **msg)<br>
+static int recv_criu_msg(int socket_fd, CriuReq **req)<br>
 {<br>
-       unsigned char buf[CR_MAX_MSG_SIZE];<br>
+       unsigned char *buf;<br>
        int len;<br>
<br>
-       len = read(socket_fd, buf, CR_MAX_MSG_SIZE);<br>
+       len = recv(socket_fd, NULL, 0, MSG_TRUNC | MSG_PEEK);<br>
+       if (len == -1) {<br>
+               pr_perror(&quot;Can&#39;t read request&quot;);<br>
+               return -1;<br>
+       }<br>
+<br>
+       buf = alloca(len);<br>
+<br>
+       len = recv(socket_fd, buf, len, MSG_TRUNC);<br>
        if (len == -1) {<br>
                pr_perror(&quot;Can&#39;t read request&quot;);<br>
                return -1;<br>
@@ -53,8 +62,8 @@ static int recv_criu_msg(int socket_fd, CriuReq **msg)<br>
                return -1;<br>
        }<br>
<br>
-       *msg = criu_req__unpack(NULL, len, buf);<br>
-       if (!*msg) {<br>
+       *req = criu_req__unpack(NULL, len, buf);<br>
+       if (!*req) {<br>
                pr_perror(&quot;Failed unpacking request&quot;);<br>
                return -1;<br>
        }<br>
@@ -64,11 +73,13 @@ static int recv_criu_msg(int socket_fd, CriuReq **msg)<br>
<br>
 static int send_criu_msg(int socket_fd, CriuResp *msg)<br>
 {<br>
-       unsigned char buf[CR_MAX_MSG_SIZE];<br>
+       unsigned char *buf;<br>
        int len;<br>
<br>
        len = criu_resp__get_packed_size(msg);<br>
<br>
+       buf = alloca(len);<br>
+<br>
        if (criu_resp__pack(msg, buf) != len) {<br>
                pr_perror(&quot;Failed packing response&quot;);<br>
                return -1;<br>
diff --git a/include/cr-service-const.h b/include/cr-service-const.h<br>
index 668882b..b8827f4 100644<br>
--- a/include/cr-service-const.h<br>
+++ b/include/cr-service-const.h<br>
@@ -1,7 +1,6 @@<br>
 #ifndef __CR_SERVICE_CONST_H__<br>
 #define __CR_SERVICE_CONST_H__<br>
<br>
-#define CR_MAX_MSG_SIZE 1024<br>
 #define CR_DEFAULT_SERVICE_ADDRESS &quot;/var/run/criu_service.socket&quot;<br>
<br>
 #endif /* __CR_SERVICE_CONST_H__ */<br>
diff --git a/lib/criu.c b/lib/criu.c<br>
index 9308250..ff7e400 100644<br>
--- a/lib/criu.c<br>
+++ b/lib/criu.c<br>
@@ -10,6 +10,7 @@<br>
 #include &lt;stdlib.h&gt;<br>
 #include &lt;errno.h&gt;<br>
 #include &lt;signal.h&gt;<br>
+#include &lt;alloca.h&gt;<br>
<br>
 #include &quot;criu.h&quot;<br>
 #include &quot;rpc.pb-c.h&quot;<br>
@@ -311,13 +312,21 @@ er:<br>
<br>
 static CriuResp *recv_resp(int socket_fd)<br>
 {<br>
-       unsigned char buf[CR_MAX_MSG_SIZE];<br>
+       unsigned char *buf;<br>
        int len;<br>
        CriuResp *msg = 0;<br>
<br>
-       len = read(socket_fd, buf, CR_MAX_MSG_SIZE);<br>
+       len = recv(socket_fd, NULL, 0, MSG_TRUNC | MSG_PEEK);<br>
        if (len == -1) {<br>
-               perror(&quot;Can&#39;t read response&quot;);<br>
+               perror(&quot;Can&#39;t read request&quot;);<br>
+               goto err;<br>
+       }<br>
+<br>
+       buf = alloca(len);<br>
+<br>
+       len = recv(socket_fd, buf, len, MSG_TRUNC);<br>
+       if (len == -1) {<br>
+               perror(&quot;Can&#39;t read request&quot;);<br>
                goto err;<br>
        }<br>
<br>
@@ -335,11 +344,13 @@ err:<br>
<br>
 static int send_req(int socket_fd, CriuReq *req)<br>
 {<br>
-       unsigned char buf[CR_MAX_MSG_SIZE];<br>
+       unsigned char *buf;<br>
        int len;<br>
<br>
        len = criu_req__get_packed_size(req);<br>
<br>
+       buf = alloca(len);<br>
+<br>
        if (criu_req__pack(req, buf) != len) {<br>
                perror(&quot;Failed packing request&quot;);<br>
                goto err;<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.1.0<br>
<br>
</font></span></blockquote></div><br></div>