[CRIU] [PATCH 4/3] zdtm: check that sockets are functional in del_standalone_un_dentry
Andrei Vagin
avagin at openvz.org
Wed Nov 23 22:38:44 PST 2016
From: Andrei Vagin <avagin at virtuozzo.com>
(00.026253) 30: Error (criu/sk-unix.c:918): sk unix: Can't connect 0xa48a0 socket: No such file or directory
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
test/zdtm/static/del_standalone_un_dentry.c | 44 +++++++++++++++++++++++------
1 file changed, 35 insertions(+), 9 deletions(-)
diff --git a/test/zdtm/static/del_standalone_un_dentry.c b/test/zdtm/static/del_standalone_un_dentry.c
index 28f95d5..439b050 100644
--- a/test/zdtm/static/del_standalone_un_dentry.c
+++ b/test/zdtm/static/del_standalone_un_dentry.c
@@ -30,11 +30,11 @@ static int fill_sock_name(struct sockaddr_un *name, const char *filename)
return 0;
}
-static int bind_and_listen(struct sockaddr_un *addr)
+static int sk_bind(struct sockaddr_un *addr)
{
int sk;
- sk = socket(PF_UNIX, SOCK_STREAM, 0);
+ sk = socket(PF_UNIX, SOCK_DGRAM, 0);
if (sk < 0) {
fail("socket");
return -1;
@@ -46,8 +46,21 @@ static int bind_and_listen(struct sockaddr_un *addr)
return -1;
}
- if (listen(sk, 1)) {
- fail("listen");
+ return sk;
+}
+
+static int sk_connect(struct sockaddr_un *addr)
+{
+ int sk;
+
+ sk = socket(PF_UNIX, SOCK_DGRAM, 0);
+ if (sk < 0) {
+ fail("socket");
+ return -1;
+ }
+
+ if (connect(sk, addr, sizeof(*addr))) {
+ fail("bind %s", addr->sun_path);
close(sk);
return -1;
}
@@ -58,7 +71,7 @@ static int bind_and_listen(struct sockaddr_un *addr)
int main(int argc, char **argv)
{
struct sockaddr_un addr;
- int sk1 = -1, sk2 = -1, sk3 = -1, ret = 1;
+ int sk1 = -1, sk2 = -1, sk3 = -1, sk4 = -1, ret = 1;
char filename[PATH_MAX], subdir[PATH_MAX];
char nestedname[PATH_MAX], temp[PATH_MAX];
@@ -79,7 +92,7 @@ int main(int argc, char **argv)
goto out;
}
- sk1 = bind_and_listen(&addr);
+ sk1 = sk_bind(&addr);
if (sk1 < 0)
goto out;
@@ -88,7 +101,7 @@ int main(int argc, char **argv)
goto out;
}
- sk2 = bind_and_listen(&addr);
+ sk2 = sk_bind(&addr);
if (sk2 < 0)
goto out;
@@ -102,8 +115,11 @@ int main(int argc, char **argv)
goto out;
}
- sk3 = bind_and_listen(&addr);
- if (sk1 < 0)
+ sk3 = sk_bind(&addr);
+ if (sk3 < 0)
+ goto out;
+ sk4 = sk_connect(&addr);
+ if (sk4 < 0)
goto out;
unlink(nestedname);
@@ -112,6 +128,16 @@ int main(int argc, char **argv)
test_daemon();
test_waitsig();
+ int c = 5;
+ if (write(sk4, &c, 1) != 1) {
+ fail("Unable to send a message");
+ return 1;
+ }
+ if (read(sk3, &c, 1) != 1) {
+ fail("Unable to recv a message");
+ return 1;
+ }
+
if (getsockopt(sk1, 0, 0, NULL, 0) && errno != EOPNOTSUPP) {
fail("socket 1 didn't survive restore");
goto out;
--
2.7.4
More information about the CRIU
mailing list