shithub: riscv

ref: 90032afb5f48daa2f05f572b645da92db945284f
dir: /sys/man/3/srv/

View raw version
.TH SRV 3 
.SH NAME
srv \- server registry
.SH SYNOPSIS
.nf
.BI "bind -c #s" $srvspec " /srv"

.BI /srv/ clone
.BI /srv/ id / ...
.BI /srv/ service1
.BI /srv/ service2
.I ...
.fi
.SH DESCRIPTION
The
.I srv
device provides a tree of directories holding
already-open channels to services.
In effect,
.I srv
is a bulletin board on which processes may post open file descriptors
to make them available to other processes.
.PP
To install a channel, create
a new file such as
.BI /srv/ myserv
and then write a text string (suitable for
.IR strtoul ;
see
.IR atof (2))
giving the file descriptor number of an open file.
Any process may then open
.BI /srv/ myserv
to acquire another reference to the open file that was registered.
.PP
An entry in
.I srv
holds a reference to the associated file even if no process has the
file open.  Removing the file from
.B /srv
releases that reference.
.PP
It is an error to write more than one number into a server file,
or to create a file with a name that is already being used.
.PP
Opening the
.I clone
file allocates a new service directory. Reading
.I clone
returns the
.I id
of the new directory.
This new service directory can then be accessed at
.BI /srv/ id .
Directories are recursive; each new service directory
contains its own
.I clone
file and sub-directories.
Directories can be walked from the root such as
.BI #s/ id1 / id2 / id3
which makes them globally addressable.
As a convention,
.B /lib/namespace
accepts the path to the service directory from the
environment variable
.IR $srvspec ,
making it possible to start a new namespace
using a specific service directory as a
starting point.
.SH EXAMPLE
To drop one end of a pipe into
.BR /srv ,
that is, to create a named pipe:
.IP
.EX
int fd, p[2];
char buf[32];

pipe(p);
fd = create("/srv/namedpipe", OWRITE, 0666);
fprint(fd, "%d", p[0]);
close(fd);
close(p[0]);
fprint(p[1], "hello");
.EE
.PP
At this point, any process may open and read
.B /srv/namedpipe
to receive the
.B hello
string.  Data written to
.B /srv/namedpipe
can be received by executing
.IP
.EX
read(p[1], buf, sizeof buf);
.EE
.PP
in the above process.
.PP
Create a disposable
.B /srv
and start a
.IR factotum (4)
and a
.IR rio (1)
in it.
.IP
.EX
<[3]/srv/clone{
	id=`{<[0=3]read}
	<[3=]@{ # close the clone fd
		rfork n
		bind -c /srv/$id /srv
		auth/factotum -s factotum
		rio
	}
}
.EE
.PP
.SH SOURCE
.B /sys/src/9/port/devsrv.c