mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-29 21:38:16 +00:00
sockets: Split open_unix_sk to stream and dgram versions
And add some comments. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
parent
cc15c01832
commit
04ec43a5d5
60
sockets.c
60
sockets.c
@ -484,22 +484,23 @@ static void prep_conn_addr(int id, struct sockaddr_un *addr, int *addrlen)
|
|||||||
*addrlen = sizeof(addr->sun_family) + sizeof("crtools-sk-") - 1 + 10;
|
*addrlen = sizeof(addr->sun_family) + sizeof("crtools-sk-") - 1 + 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int open_unix_sk(struct unix_sk_entry *ue, int *img_fd)
|
static int open_unix_sk_dgram(int sk, struct unix_sk_entry *ue, int *img_fd)
|
||||||
{
|
{
|
||||||
int sk;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
show_one_unix_img("Restore", ue);
|
static int open_unix_sk_stream(int sk, struct unix_sk_entry *ue, int *img_fd)
|
||||||
|
{
|
||||||
sk = socket(PF_UNIX, ue->type, 0);
|
int ret = -1;
|
||||||
if (sk < 0) {
|
|
||||||
pr_perror("Can't create unix socket\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ue->state == TCP_LISTEN) {
|
if (ue->state == TCP_LISTEN) {
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Listen sockets are easiest ones -- simply
|
||||||
|
* bind() and listen(), and that's all.
|
||||||
|
*/
|
||||||
if (!ue->namelen || ue->namelen >= UNIX_PATH_MAX) {
|
if (!ue->namelen || ue->namelen >= UNIX_PATH_MAX) {
|
||||||
pr_err("Bad unix name len %d\n", ue->namelen);
|
pr_err("Bad unix name len %d\n", ue->namelen);
|
||||||
goto err;
|
goto err;
|
||||||
@ -527,6 +528,16 @@ static int open_unix_sk(struct unix_sk_entry *ue, int *img_fd)
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
} else if (ue->state == TCP_ESTABLISHED) {
|
} else if (ue->state == TCP_ESTABLISHED) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If a connection is established we need
|
||||||
|
* two separate steps -- one peer become
|
||||||
|
* a server and do bind()/listen(), then
|
||||||
|
* it deferred to accept() later, while
|
||||||
|
* another peer become a client and
|
||||||
|
* deferred to connect() later.
|
||||||
|
*/
|
||||||
|
|
||||||
if (ue->peer < ue->id) {
|
if (ue->peer < ue->id) {
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
int len;
|
int len;
|
||||||
@ -577,6 +588,37 @@ static int open_unix_sk(struct unix_sk_entry *ue, int *img_fd)
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
err:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int open_unix_sk(struct unix_sk_entry *ue, int *img_fd)
|
||||||
|
{
|
||||||
|
int sk;
|
||||||
|
|
||||||
|
show_one_unix_img("Restore", ue);
|
||||||
|
|
||||||
|
sk = socket(PF_UNIX, ue->type, 0);
|
||||||
|
if (sk < 0) {
|
||||||
|
pr_perror("Can't create unix socket\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (ue->type) {
|
||||||
|
case SOCK_STREAM:
|
||||||
|
if (open_unix_sk_stream(sk, ue, img_fd))
|
||||||
|
goto err;
|
||||||
|
break;
|
||||||
|
case SOCK_DGRAM:
|
||||||
|
if (open_unix_sk_dgram(sk, ue, img_fd))
|
||||||
|
goto err;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
pr_err("Unsupported socket type: %d\n", ue->type);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
if (move_img_fd(img_fd, ue->fd))
|
if (move_img_fd(img_fd, ue->fd))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user