summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2020-08-27 16:50:11 -0700
committergVisor bot <gvisor-bot@google.com>2020-08-27 16:52:02 -0700
commitdc008fbbccf69deba55fd7649424bc568f766596 (patch)
tree297dbd6d147e23f84026dd44d245703f9a0afad9 /test
parent57877b420caa02bf4c60004c7b434ceef8603b26 (diff)
unix: return ECONNREFUSE if a socket file exists but a socket isn't bound to it
PiperOrigin-RevId: 328843560
Diffstat (limited to 'test')
-rw-r--r--test/syscalls/linux/mknod.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/syscalls/linux/mknod.cc b/test/syscalls/linux/mknod.cc
index 05dfb375a..2ba8c11b8 100644
--- a/test/syscalls/linux/mknod.cc
+++ b/test/syscalls/linux/mknod.cc
@@ -14,6 +14,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>
@@ -103,6 +104,24 @@ TEST(MknodTest, UnimplementedTypesReturnError) {
ASSERT_THAT(mknod(path.c_str(), S_IFBLK, 0), SyscallFailsWithErrno(EPERM));
}
+TEST(MknodTest, Socket) {
+ ASSERT_THAT(chdir(GetAbsoluteTestTmpdir().c_str()), SyscallSucceeds());
+
+ SKIP_IF(IsRunningOnGvisor() && IsRunningWithVFS1());
+
+ ASSERT_THAT(mknod("./file0", S_IFSOCK | S_IRUSR | S_IWUSR, 0),
+ SyscallSucceeds());
+
+ int sk;
+ ASSERT_THAT(sk = socket(AF_UNIX, SOCK_SEQPACKET, 0), SyscallSucceeds());
+ FileDescriptor fd(sk);
+
+ struct sockaddr_un addr = {.sun_family = AF_UNIX};
+ absl::SNPrintF(addr.sun_path, sizeof(addr.sun_path), "./file0");
+ ASSERT_THAT(connect(sk, (struct sockaddr *)&addr, sizeof(addr)),
+ SyscallFailsWithErrno(ECONNREFUSED));
+}
+
TEST(MknodTest, Fifo) {
const std::string fifo = NewTempAbsPath();
ASSERT_THAT(mknod(fifo.c_str(), S_IFIFO | S_IRUSR | S_IWUSR, 0),