summaryrefslogtreecommitdiff
path: root/pflocal
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@gnu.org>2000-08-02 20:19:45 +0000
committerMark Kettenis <kettenis@gnu.org>2000-08-02 20:19:45 +0000
commita6888a2b3a918920fe27133308c820e78dcecf16 (patch)
treef6f411ce5fcbcc26087c78daa4b93ddc613defd7 /pflocal
parent18dc5dc677ebf1d415e1adeff24041e9f496a2ed (diff)
Add `magic' protocols to specify the file type of a sockets. This
allows implementation of POSIX pipes by using a S_IFSOCK protocol. * sock.h: Include <sys/types.h>. (struct sock): Add new member `mode'. (sock_create): Add new parameter `mode'. * sock.c (sock_create): Initialize `mode' member of struct sock, with new parameter. * pf.c (S_socket_create): Pass file type/mode to sock_create based on PROTOCOL. * io.c (S_io_stat): Use new member of `struct sock' to set ST->st_mode.
Diffstat (limited to 'pflocal')
-rw-r--r--pflocal/ChangeLog14
-rw-r--r--pflocal/io.c4
-rw-r--r--pflocal/pf.c17
-rw-r--r--pflocal/sock.c7
-rw-r--r--pflocal/sock.h10
5 files changed, 41 insertions, 11 deletions
diff --git a/pflocal/ChangeLog b/pflocal/ChangeLog
index 92f51914..a8b48a63 100644
--- a/pflocal/ChangeLog
+++ b/pflocal/ChangeLog
@@ -1,3 +1,17 @@
+2000-08-02 Mark Kettenis <kettenis@gnu.org>
+
+ Add `magic' protocols to specify the file type of a sockets. This
+ allows implementation of POSIX pipes by using a S_IFSOCK protocol.
+ * sock.h: Include <sys/types.h>.
+ (struct sock): Add new member `mode'.
+ (sock_create): Add new parameter `mode'.
+ * sock.c (sock_create): Initialize `mode' member of struct sock,
+ with new parameter.
+ * pf.c (S_socket_create): Pass file type/mode to sock_create based
+ on PROTOCOL.
+ * io.c (S_io_stat): Use new member of `struct sock' to set
+ ST->st_mode.
+
2000-07-26 Mark Kettenis <kettenis@gnu.org>
* Makefile (HURDLIBS): Reorder libs such that the threads lib
diff --git a/pflocal/io.c b/pflocal/io.c
index 133c75c9..dca24876 100644
--- a/pflocal/io.c
+++ b/pflocal/io.c
@@ -1,6 +1,6 @@
/* Socket I/O operations
- Copyright (C) 1995, 1996, 1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1998, 1999, 2000 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.ai.mit.edu>
@@ -287,7 +287,7 @@ S_io_stat (struct sock_user *user, struct stat *st)
bzero (st, sizeof (struct stat));
st->st_fstype = FSTYPE_SOCKET;
- st->st_mode = S_IFSOCK;
+ st->st_mode = sock->mode;
st->st_fsid = getpid ();
st->st_ino = sock->id;
/* As we try to be clever with large transfers, ask for them. */
diff --git a/pflocal/pf.c b/pflocal/pf.c
index 65d5c5a9..1244c600 100644
--- a/pflocal/pf.c
+++ b/pflocal/pf.c
@@ -1,6 +1,6 @@
/* Protocol family operations
- Copyright (C) 1995, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1999, 2000 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.ai.mit.edu>
@@ -36,8 +36,17 @@ S_socket_create (mach_port_t pf,
error_t err;
struct sock *sock;
struct pipe_class *pipe_class;
-
- if (protocol != 0)
+ mode_t mode;
+
+ /* We have a set of `magic' protocols that allow the user to choose
+ the file type of the socket. The primary application is to make
+ sockets that pretend to be a FIFO, for the implementations of
+ pipes. */
+ if (protocol == 0)
+ mode = S_IFSOCK;
+ else if ((protocol & ~S_IFMT) == 0)
+ mode = protocol & S_IFMT;
+ else
return EPROTONOSUPPORT;
switch (sock_type)
@@ -52,7 +61,7 @@ S_socket_create (mach_port_t pf,
return ESOCKTNOSUPPORT;
}
- err = sock_create (pipe_class, &sock);
+ err = sock_create (pipe_class, mode, &sock);
if (!err)
{
err = sock_create_port (sock, port);
diff --git a/pflocal/sock.c b/pflocal/sock.c
index 350c7de8..dffd6bf7 100644
--- a/pflocal/sock.c
+++ b/pflocal/sock.c
@@ -1,6 +1,6 @@
/* Sock functions
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 2000 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.ai.mit.edu>
@@ -94,7 +94,7 @@ sock_acquire_write_pipe (struct sock *sock, struct pipe **pipe)
/* Return a new socket with the given pipe class in SOCK. */
error_t
-sock_create (struct pipe_class *pipe_class, struct sock **sock)
+sock_create (struct pipe_class *pipe_class, mode_t mode, struct sock **sock)
{
error_t err;
struct sock *new = malloc (sizeof (struct sock));
@@ -116,6 +116,7 @@ sock_create (struct pipe_class *pipe_class, struct sock **sock)
new->refs = 0;
new->flags = 0;
new->write_pipe = NULL;
+ new->mode = mode;
new->id = MACH_PORT_NULL;
new->listen_queue = NULL;
new->connect_queue = NULL;
@@ -155,7 +156,7 @@ _sock_norefs (struct sock *sock)
error_t
sock_clone (struct sock *template, struct sock **sock)
{
- error_t err = sock_create (template->pipe_class, sock);
+ error_t err = sock_create (template->pipe_class, template->mode, sock);
if (err)
return err;
diff --git a/pflocal/sock.h b/pflocal/sock.h
index e2852da0..94035759 100644
--- a/pflocal/sock.h
+++ b/pflocal/sock.h
@@ -1,6 +1,6 @@
/* Internal sockets
- Copyright (C) 1995, 1996, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1999, 2000 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.ai.mit.edu>
@@ -24,6 +24,7 @@
#include <assert.h>
#include <cthreads.h> /* For mutexes */
#include <sys/mman.h>
+#include <sys/types.h>
#include <hurd/ports.h>
@@ -60,6 +61,10 @@ struct sock
/* Last time the socket got frobbed. */
time_value_t change_time;
+ /* File mode as reported by stat. Usually this is S_ISOCK, but it
+ should be S_IFIFO for sockets (ab)used in a pipe. */
+ mode_t mode;
+
/* This socket's local address. Note that we don't hold any references on
ADDR, and depend on the addr zeroing our pointer if it goes away (which
is ok, as we can then just make up another address if necessary, and no
@@ -100,7 +105,8 @@ error_t sock_acquire_write_pipe (struct sock *sock, struct pipe **pipe);
error_t sock_connect (struct sock *sock1, struct sock *sock2);
/* Return a new socket with the given pipe class in SOCK. */
-error_t sock_create (struct pipe_class *pipe_class, struct sock **sock);
+error_t sock_create (struct pipe_class *pipe_class, mode_t mode,
+ struct sock **sock);
/* Free SOCK, assuming there are no more handle on it. */
void sock_free (struct sock *sock);