mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 14:25:49 +00:00
zdtm: improve socket-tcp-close-wait.c
* Don't send uninitialized data * Close descriptors more carefully * Add comments travis-ci: success for zdtm: improve socket-tcp-close-wait.c Reported-by: Dmitry Safonov <dsafonov@virtuozzo.com> Cc: Dmitry Safonov <dsafonov@virtuozzo.com> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com> Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
f2181eaed2
commit
3dd21b1bdd
@@ -95,7 +95,7 @@ int main(int argc, char **argv)
|
|||||||
int fd, fd_s, ctl_fd;
|
int fd, fd_s, ctl_fd;
|
||||||
pid_t extpid;
|
pid_t extpid;
|
||||||
int pfd[2];
|
int pfd[2];
|
||||||
int ret, snd_size = 0, rcv_size = 0;
|
int ret = 0, snd_size = 0, rcv_size = 0;
|
||||||
#ifndef ZDTM_TCP_LAST_ACK
|
#ifndef ZDTM_TCP_LAST_ACK
|
||||||
char buf[BUF_SIZE];
|
char buf[BUF_SIZE];
|
||||||
#endif
|
#endif
|
||||||
@@ -104,13 +104,13 @@ int main(int argc, char **argv)
|
|||||||
test_init(argc, argv);
|
test_init(argc, argv);
|
||||||
|
|
||||||
if (pipe(pfd)) {
|
if (pipe(pfd)) {
|
||||||
pr_err("pipe() failed");
|
pr_perror("pipe() failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
extpid = fork();
|
extpid = fork();
|
||||||
if (extpid < 0) {
|
if (extpid < 0) {
|
||||||
pr_err("fork() failed");
|
pr_perror("fork() failed");
|
||||||
return 1;
|
return 1;
|
||||||
} else if (extpid == 0) {
|
} else if (extpid == 0) {
|
||||||
int size = 0;
|
int size = 0;
|
||||||
@@ -121,9 +121,10 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
close(pfd[1]);
|
close(pfd[1]);
|
||||||
if (read(pfd[0], &port, sizeof(port)) != sizeof(port)) {
|
if (read(pfd[0], &port, sizeof(port)) != sizeof(port)) {
|
||||||
pr_err("Can't read port\n");
|
pr_perror("Can't read port\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
close(pfd[0]);
|
||||||
|
|
||||||
fd = tcp_init_client(ZDTM_FAMILY, "127.0.0.1", port);
|
fd = tcp_init_client(ZDTM_FAMILY, "127.0.0.1", port);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
@@ -133,23 +134,28 @@ int main(int argc, char **argv)
|
|||||||
if (ctl_fd < 0)
|
if (ctl_fd < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
/* == The preparation stage == */
|
||||||
if (read(ctl_fd, &size, sizeof(size)) != sizeof(size)) {
|
if (read(ctl_fd, &size, sizeof(size)) != sizeof(size)) {
|
||||||
pr_err("write");
|
pr_perror("read");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shutdown(fd, SHUT_WR) == -1) {
|
if (shutdown(fd, SHUT_WR) == -1) {
|
||||||
pr_err("shutdown");
|
pr_perror("shutdown");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write(ctl_fd, &size, sizeof(size)) != sizeof(size)) {
|
if (write(ctl_fd, &size, sizeof(size)) != sizeof(size)) {
|
||||||
pr_err("write");
|
pr_perror("write");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
/* == End of the preparation stage == */
|
||||||
|
|
||||||
|
/* Checkpoint/restore */
|
||||||
|
|
||||||
|
/* == The final stage == */
|
||||||
if (read(ctl_fd, &c, 1) != 0) {
|
if (read(ctl_fd, &c, 1) != 0) {
|
||||||
pr_err("read");
|
pr_perror("read");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,12 +166,18 @@ int main(int argc, char **argv)
|
|||||||
#else
|
#else
|
||||||
if (read(fd, buf, sizeof(buf)) != sizeof(TEST_MSG) ||
|
if (read(fd, buf, sizeof(buf)) != sizeof(TEST_MSG) ||
|
||||||
strncmp(buf, TEST_MSG, sizeof(TEST_MSG))) {
|
strncmp(buf, TEST_MSG, sizeof(TEST_MSG))) {
|
||||||
pr_err("read");
|
pr_perror("read");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
write(ctl_fd, &size, sizeof(size));
|
if (write(ctl_fd, &size, sizeof(size)) != sizeof(size)) {
|
||||||
|
pr_perror("write");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/* == End of the final stage == */
|
||||||
|
|
||||||
|
close(ctl_fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -181,7 +193,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
close(pfd[0]);
|
close(pfd[0]);
|
||||||
if (write(pfd[1], &port, sizeof(port)) != sizeof(port)) {
|
if (write(pfd[1], &port, sizeof(port)) != sizeof(port)) {
|
||||||
pr_err("Can't send port");
|
pr_perror("Can't send port");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
close(pfd[1]);
|
close(pfd[1]);
|
||||||
@@ -191,16 +203,17 @@ int main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
fd = tcp_accept_server(fd_s);
|
fd = tcp_accept_server(fd_s);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
pr_err("can't accept client connection %m");
|
pr_perror("can't accept client connection %m");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctl_fd = tcp_accept_server(fd_s);
|
ctl_fd = tcp_accept_server(fd_s);
|
||||||
if (ctl_fd < 0) {
|
if (ctl_fd < 0) {
|
||||||
pr_err("can't accept client connection %m");
|
pr_perror("can't accept client connection %m");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* == The preparation stage == */
|
||||||
#ifdef ZDTM_TCP_LAST_ACK
|
#ifdef ZDTM_TCP_LAST_ACK
|
||||||
snd_size = fill_sock_buf(fd);
|
snd_size = fill_sock_buf(fd);
|
||||||
if (snd_size <= 0)
|
if (snd_size <= 0)
|
||||||
@@ -208,18 +221,19 @@ int main(int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (write(ctl_fd, &ret, sizeof(ret)) != sizeof(ret)) {
|
if (write(ctl_fd, &ret, sizeof(ret)) != sizeof(ret)) {
|
||||||
pr_err("read");
|
pr_perror("read");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read(ctl_fd, &ret, sizeof(ret)) != sizeof(ret)) {
|
if (read(ctl_fd, &ret, sizeof(ret)) != sizeof(ret)) {
|
||||||
pr_err("read");
|
pr_perror("read");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
/* == End of the preparation stage */
|
||||||
|
|
||||||
#ifdef ZDTM_TCP_LAST_ACK
|
#ifdef ZDTM_TCP_LAST_ACK
|
||||||
if (shutdown(fd, SHUT_WR) == -1) {
|
if (shutdown(fd, SHUT_WR) == -1) {
|
||||||
pr_err("shutdown");
|
pr_perror("shutdown");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -227,19 +241,20 @@ int main(int argc, char **argv)
|
|||||||
test_daemon();
|
test_daemon();
|
||||||
test_waitsig();
|
test_waitsig();
|
||||||
|
|
||||||
|
/* == The final stage == */
|
||||||
if (shutdown(ctl_fd, SHUT_WR) == -1) {
|
if (shutdown(ctl_fd, SHUT_WR) == -1) {
|
||||||
pr_err("shutdown");
|
pr_perror("shutdown");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef ZDTM_TCP_LAST_ACK
|
#ifndef ZDTM_TCP_LAST_ACK
|
||||||
if (write(fd, TEST_MSG, sizeof(TEST_MSG)) != sizeof(TEST_MSG)) {
|
if (write(fd, TEST_MSG, sizeof(TEST_MSG)) != sizeof(TEST_MSG)) {
|
||||||
pr_err("write");
|
pr_perror("write");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shutdown(fd, SHUT_WR) == -1) {
|
if (shutdown(fd, SHUT_WR) == -1) {
|
||||||
pr_err("shutdown");
|
pr_perror("shutdown");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -252,9 +267,10 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (read(ctl_fd, &ret, sizeof(ret)) != sizeof(ret)) {
|
if (read(ctl_fd, &ret, sizeof(ret)) != sizeof(ret)) {
|
||||||
pr_err("read");
|
pr_perror("read");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
/* == End of the final stage == */
|
||||||
|
|
||||||
if (ret != snd_size) {
|
if (ret != snd_size) {
|
||||||
fail("The parent sent %d bytes, but the child received %d bytes\n", snd_size, ret);
|
fail("The parent sent %d bytes, but the child received %d bytes\n", snd_size, ret);
|
||||||
|
Reference in New Issue
Block a user