1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
.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.
.SH SOURCE
.B /sys/src/9/port/devsrv.c
|