blob: ab7dd31d131d838ae3893183af266745ec1aec3e [file] [log] [blame]
rscf305dff2003-10-13 17:18:52 +00001This is a port of some Plan 9 libraries and programs to Unix.
2
rscf305dff2003-10-13 17:18:52 +00003* Obtaining the source
4
rsc771ff2b2003-10-13 18:11:43 +00005Tarballs will be posted nightly (but only when there are updates!) at
rscf305dff2003-10-13 17:18:52 +00006
rscc4991212004-03-02 17:52:49 +00007 http://swtch.com/plan9port
rscf305dff2003-10-13 17:18:52 +00008
9/usr/local/plan9 is the suggested location to keep the software.
10All the paths in the tarball begin with plan9/, so it's okay to unpack it
11directly in /usr/local.
12
13You can use CVS to obtain the very latest version and stay up-to-date.
14See below.
15
16* Building
17
rscaf78a4c2004-03-02 23:11:58 +000018First, you need to extract the tarball or check out the CVS tree
19(see below for CVS). You should be able to install the tree anywhere
20-- tools check the environment variable $PLAN9 for the root of the
21tree. Most of them assume /usr/local/plan9 if $PLAN9 is not set.
rscf305dff2003-10-13 17:18:52 +000022
rscaf78a4c2004-03-02 23:11:58 +000023To build and install, cd into the plan9/ directory and run "./INSTALL".
24This will first build "mk" and then use mk to build the rest of the
25system, installing libraries in plan9/lib/ and binaries in plan9/bin/.
rsca463d2a2004-04-24 05:01:27 +000026There are a few shell scripts already included in bin -- B, E,
rscaf78a4c2004-03-02 23:11:58 +000027and samsave. Arguably these directories should be broken up by
28architecture so that
29
rsccb274432004-03-25 23:03:22 +000030During the initial build of mk, you will likely see a message like
31
32 Assembler messages:
33 Error: can't open getcallerpc-386.s for reading
34 getcallerpc-386.s: No error
35
36This is not a problem. The script tries to build getcallerpc
37from assembly and then C. As long as one of them succeeds, great.
38
39There are various directories that are not built by default.
40They are listed in the BUGGERED definitions in src/mkfile and src/cmd/mkfile.
41These aren't built because they're not quite ready for prime time.
42Either they don't actually build or they haven't been very well tested.
43
44As of this writing, factotum is buggered because it's not done yet,
45and Venti and vac are buggered because they've hardly been tested
46and are in a state of flux (they were both quite rewritten for the port).
47
48
rscaf78a4c2004-03-02 23:11:58 +000049* Writing programs
50
51The bin/ directory contains shell scripts 9a, 9c, 9l, and 9ar that mimic
52the Plan 9 tools pretty well, except in the object names: "9c x.c" produces
53x.o not x.9, and "9l x.o" produces "a.out" not "9.out" or "o.out".
54
55Mkfiles look substantially the same as in Plan 9, with slightly different
56names for the included rules. The most significant
57difference is that, since there is no autolinker, the Plan 9 libraries
58needed must be named explicitly. The variable SHORTLIBS can
59be used to list them without giving paths, e.g.:
60
61 SHORTLIBS=thread bio 9
62
63The default is "SHORTLIBS=9". (Libc is known as lib9; libregexp is
64known as libregexp9; the rest of the libraries retain their usual names.)
65
66Various function names (like open, accept, dup, malloc) are #defined in
67order to provide routines that mimic the Plan 9 interface better
68(for example, open handles the OCEXEC flag). Lib9.h contains these
69definitions. Function "foo" is #defined to "p9foo". These definitions
70can cause problems in the rare case that other Unix headers are needed
71as well. To avoid this, #define NOPLAN9DEFINES before including lib9.h,
72and then add the p9 prefix yourself for the renamed functions you wish to use.
73
74* 9P servers and "name spaces"
75
76A few Plan 9 programs, notably the plumber and acme, are heavily
77dependent on the use of 9P to interact with other programs. Rather
78than rewrite them, they have been left alone. Via the helper program 9pserve,
79they post a Unix domain socket with a well-known name (for example,
80"acme" or "plumb") in the directory /tmp/ns.$USER.$DISPLAY.
81Clients connect to that socket and interact via 9P. 9pserve takes
82care of muxing the various clients of that socket onto a single 9P
83conversation with the actual server, just like the kernel does on Plan 9.
84
85The choice of "namespace" directory is meant to provide a different
86name space for each X11 session a user has. The environment variable
87$NAMESPACE overrides this. The command "namespace" prints the
88current name space directory.
89
90In order to run normal Unix commands with their input or output
91connected to a 9P server, there is a new 9P request "openfd" whose
92response contains a real Unix file descriptor. 9pserve handles
93this request by sending a normal open to the real 9P server and
94sending back one side of a pipe. Then 9pserver forks a thread to
95ferry bytes back and forth between its end of the pipe and the 9P
96conversation. This works reasonably well, but has the drawback
97that reads are no longer "demand-driven" (the ferry thread issues
98the reads and fills the pipe regardless of whether the other end
99of the pipe is being read) and writes cannot return errors (writes
100to the pipe by the application will always succeed even though the
101write in the ferry thread might actually draw an interesting error).
102This doesn't cause too many problems in practice, but is worth
103keeping in mind.
104
105The command "9p" interacts with a given server to read or write
106a particular file. Run "9p" for a usage message.
107
108* Plumbing
109
110There is a plumber. It expects to find a plumbing rule file in
111$HOME/lib/plumbing. $PLAN9/plumb/initial.plumbing is a
112good start.
113
114Sam and acme interact with the plumber as they do on Plan 9.
115(If there is no plumber, sam falls back to a named pipe
116as it always has on Unix.) Unlike on Plan 9, there is a "web"
117command whose purpose is to load files or URLs in a running
118web browser. Right now, only Mozilla Firebird and Opera are
119supported, but it should be easy to add others to the script.
120The plumbing rules in $PLAN9/plumb/basic know to run "web"
121to handle URLs.
122
123Because sam and acme read from the plumber using file descriptors
124(and therefore the openfd hack described above), if the editor exits,
125this fact is not noted until the ferry thread tries to write the next
126plumbing message to the pipe. At this point the ferry thread closes
127the corresponding plumber fid, but the plumber thinks the message
128has been sent -- the message is lost. The message did serve a purpose --
129now the plumber knows there are no readers of the "edit" channel,
130so when it gets the next message it will start a new editor.
131This situation doesn't happen often, but it is worth keeping in mind.
132
133Both acme and sam try to raise themselves when they get plumbing
134messages.
135
136* Acme
137
138Acme works.
139
140Programs executed with the middle button interact with acme by the
141"openfd" trick described above. In a plain execution (as opposed
142to >prog or |prog), because of the delay introduced by the pipes,
143there is no guarantee that the command output will finish being
144displayed before the exit status notice is displayed. This can be
145annoying.
146
147There is a "win" shell. Of course, since we're on Unix, win can't
148tell when programs are reading from the tty, so proper input point
149management is right out the window.
rscf305dff2003-10-13 17:18:52 +0000150
151* Helping out
152
153If you'd like to help out, great!
154
rscaf78a4c2004-03-02 23:11:58 +0000155The TODO file contains a small list.
rscf305dff2003-10-13 17:18:52 +0000156
157If you port this code to other architectures, please share your changes
158so others can benefit. See PORTING for some notes.
159
160Please use diff -u or CVS (see below) to prepare patches.
161
162* CVS
163
164You can use CVS to keep your local copy up-to-date as we make
165changes and fix bugs. The idioms explained here are pretty much
166all you need to know about CVS.
167
168To check out from the anonymous CVS repository, use
169
170 cd /usr/local
171 >$HOME/.cvspass
172 cvs -d :pserver:anoncvs@cvs.pdos.lcs.mit.edu:/cvs login
173 cvs -d :pserver:anoncvs@cvs.pdos.lcs.mit.edu:/cvs checkout plan9
174
175When prompted for a password, just hit enter.
176
rsccb274432004-03-25 23:03:22 +0000177If there is already a /usr/local/plan9 directory (from a previous
178unpacking), remove it or move it out of the way. You need write
179access to /usr/local in order to run the checkout, but after that
180you'll only need write access to the plan9 subtree. I typically run
181the initial checkout as root and then chown -R rsc plan9 so that
182I can do things as rsc afterward.
183
rscf305dff2003-10-13 17:18:52 +0000184From then on, when you want to update, you can do
185
186 cd /usr/local/plan9
187 cvs update -dAP
188
189If there are conflicts between changes you have made locally
190and changes on the server, cvs will warn about them and leave
191them clearly marked in the updated files.
192
193If you change something and want to submit the change (please do!),
194you can run
195
196 cd /usr/local/plan9
197 cvs diff -u
198
199to generate the diff in a format that will be easy to apply.
200(You can also use this to see what you've changed.)
201
rsccb274432004-03-25 23:03:22 +0000202 cvs diff -D20040101 -u
203
204shows you differences txixt your tree and the repository
205as of January 1, 2004.
206
rscf305dff2003-10-13 17:18:52 +0000207Running the cvs commands in /usr/local/plan9 makes them
208apply to the whole tree. Running them in a subdirectory applies
209only to the code rooted there in the code.
210
211There's not much magical about /usr/local/plan9. If you
212check out the tree in some other directory, it should work
213just as well.
214
215Thanks.
216
217Russ Cox <rsc@swtch.com>