SRV(3) SRV(3)
NAME
srv - server registry
SYNOPSIS
bind -c #s$srvspec /srv
/srv/clone
/srv/id/...
/srv/service1
/srv/service2
...
DESCRIPTION
The srv device provides a tree of directories holding
already-open channels to services. In effect, srv is a bul-
letin board on which processes may post open file descrip-
tors to make them available to other processes.
To install a channel, create a new file such as /srv/myserv
and then write a text string (suitable for strtoul; see
atof(2)) giving the file descriptor number of an open file.
Any process may then open /srv/myserv to acquire another
reference to the open file that was registered.
An entry in srv holds a reference to the associated file
even if no process has the file open. Removing the file
from /srv releases that reference.
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.
Opening the clone file allocates a new service directory.
Reading clone returns the id of the new directory. This new
service directory can then be accessed at /srv/id. Directo-
ries are recursive; each new service directory contains its
own clone file and sub-directories. Directories can be
walked from the root such as #s/id1/id2/id3 which makes them
globally addressable. As a convention, /lib/namespace
accepts the path to the service directory from the environ-
ment variable $srvspec, making it possible to start a new
namespace using a specific service directory as a starting
point.
EXAMPLE
To drop one end of a pipe into /srv, that is, to create a
named pipe:
int fd, p[2];
char buf[32];
Page 1 Plan 9 (printed 10/29/25)
SRV(3) SRV(3)
pipe(p);
fd = create("/srv/namedpipe", OWRITE, 0666);
fprint(fd, "%d", p[0]);
close(fd);
close(p[0]);
fprint(p[1], "hello");
At this point, any process may open and read /srv/namedpipe
to receive the hello string. Data written to /srv/namedpipe
can be received by executing
read(p[1], buf, sizeof buf);
in the above process.
Create a disposable /srv and start a factotum(4) and a
rio(1) in it.
<[3]/srv/clone{
id=`{<[0=3]read}
<[3=]@{ # close the clone fd
rfork n
bind -c /srv/$id /srv
auth/factotum -s factotum
rio
}
}
SOURCE
/sys/src/9/port/devsrv.c
Page 2 Plan 9 (printed 10/29/25)