From 7a87d77509269f08dedb9dfe0b34041bd597130a Mon Sep 17 00:00:00 2001 From: He Sun Date: Fri, 8 May 2020 17:09:28 +0800 Subject: [PATCH] Fix error when PF_UNIX is passed as protocol to create unix socket Zero and PF_UNIX are both supported as protocol when creating unix socket. --- src/libos/src/net/unix_socket.rs | 3 ++- test/unix_socket/main.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libos/src/net/unix_socket.rs b/src/libos/src/net/unix_socket.rs index 5fc2808e..bfde30b1 100644 --- a/src/libos/src/net/unix_socket.rs +++ b/src/libos/src/net/unix_socket.rs @@ -184,12 +184,13 @@ enum Status { impl UnixSocket { /// C/S 1: Create a new unix socket pub fn new(socket_type: c_int, protocol: c_int) -> Result { - if socket_type == libc::SOCK_STREAM && protocol == 0 { + if socket_type == libc::SOCK_STREAM && (protocol == 0 || protocol == libc::PF_UNIX) { Ok(UnixSocket { obj: None, status: Status::None, }) } else { + // Return different error numbers according to input return_errno!(ENOSYS, "unimplemented unix socket type") } } diff --git a/test/unix_socket/main.c b/test/unix_socket/main.c index 06aff443..b41d0c71 100644 --- a/test/unix_socket/main.c +++ b/test/unix_socket/main.c @@ -34,7 +34,7 @@ int create_connected_sockets(int *sockets, char *sock_path) { THROW_ERROR("failed to listen"); } - int client_fd = socket(AF_UNIX, SOCK_STREAM, 0); + int client_fd = socket(AF_UNIX, SOCK_STREAM, PF_UNIX); if (client_fd == -1) { close(listen_fd); THROW_ERROR("failed to create a unix socket");