[CRIU] [PATCH 1/2] libcriu: criu_dump_me() and library header
Pavel Emelyanov
xemul at parallels.com
Thu Aug 29 14:02:35 EDT 2013
On 08/29/2013 09:27 PM, Ruslan Kuprieiev wrote:
> Hi!
>
> Patch 1\2 contains criu_dump_me() for library and library header.
> * criu_dump_me() gets an argument of type struct criu_dump_args
> from user program,
> processes it and sends request to criu through unix domain socket.
> Then, it gets flag from criu and returns it back to program.
> * libcriu.h contains definitions of flags, struct criu_dump_args etc.
> So, it is to be used in user program.
Somehow lines get wrapped. Plz, don't.
> Signed-off-by: Ruslan Kuprieiev kupruser at gmail.com
Mail should be in <> braces. Mind using the -s key to git commit command.
> +int criu_dump_me(struct criu_dump_args *arg)
> +{
> + int socket_fd;
> +
> + socket_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
> + if (socket_fd == -1) {
> + perror("Can't create socket");
> + return -1;
> + }
> +
> + struct sockaddr_un server_addr;
No variables declarations in the middle of the code.
> +
> + memset(&server_addr, 0, sizeof(server_addr));
> + server_addr.sun_family = AF_LOCAL;
> +
> + if (!arg->service_addr)
> + arg->service_addr = CR_DEFAULT_SERVICE_ADDRESS;
> +
> + strcpy(server_addr.sun_path, arg->service_addr);
> +
> + socklen_t server_addr_len;
> +
> + server_addr_len = strlen(server_addr.sun_path)
> + + sizeof(server_addr.sun_family);
> +
> + if (connect(socket_fd, (struct sockaddr *) &server_addr,
> + server_addr_len) != 0) {
> + perror("Can't connect to service socket");
> + return -1;
-1? We have pre-defined error codes for that.
> + }
> +
> + if (criu_send_dump_arg(socket_fd, arg) == -1) {
> + perror("Can't send dump arg");
> + close(socket_fd);
> + return -1;
> + }
> +
> + int ret;
> + int c;
> +
> + c = read(socket_fd, &ret, sizeof(ret));
> + if (c == -1)
> + goto err;
> +
> + close(socket_fd);
> + return ret;
> +
> +err:
> + close(socket_fd);
> + return -1;
> +}
> +
More information about the CRIU
mailing list