Commit 49a2cbd6 authored by Pavel Emelyanov's avatar Pavel Emelyanov

zdtm: Send two descriptors in two SCMs

Only the send code is altered, as upon receiving kernel
merges all scm_rights int one. CRIU relies on this merge
and this is to catch situations if the kernel suddenly
stops doing this.
Reviewed-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent ff90e847
...@@ -157,6 +157,7 @@ TST_NOFILE := \ ...@@ -157,6 +157,7 @@ TST_NOFILE := \
scm01 \ scm01 \
scm02 \ scm02 \
scm03 \ scm03 \
scm04 \
aio00 \ aio00 \
aio01 \ aio01 \
fd \ fd \
...@@ -444,6 +445,7 @@ sigpending: LDLIBS += -lrt ...@@ -444,6 +445,7 @@ sigpending: LDLIBS += -lrt
vdso01: LDLIBS += -lrt vdso01: LDLIBS += -lrt
scm01: CFLAGS += -DKEEP_SENT_FD scm01: CFLAGS += -DKEEP_SENT_FD
scm02: CFLAGS += -DSEND_BOTH scm02: CFLAGS += -DSEND_BOTH
scm04: CFLAGS += -DSEPARATE
mntns_link_remap: CFLAGS += -DZDTM_LINK_REMAP mntns_link_remap: CFLAGS += -DZDTM_LINK_REMAP
mntns_shared_bind02: CFLAGS += -DSHARED_BIND02 mntns_shared_bind02: CFLAGS += -DSHARED_BIND02
mntns_root_bind02: CFLAGS += -DROOT_BIND02 mntns_root_bind02: CFLAGS += -DROOT_BIND02
......
...@@ -14,11 +14,30 @@ static int send_fd(int via, int fd1, int fd2) ...@@ -14,11 +14,30 @@ static int send_fd(int via, int fd1, int fd2)
struct msghdr h = {}; struct msghdr h = {};
struct cmsghdr *ch; struct cmsghdr *ch;
struct iovec iov; struct iovec iov;
char buf[CMSG_SPACE(2 * sizeof(int))], c = '\0'; #ifdef SEPARATE
char buf[2 * CMSG_SPACE(sizeof(int))];
#else
char buf[CMSG_SPACE(2 * sizeof(int))];
#endif
char c = '\0';
int *fdp; int *fdp;
h.msg_control = buf; h.msg_control = buf;
h.msg_controllen = sizeof(buf); h.msg_controllen = sizeof(buf);
#ifdef SEPARATE
ch = CMSG_FIRSTHDR(&h);
ch->cmsg_level = SOL_SOCKET;
ch->cmsg_type = SCM_RIGHTS;
ch->cmsg_len = CMSG_LEN(sizeof(int));
fdp = (int *)CMSG_DATA(ch);
fdp[0] = fd1;
ch = CMSG_NXTHDR(&h, ch);
ch->cmsg_level = SOL_SOCKET;
ch->cmsg_type = SCM_RIGHTS;
ch->cmsg_len = CMSG_LEN(sizeof(int));
fdp = (int *)CMSG_DATA(ch);
fdp[0] = fd2;
#else
ch = CMSG_FIRSTHDR(&h); ch = CMSG_FIRSTHDR(&h);
ch->cmsg_level = SOL_SOCKET; ch->cmsg_level = SOL_SOCKET;
ch->cmsg_type = SCM_RIGHTS; ch->cmsg_type = SCM_RIGHTS;
...@@ -26,6 +45,7 @@ static int send_fd(int via, int fd1, int fd2) ...@@ -26,6 +45,7 @@ static int send_fd(int via, int fd1, int fd2)
fdp = (int *)CMSG_DATA(ch); fdp = (int *)CMSG_DATA(ch);
fdp[0] = fd1; fdp[0] = fd1;
fdp[1] = fd2; fdp[1] = fd2;
#endif
h.msg_iov = &iov; h.msg_iov = &iov;
h.msg_iovlen = 1; h.msg_iovlen = 1;
iov.iov_base = &c; iov.iov_base = &c;
...@@ -42,7 +62,8 @@ static int recv_fd(int via, int *fd1, int *fd2) ...@@ -42,7 +62,8 @@ static int recv_fd(int via, int *fd1, int *fd2)
struct msghdr h = {}; struct msghdr h = {};
struct cmsghdr *ch; struct cmsghdr *ch;
struct iovec iov; struct iovec iov;
char buf[CMSG_SPACE(2 * sizeof(int))], c; char buf[CMSG_SPACE(2 * sizeof(int))];
char c;
int *fdp; int *fdp;
h.msg_control = buf; h.msg_control = buf;
...@@ -55,6 +76,12 @@ static int recv_fd(int via, int *fd1, int *fd2) ...@@ -55,6 +76,12 @@ static int recv_fd(int via, int *fd1, int *fd2)
if (recvmsg(via, &h, 0) <= 0) if (recvmsg(via, &h, 0) <= 0)
return -1; return -1;
if (h.msg_flags & MSG_CTRUNC) {
test_msg("CTR\n");
return -2;
}
/* No 2 SCM-s here, kernel merges them upon send */
ch = CMSG_FIRSTHDR(&h); ch = CMSG_FIRSTHDR(&h);
if (h.msg_flags & MSG_TRUNC) if (h.msg_flags & MSG_TRUNC)
return -2; return -2;
......
scm03.c
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment