static int recv_criu_msg(int socket_fd, CriuReq **msg) { unsigned char buf[CR_MAX_MSG_SIZE]; int len; len = read(socket_fd, buf, CR_MAX_MSG_SIZE); if (len == -1) { pr_perror("Can't read request"); return -1; } if (len == 0) { pr_info("Client exited unexpectedly\n"); errno = ECONNRESET; return -1; } *msg = criu_req__unpack(NULL, len, buf); if (!*msg) { pr_perror("Failed unpacking request"); return -1; } return 0; }
static int recv_criu_msg(int socket_fd, CriuReq **req) { unsigned char *buf; int len; len = recv(socket_fd, NULL, 0, MSG_TRUNC | MSG_PEEK); if (len == -1) { pr_perror("Can't read request"); return -1; } buf = alloca(len); len = recv(socket_fd, buf, len, MSG_TRUNC); if (len == -1) { pr_perror("Can't read request"); return -1; } if (len == 0) { pr_info("Client exited unexpectedly\n"); errno = ECONNRESET; return -1; } *req = criu_req__unpack(NULL, len, buf); if (!*req) { pr_perror("Failed unpacking request"); return -1; } return 0; }