Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Jul 2015 13:52:54 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r285812 - head/sys/compat/cloudabi
Message-ID:  <201507231352.t6NDqsn5075410@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Thu Jul 23 13:52:53 2015
New Revision: 285812
URL: https://svnweb.freebsd.org/changeset/base/285812

Log:
  Allow us to create UNIX sockets and socketpairs in CloudABI processes.

Modified:
  head/sys/compat/cloudabi/cloudabi_fd.c

Modified: head/sys/compat/cloudabi/cloudabi_fd.c
==============================================================================
--- head/sys/compat/cloudabi/cloudabi_fd.c	Thu Jul 23 13:22:13 2015	(r285811)
+++ head/sys/compat/cloudabi/cloudabi_fd.c	Thu Jul 23 13:52:53 2015	(r285812)
@@ -46,18 +46,51 @@ int
 cloudabi_sys_fd_create1(struct thread *td,
     struct cloudabi_sys_fd_create1_args *uap)
 {
+	struct socket_args socket_args = {
+		.domain = AF_UNIX,
+	};
 
-	/* Not implemented. */
-	return (ENOSYS);
+	switch (uap->type) {
+	case CLOUDABI_FILETYPE_SOCKET_DGRAM:
+		socket_args.type = SOCK_DGRAM;
+		return (sys_socket(td, &socket_args));
+	case CLOUDABI_FILETYPE_SOCKET_SEQPACKET:
+		socket_args.type = SOCK_SEQPACKET;
+		return (sys_socket(td, &socket_args));
+	case CLOUDABI_FILETYPE_SOCKET_STREAM:
+		socket_args.type = SOCK_STREAM;
+		return (sys_socket(td, &socket_args));
+	default:
+		return (EINVAL);
+	}
 }
 
 int
 cloudabi_sys_fd_create2(struct thread *td,
     struct cloudabi_sys_fd_create2_args *uap)
 {
+	int fds[2];
+	int error;
 
-	/* Not implemented. */
-	return (ENOSYS);
+	switch (uap->type) {
+	case CLOUDABI_FILETYPE_SOCKET_DGRAM:
+		error = kern_socketpair(td, AF_UNIX, SOCK_DGRAM, 0, fds);
+		break;
+	case CLOUDABI_FILETYPE_SOCKET_SEQPACKET:
+		error = kern_socketpair(td, AF_UNIX, SOCK_SEQPACKET, 0, fds);
+		break;
+	case CLOUDABI_FILETYPE_SOCKET_STREAM:
+		error = kern_socketpair(td, AF_UNIX, SOCK_STREAM, 0, fds);
+		break;
+	default:
+		return (EINVAL);
+	}
+
+	if (error == 0) {
+		td->td_retval[0] = fds[0];
+		td->td_retval[1] = fds[1];
+	}
+	return (0);
 }
 
 int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507231352.t6NDqsn5075410>