1
0

plumb.ms 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  1. .TL
  2. Plumbing and Other Utilities
  3. .AU
  4. Rob Pike
  5. .AI
  6. .MH
  7. .AB
  8. .LP
  9. Plumbing is a new mechanism for inter-process communication in Plan 9,
  10. specifically the passing of messages between interactive programs as part of
  11. the user interface.
  12. Although plumbing shares some properties with familiar notions
  13. such as cut and paste,
  14. it offers a more general data exchange mechanism without imposing
  15. a particular user interface.
  16. .LP
  17. The core of the plumbing system is a program called the
  18. .I plumber ,
  19. which handles all messages and dispatches and reformats them
  20. according to configuration rules written in a special-purpose language.
  21. This approach allows the contents and context of a piece of data to define how
  22. it is handled.
  23. Unlike with drag and drop or cut and paste,
  24. the user doesn't need to deliver the data;
  25. the contents of a plumbing message, as interpreted by the plumbing rules,
  26. determine its destination.
  27. .LP
  28. The plumber has an unusual architecture: it is a language-driven file server.
  29. This design has distinct advantages.
  30. It makes plumbing easy to add to an existing, Unix-like command environment;
  31. it guarantees uniform handling of inter-application messages;
  32. it off-loads from those applications most of the work of extracting and dispatching messages;
  33. and it works transparently across a network.
  34. .AE
  35. .SH
  36. Introduction
  37. .LP
  38. Data moves from program to program in myriad ways.
  39. Command-line arguments,
  40. shell pipe lines,
  41. cut and paste,
  42. drag and drop, and other user interface techniques all provide some form
  43. of interprocess communication.
  44. Then there are tricks associated with special domains,
  45. such as HTML hyperlinks or the heuristics mail readers
  46. use to highlight URLs embedded in mail messages.
  47. Some systems provide implicit ways to automate the attachment of program to data\(emthe
  48. best known examples are probably the resource forks in MacOS and the
  49. file name extension `associations' in Microsoft Windows\(embut in practice
  50. humans must too often carry their data from program to program.
  51. .LP
  52. Why should a human do the work?
  53. Usually there is one obvious thing to do with a piece of data,
  54. and the data itself suggests what this is.
  55. Resource forks and associations speak to this issue directly, but statically and narrowly and with
  56. little opportunity to control the behavior.
  57. Mechanisms with more generality,
  58. such as cut and paste or drag and drop, demand too much manipulation by
  59. the user and are (therefore) too error-prone.
  60. .LP
  61. We want a system that, given a piece of data,
  62. hands it to the appropriate application by default with little or no human intervention,
  63. while still permitting the user to override the defaults if desired.
  64. .LP
  65. The plumbing system is an attempt to address some of these issues in a single,
  66. coherent, central way.
  67. It provides a mechanism for
  68. formatting and sending arbitrary messages between applications,
  69. typically interactive programs such as text editors, web browsers, and the window system,
  70. under the control of a central message-handling server called the
  71. .I plumber .
  72. Interactive programs provide application-specific connections to the plumber,
  73. triggering with minimal user action the transfer of data or control to other programs.
  74. The result is similar to a hypertext system in which all the links are implicit,
  75. extracted automatically by examining the data and the user's actions.
  76. It obviates
  77. cut and paste and other such hand-driven interprocess communication mechanisms.
  78. Plumbing delivers the goods to the right place automatically.
  79. .SH
  80. Overview
  81. .LP
  82. The plumber is implemented as a Plan 9 file server [Pike93];
  83. programs send messages by writing them to the plumber's file
  84. .CW /mnt/plumb/send ,
  85. and receive messages by reading them from
  86. .I ports ,
  87. which are other plumber files in
  88. .CW /mnt/plumb .
  89. For example,
  90. .CW /mnt/plumb/edit
  91. is by convention the file from which a text editor reads messages requesting it to
  92. open and display a file for editing.
  93. (See Figure 1.)
  94. .KF
  95. .PS
  96. down
  97. P1: ellipse "ProgramA"
  98. move
  99. P2: ellipse "ProgramB"
  100. move
  101. P3: ellipse "ProgramC"
  102. right
  103. INVIS: box wid 1.3 invis at P2.e
  104. SEND: arrow from INVIS.e "\f(CWsend \fP" ""
  105. arrow -> right 0.2 from P1.e; spline -> right 0.2 then down 1 to SEND.w
  106. arrow -> right 0.2 from P2.e; arrow -> to SEND.w
  107. arrow -> right 0.2 from P3.e; spline -> right 0.2 then up 1 to SEND.w
  108. right
  109. PL: box height 1 "plumber" with .w at SEND.e
  110. A3: arrow 0.8 -> "\f(CWimage\fP" ""; arrow ->
  111. O3: ellipse "Viewer"
  112. O2: ellipse "Browser" with .s at O3.n + (0, 0.1)
  113. O1: ellipse "Editor" with .s at O2.n + (0, 0.1)
  114. O4: ellipse "Faces" with .n at O3.s + (0, -0.1)
  115. O5: ellipse "..." with .n at O4.s + (0, -0.1)
  116. right
  117. A1: arrow 0.8 -> "\f(CWedit\fP" "" from PL.e + (0, .4); spline -> right 0.15 then up 0.7 then to O1.w
  118. right
  119. A2: arrow 0.8 -> "\f(CWweb\fP" "" from PL.e + (0, .2); spline -> right 0.3 then up 0.3 then to O2.w
  120. right
  121. A4: arrow 0.8 -> "\f(CWnewmail\fP" "" from PL.e + (0, -.2); spline -> right 0.3 then down 0.3 then to O4.w
  122. right
  123. A5: arrow 0.8 -> "\f(CW...\fP" "" from PL.e + (0, -.4); spline -> right 0.15 then down 0.7 then to O5.w
  124. .PE
  125. .IP
  126. .ps -1
  127. Figure 1. The plumber controls the flow of messages between applications.
  128. Programs write to the file
  129. .CW send
  130. and receive on `ports' of various names representing services such as
  131. .CW edit
  132. or
  133. .CW web .
  134. Although the figure doesn't illustrate it, some programs may both send and receive messages,
  135. and some ports are read by multiple applications.
  136. .sp
  137. .KE
  138. .LP
  139. The plumber takes messages from the
  140. .CW send
  141. file and interprets their contents using rules defined by
  142. a special-purpose pattern-action language.
  143. The language specifies any rewriting of the message that is to be done by the plumber
  144. and defines how to dispose of a message, such as by sending it to a port or
  145. starting a new process to handle it.
  146. .LP
  147. The behavior is best described by example.
  148. Imagine that the user has, in a terminal emulator window,
  149. just run a compilation that has failed:
  150. .P1
  151. % make
  152. cc -c rmstar.c
  153. rmstar.c:32: syntax error
  154. \&...
  155. .P2
  156. The user points the typing cursor somewhere in the string
  157. .CW rmstar.c:32:
  158. and executes the
  159. .CW plumb
  160. menu entry.
  161. This causes the terminal emulator to format a plumbing message
  162. containing the entire string surrounding the cursor,
  163. .CW rmstar:32: ,
  164. and to write it to
  165. .CW /mnt/plumb/send .
  166. The plumber receives this message and compares it sequentially to the various
  167. patterns in its configuration.
  168. Eventually, it will find one that breaks the string into pieces,
  169. .CW rmstar.c ,
  170. a colon,
  171. .CW 32 ,
  172. and the final colon.
  173. Other associated patterns verify that
  174. .CW rmstar.c
  175. is a file in the current directory of the program generating
  176. the message, and that
  177. .CW 32
  178. looks like a line number within it.
  179. The plumber rewrites the message,
  180. setting the data to the string
  181. .CW rmstar.c
  182. and attaching an indication that
  183. .CW 32
  184. is a line number to display.
  185. Finally, it sends the resulting message to the
  186. .CW edit
  187. port.
  188. The text editor picks up the message, opens
  189. .CW rmstar.c
  190. (if it's not already open) and highlights line 32, the location of the syntax error.
  191. .LP
  192. From the user's point of view, this process is simple: the error message appears,
  193. it is `plumbed', and the editor jumps to the problem.
  194. .LP
  195. Of course, there are many different ways to cause compiler messages to
  196. pop up the source of an error,
  197. but the design of the plumber addresses more general issues than the specific
  198. goal of shortening the compile/debug/edit cycle.
  199. It facilitates the general exchange of data among programs, interactive or otherwise,
  200. throughout the environment, and its
  201. architecture\(ema central, language-driven file server\(emalthough
  202. unusual, has distinct advantages.
  203. It makes plumbing easy to add to an existing, Unix-like command environment;
  204. it guarantees uniform handling of inter-application messages;
  205. it off-loads from those applications most of the work of extracting and dispatching messages;
  206. and it works transparently and effortlessly across a network.
  207. .LP
  208. This paper is organized bottom-up, beginning with the format of the messages
  209. and proceeding through the plumbing language, the handling of messages,
  210. and the interactive user interface.
  211. The last sections discuss the implications of the design
  212. and compare the plumbing system to other environments that
  213. provide similar services.
  214. .SH
  215. Format of messages
  216. .LP
  217. Since the language that controls the plumber is defined in terms of the
  218. contents of plumbing messages, we begin by describing their layout.
  219. .LP
  220. Plumbing messages have a fixed-format textual
  221. header followed by a free-format data section.
  222. The header consists of six lines of text, in set order,
  223. each specifying a property of the message.
  224. Any line may be blank except the last, which is the length of the data portion of the
  225. message, as a decimal string.
  226. The lines are, in order:
  227. .IP
  228. The source application, the name of the program generating the message.
  229. .IP
  230. The destination port, the name of the port to which the messages should be sent.
  231. .IP
  232. The working directory in which the message was generated.
  233. .IP
  234. The type of the data, analogous to a MIME type, such as
  235. .CW text
  236. or
  237. .CW image/gif .
  238. .IP
  239. Attributes of the message, given as blank-separated
  240. .I name\f(CW=\fPvalue
  241. pairs.
  242. The values may be quoted to protect
  243. blanks or quotes; values may not contain newlines.
  244. .IP
  245. The length of the data section, in bytes.
  246. .LP
  247. Here is a sample message, one that (conventionally) tells the editor to open the file
  248. .CW /usr/rob/src/mem.c
  249. and display line
  250. 27 within it:
  251. .P1
  252. plumbtest
  253. edit
  254. /usr/rob/src
  255. text
  256. addr=27
  257. 5
  258. mem.c
  259. .P2
  260. Because in general it need not be text, the data section of the message has no terminating newline.
  261. .LP
  262. A library interface simplifies the processing of messages by translating them
  263. to and from a data structure,
  264. .CW Plumbmsg ,
  265. defined like this:
  266. .P1
  267. .ta 4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n +4n
  268. typedef struct Plumbattr Plumbattr;
  269. typedef struct Plumbmsg Plumbmsg;
  270. struct Plumbmsg
  271. {
  272. char *src; /* source application */
  273. char *dst; /* destination port */
  274. char *wdir; /* working directory */
  275. char *type; /* type of data */
  276. Plumbattr *attr; /* attribute list */
  277. int ndata; /* #bytes of data */
  278. char *data;
  279. };
  280. struct Plumbattr
  281. {
  282. char *name;
  283. char *value;
  284. Plumbattr *next;
  285. };
  286. .P2
  287. The library also includes routines to send a message, receive a message,
  288. manipulate the attribute list, and so on.
  289. .SH
  290. The Language
  291. .LP
  292. An instance of the plumber runs for each user on each terminal or workstation.
  293. It
  294. begins by reading its rules from the file
  295. .CW lib/plumbing
  296. in the user's home directory,
  297. which in turn may use
  298. .CW include
  299. statements to interpolate macro definitions and
  300. rules from standard plumbing rule libraries stored in
  301. .CW /sys/lib/plumb .
  302. .LP
  303. The rules control the processing of messages.
  304. They are written in
  305. a pattern-action language comprising a sequence of blank-line-separated
  306. .I rule
  307. .I sets ,
  308. each of which contains one or more
  309. .I patterns
  310. followed by one or more
  311. .I actions .
  312. Each incoming message is compared against the rule sets in order.
  313. If all the patterns within a rule set succeed,
  314. one of the associated actions is taken and processing completes.
  315. .LP
  316. The syntax of the language is straightforward.
  317. Each rule (pattern or action) has three components, separated by white space:
  318. an
  319. .I object ,
  320. a
  321. .I verb ,
  322. and optional
  323. .I arguments .
  324. The object
  325. identifies a part of the message, such as
  326. the source application
  327. .CW src ), (
  328. or the data
  329. portion of the message
  330. .CW data ), (
  331. or the rule's own arguments
  332. .CW arg ); (
  333. or it is the keyword
  334. .CW plumb ,
  335. which introduces an action.
  336. The verb specifies an operation to perform on the object, such as the word
  337. .CW is ' `
  338. to require precise equality between the object and the argument, or
  339. .CW isdir ' `
  340. to require that the object be the name of a directory.
  341. .LP
  342. For instance, this rule set sends messages containing the names of files
  343. ending in
  344. .CW .gif ,
  345. .CW .jpg ,
  346. etc. to a program,
  347. .CW page ,
  348. to display them; it is analogous to a Windows association rule:
  349. .P1
  350. # image files go to page
  351. type is text
  352. data matches '[a-zA-Z0-9_\e-./]+'
  353. data matches '([a-zA-Z0-9_\e-./]+)\e.(jpe?g|gif|bit|tiff|ppm)'
  354. arg isfile $0
  355. plumb to image
  356. plumb client page -wi
  357. .P2
  358. (Lines beginning with
  359. .CW #
  360. are commentary.)
  361. Consider how this rule handles the following message, annotated down the left column for clarity:
  362. .P1
  363. .ta 10n
  364. \f2src\fP plumbtest
  365. \f2dst\fP
  366. \f2wdir\fP /usr/rob/pics
  367. \f2type\fP text
  368. \f2attr\fP
  369. \f2ndata\fP 9
  370. \f2data\fP horse.gif
  371. .P2
  372. The
  373. .CW is
  374. verb specifies a precise match, and the
  375. .CW type
  376. field of the message is the string
  377. .CW text ,
  378. so the first pattern succeeds.
  379. The
  380. .CW matches
  381. verb invokes a regular expression pattern match of the object (here
  382. .CW data )
  383. against the argument pattern.
  384. Both
  385. .CW matches
  386. patterns in this rule set will succeed, and in the process set the variables
  387. .CW $0
  388. to the matched string,
  389. .CW $1
  390. to the first parenthesized submatch, and so on (analogous to
  391. .CW & ,
  392. .CW \e1 ,
  393. etc. in
  394. .CW ed 's
  395. regular expressions).
  396. The pattern
  397. .CW arg
  398. .CW isfile
  399. .CW $0
  400. verifies that the named file,
  401. .CW horse.gif ,
  402. is an actual file in the directory
  403. .CW /usr/rob/pics .
  404. If all the patterns succeed, one of the actions will be executed.
  405. .LP
  406. There are two actions in this rule set.
  407. The
  408. .CW plumb
  409. .CW to
  410. rule specifies
  411. .CW image
  412. as the destination port of the message.
  413. By convention, the plumber mounts its services in the directory
  414. .CW /mnt/plumb ,
  415. so in this case if the file
  416. .CW /mnt/plumb/image
  417. has been opened, the message will be made available to the program reading from it.
  418. Note that the message does not name a port, but the rule set that matches
  419. the message does, and that is sufficient to dispatch the message.
  420. If on the other hand a message matches no rule but has an explicit port mentioned,
  421. that too is sufficient.
  422. .LP
  423. If no client has opened the
  424. .CW image
  425. port,
  426. that is, if the program
  427. .CW page
  428. is not already running, the
  429. .CW plumb
  430. .CW client
  431. action gives the execution script to start the application
  432. and send the message on its way; the
  433. .CW -wi
  434. arguments tell
  435. .CW page
  436. to create a window and to receive its initial arguments from the plumbing port.
  437. The process by which the plumber starts a program is described in more detail in the next section.
  438. .LP
  439. It may seem odd that there are two
  440. .CW matches
  441. rules in this example.
  442. The reason is related to the way the plumber can use the rules themselves
  443. to refine the
  444. .I data
  445. in the message, somewhat in the manner of Structural Regular Expressions [Pike87a].
  446. For example, consider what happens if the cursor is at the last character of
  447. .P1
  448. % make nightmare>horse.gif
  449. .P2
  450. and the user asks to plumb what the cursor is pointing at.
  451. The program creating the plumbing
  452. message\(emin this case the terminal emulator running the window\(emcan send the
  453. entire white-space-delimited string
  454. .CW nightmare>horse.gif
  455. or even the entire line, and the combination of
  456. .CW matches
  457. rules can determine that the user was referring to the string
  458. .CW horse.gif .
  459. The user could of course select the entire string
  460. .CW horse.gif ,
  461. but it's more convenient just to point in the general location and let the machine
  462. figure out what should be done.
  463. The process is as follows.
  464. .LP
  465. The application generating the message adds a special attribute to the message, named
  466. .CW click ,
  467. whose numerical value is the offset of the cursor\(emthe selection point\(emwithin the data string.
  468. This attribute tells the plumber two things:
  469. first, that the regular expressions in
  470. .CW matches
  471. rules should be used to identify the relevant data;
  472. and second, approximately where the relevant data lies.
  473. The plumber
  474. will then use the first
  475. .CW matches
  476. pattern to identify the longest leftmost match that touches the cursor, which will extract the string
  477. .CW horse.gif ,
  478. and the second pattern will then verify that that names a picture file.
  479. The rule set succeeds and the data is winnowed to the matching substring
  480. before being sent to its destination.
  481. .LP
  482. Each
  483. .CW matches
  484. pattern within a given rule set must match the same portion of the string, which
  485. guarantees that the rule set fails to match a string for which the
  486. second pattern matches only a portion.
  487. For instance, our example rule set should not execute if the data is the string
  488. .CW horse.gift ,
  489. and although the first pattern will match
  490. .CW horse.gift ,
  491. the second will match only
  492. .CW horse.gif
  493. and the rule set will fail.
  494. .LP
  495. The same approach of multiple
  496. .CW matches
  497. rules can be used to exclude, for instance, a terminal period from
  498. a file name or URL, so a file name or URL at the end of a sentence is recognized properly.
  499. .LP
  500. If a
  501. .CW click
  502. attribute is not specified, all patterns must match the entire string,
  503. so the user has an option:
  504. he or she may select exactly what data to send,
  505. or may instead indicate where the data is by clicking the selection button on the mouse
  506. and letting the machine locate the URL or image file name within the text.
  507. In other words,
  508. the user can control the contents of the message precisely when required,
  509. but the default, simplest action in the user interface does the right thing most of the time.
  510. .SH
  511. How Messages are Handled in the Plumber
  512. .LP
  513. An application creates a message header, fills in whatever fields it wishes to define,
  514. attaches the data, and writes the result to the file
  515. .CW send
  516. in the plumber's service directory,
  517. .CW /mnt/plumb .
  518. The plumber receives the message and applies the plumbing rules successively to it.
  519. When a rule set matches, the message is dispatched as indicated by that rule set
  520. and processing continues with the next message.
  521. If no rule set matches the message, the plumber indicates this by returning a write
  522. error to the application, that is, the write to
  523. .CW /mnt/plumb/send
  524. fails, with the resulting error string
  525. describing the failure.
  526. (Plan 9 uses strings rather than pre-defined numbers to describe error conditions.)
  527. Thus a program can discover whether a plumbing message has been sent successfully.
  528. .LP
  529. After a matching rule set has been identified, the plumber applies a series of rewriting
  530. steps to the message. Some rewritings are defined by the rule set; others are implicit.
  531. For example, if the message does not specify a destination port, the outgoing message
  532. will be rewritten to identify it.
  533. If the message does specify the port, the rule set will only match if any
  534. .CW plumb
  535. .CW to
  536. action in the rule set names the same port.
  537. (If it matches no rule sets, but mentions a port, it will be sent there unmodified.)
  538. .LP
  539. The rule set may contain actions that explicitly rewrite components of the message.
  540. These may modify the attribute list or replace the data section of the message.
  541. Here is a sample rule set that does both.
  542. It matches strings of the form
  543. .CW plumb.h
  544. or
  545. .CW plumb.h:27 .
  546. If that string identifies a file in the standard C include directory,
  547. .CW /sys/include ,
  548. perhaps with an optional line number, the outgoing message
  549. is rewritten to contain the full path name and an attribute,
  550. .CW addr ,
  551. to hold the line number:
  552. .P1
  553. # .h files are looked up in /sys/include and passed to edit
  554. type is text
  555. data matches '([a-zA-Z0-9]+\e.h)(:([0-9]+))?'
  556. arg isfile /sys/include/$1
  557. data set /sys/include/$1
  558. attr add addr=$3
  559. plumb to edit
  560. .P2
  561. The
  562. .CW data
  563. .CW set
  564. rule replaces the contents of the data, and the
  565. .CW attr
  566. .CW add
  567. rule adds a new attribute to the message.
  568. The intent of this rule is to permit one to plumb an include file name in a C program
  569. to trigger the opening of that file, perhaps at a specified line, in the text editor.
  570. A variant of this rule, discussed below,
  571. tells the editor how to interpret syntax errors from the compiler,
  572. or the output of
  573. .CW grep
  574. .CW -n ,
  575. both of which use a fixed syntax
  576. .I file\f(CW:\fPline
  577. to identify a line of source.
  578. .LP
  579. The Plan 9 text editors interpret the
  580. .CW addr
  581. attribute as the definition of which portion of the file to display.
  582. In fact, the real rule includes a richer definition of the address syntax,
  583. so one may plumb strings such as
  584. .CW plumb.h:/plumbsend
  585. (using a regular expression after the
  586. .CW / )
  587. to pop up the declaration of a function in a C header file.
  588. .LP
  589. Another form of rewriting is that the plumber may modify the attribute list of
  590. the message to clarify how to handle the message.
  591. The primary example of this involves the treatment of the
  592. .CW click
  593. attribute, described in the previous section.
  594. If the message contains a
  595. .CW click
  596. attribute and the matching rule set uses it to extract the matching substring from the data,
  597. the plumber
  598. deletes the
  599. .CW click
  600. attribute and replaces the data with the matching substring.
  601. .LP
  602. Once the message is rewritten, the actions of the matching rule set are examined.
  603. If the rule set contains a
  604. .CW plumb
  605. .CW to
  606. action and the corresponding port is open\(emthat is, if a program is already reading
  607. from that port\(emthe message is delivered to the port.
  608. The application will receive the message and handle it as it sees fit.
  609. If the port is not open, a
  610. .CW plumb
  611. .CW start
  612. or
  613. .CW plumb
  614. .CW client
  615. action will start a new program to handle the message.
  616. .LP
  617. The
  618. .CW plumb
  619. .CW start
  620. action is the simpler: its argument specifies a command to run
  621. instead of passing on the message; the message is discarded.
  622. Here for instance is a rule that, given the process id (pid) of an existing process,
  623. starts the
  624. .CW acid
  625. debugger [Wint94] in a new window to examine that process:
  626. .P1
  627. # processes go to acid (assuming strlen(pid) >= 2)
  628. type is text
  629. data matches '[a-zA-Z0-9.:_\e-/]+'
  630. data matches '[0-9][0-9]+'
  631. arg isdir /proc/$0
  632. plumb start window acid $0
  633. .P2
  634. (Note the use of multiple
  635. .CW matches
  636. rules to avoid misfires from strings like
  637. .CW party.1999 .)
  638. The
  639. .CW arg
  640. .CW isdir
  641. rule checks that the pid represents a running process (or broken one; Plan 9 does not create
  642. .CW core
  643. files but leaves broken processes around for debugging) by checking that the process file
  644. system has a directory for that pid [Kill84].
  645. Using this rule, one may plumb the pid string printed by the
  646. .CW ps
  647. command or by the operating system when the program breaks;
  648. the debugger will then start automatically.
  649. .LP
  650. The other startup action,
  651. .CW plumb
  652. .CW client ,
  653. is used when a program will read messages from the plumbing port.
  654. For example,
  655. text editors can read files specified as command arguments, so one could use a
  656. .CW plumb
  657. .CW start
  658. rule to begin editing a file.
  659. If, however, the editor will read messages from the
  660. .CW edit
  661. plumbing port, letting it read the message
  662. from the port insures that it uses other information in the message,
  663. such as the line number to display.
  664. The
  665. .CW plumb
  666. .CW client
  667. action is therefore like
  668. .CW plumb
  669. .CW start ,
  670. but keeps the message around for delivery when the application opens the port.
  671. Here is the full rule set to pass a regular file to the text editor:
  672. .P1
  673. # existing files, possibly tagged by address, go to editor
  674. type is text
  675. data matches '([.a-zA-Z0-9_/\e-]*[a-zA-Z0-9_/\e-])('$addr')?'
  676. arg isfile $1
  677. data set $1
  678. attr add addr=$3
  679. plumb to edit
  680. plumb client window $editor
  681. .P2
  682. If the editor is already running, the
  683. .CW plumb
  684. .CW to
  685. rule causes it to receive the message on the port.
  686. If not,
  687. the command
  688. .CW window "" `
  689. .CW $editor '
  690. will create a new window (using the Plan 9 program
  691. .CW window )
  692. to run the editor, and once that starts it will open the
  693. .CW edit
  694. plumbing port as usual and discover this first message already waiting.
  695. .LP
  696. The variables
  697. .CW $editor
  698. and
  699. .CW $addr
  700. in this rule set
  701. are macros defined in the plumbing rules file; they specify the name of the user's favorite text editor
  702. and a regular expression
  703. that matches that editor's address syntax, such as line numbers and patterns.
  704. This rule set lives in a library of shared plumbing rules that
  705. users' private rules can build on,
  706. so the rule set needs to be adaptable to different editors and their address syntax.
  707. The macro definitions for Acme and Sam [Pike94,Pike87b] look like this:
  708. .P1
  709. editor=acme
  710. # or editor=sam
  711. addrelem='((#?[0-9]+)|(/[A-Za-z0-9_\e^]+/?)|[.$])'
  712. addr=:($addrelem([,;+\e-]$addrelem)*)
  713. .P2
  714. .LP
  715. Finally, the application reads the message from the appropriate port, such as
  716. .CW /mnt/plumb/edit ,
  717. unpacks it, and goes to work.
  718. .SH
  719. Message Delivery
  720. .LP
  721. In summary, a message is delivered by writing it to the
  722. .CW send
  723. file and having the plumber, perhaps after some rewriting, send it to the destination
  724. port or start a new application to handle it.
  725. If no destination can be found by the plumber, the original write to the
  726. .CW send
  727. file will fail, and the application will know the message could not be delivered.
  728. .LP
  729. If multiple applications are reading from the destination port, each will receive
  730. an identical copy of the message; that is, the plumber implements fan-out.
  731. The number of messages delivered is equal to the number of clients that have
  732. opened the destination port.
  733. The plumber queues the messages and makes sure that each application that opened
  734. the port before the message was written gets exactly one copy.
  735. .LP
  736. This design minimizes blocking in the sending applications, since the write to the
  737. .CW send
  738. file can complete as soon as the message has been queued for the appropriate port.
  739. If the plumber waited for the message to be read by the recipient, the sender could
  740. block unnecessarily.
  741. Unfortunately, this design also means that there is no way for a sender to know when
  742. the message has been handled; in fact, there are cases when
  743. the message will not be delivered at all, such as if the recipient exits while there are
  744. still messages in the queue.
  745. Since the plumber is part of a user interface, and not
  746. an autonomous message delivery system,
  747. the decision was made to give the
  748. non-blocking property priority over reliability of message delivery.
  749. In practice, this tradeoff has worked out well:
  750. applications almost always know when a message has failed to be delivered (the
  751. .CW write
  752. fails because no destination could be found),
  753. and those occasions when the sender believes incorrectly that the message has been delivered
  754. are both extremely rare and easily recognized by the user\(emusually because the recipient
  755. application has exited.
  756. .SH
  757. The Rules File
  758. .LP
  759. The plumber begins execution by reading the user's startup plumbing rules file,
  760. .CW lib/plumbing .
  761. Since the plumber is implemented as a file server, it can also present its current rules
  762. as a dynamic file, a design that provides an easily understood way to maintain the rules.
  763. .LP
  764. The file
  765. .CW /mnt/plumb/rules
  766. is the text of the rule set the plumber is currently using,
  767. and it may be edited like a regular file to update those rules.
  768. To clear the rules, truncate that file;
  769. to add a new rule set, append to it:
  770. .P1
  771. % echo 'type is text
  772. data is self-destruct
  773. plumb start rm -rf $HOME' >> /mnt/plumb/rules
  774. .P2
  775. This rule set will take effect immediately.
  776. If it has a syntax error, the write will fail with an error message from the plumber,
  777. such as `malformed rule' or 'undefined verb'.
  778. .LP
  779. To restore the plumber to its startup configuration,
  780. .P1
  781. % cp /usr/$user/lib/plumbing /mnt/plumb/rules
  782. .P2
  783. For more sophisticated changes,
  784. one can of course use a regular text editor to modify
  785. .CW /mnt/plumb/rules .
  786. .LP
  787. This simple way of maintaining an active service could profitably be adopted by other systems.
  788. It avoids the need to reboot, to update registries with special tools, or to send asynchronous signals
  789. to critical programs.
  790. .SH
  791. The User Interface
  792. .LP
  793. One unusual property of the plumbing system is that
  794. the user interface that programs provide to access it can vary considerably, yet
  795. the result is nonetheless a unifying force in the environment.
  796. Shells talk to editors, image viewers, and web browsers; debuggers talk to editors;
  797. editors talk to themselves; and the window system talks to everybody.
  798. .LP
  799. The plumber grew out of some of the ideas of the Acme editor/window-system/user interface [Pike94],
  800. in particular its `acquisition' feature.
  801. With a three-button mouse, clicking the right button in Acme on a piece of text tells Acme to
  802. get the thing being pointed to.
  803. If it is a file name, open the file;
  804. if it is a directory, open a viewer for its contents;
  805. if a line number, go to that line;
  806. if a regular expression, search for it.
  807. This one-click access to anything describable textually was very powerful but had several
  808. limitations, of which the most important were that Acme's rules for interpreting the
  809. text (that is, the implicit hyperlinks) were hard-wired and inflexible, and
  810. that they only applied to and within Acme itself.
  811. One could not, for example, use Acme's power to open an image file, since Acme is
  812. a text-only system.
  813. .LP
  814. The plumber addresses these limitations, even with Acme itself:
  815. Acme now uses the plumber to interpret the right button clicks for it.
  816. When the right button is clicked on some text,
  817. Acme constructs a plumbing message much as described above,
  818. using the
  819. .CW click
  820. attribute and the white-space-delimited text surrounding the click.
  821. It then writes the message to the plumber; if the write succeeds, all is well.
  822. If not, it falls back to its original, internal rules, which will result in a context search
  823. for the word within the current document.
  824. .LP
  825. If the message is sent successfully, the recipient is likely to be Acme itself, of course:
  826. the request may be to open a file, for example.
  827. Thus Acme has turned the plumber into an external component of its own operation,
  828. while expanding the possibilities; the operation might be to start an image viewer to
  829. open a picture file, something Acme cannot do itself.
  830. The plumber expands the power of Acme's original user interface.
  831. .LP
  832. Traditional menu-driven programs such as the text editor Sam [Pike87b] and the default
  833. shell window of the window
  834. system
  835. .CW 8½
  836. [Pike91] cannot dedicate a mouse button solely to plumbing, but they can certainly
  837. dedicate a menu entry.
  838. The editing menu for such programs now contains an entry,
  839. .CW plumb ,
  840. that creates a plumbing message using the current selection.
  841. (Acme manages to send a message by clicking on the text with one button;
  842. other programs require a click with the select button and then a menu operation.)
  843. For example, after this happens in a shell window:
  844. .P1
  845. % make
  846. cc -c shaney.c
  847. shaney.c:232: i undefined
  848. \&...
  849. .P2
  850. one can click anywhere on the string
  851. .CW shaney.c:232 ,
  852. execute the
  853. .CW plumb
  854. menu entry, and have line 232 appear in the text editor, be it Sam or Acme\(emwhichever has the
  855. .CW edit
  856. port open.
  857. (If this were an Acme shell window, it would be sufficient to right-click on the string.)
  858. .LP
  859. [An interesting side line is how the window system knows what directory the
  860. shell is running in; in other words, what value to place in the
  861. .CW wdir
  862. field of the plumb message.
  863. Recall that
  864. .CW 8½
  865. is, like many Plan 9 programs, a file server.
  866. It now serves a new file,
  867. .CW /dev/wdir ,
  868. that is private to each window.
  869. Programs, in particular the
  870. Plan 9 shell,
  871. .CW rc ,
  872. can write that file to inform the window system of its current directory.
  873. When a
  874. .CW cd
  875. command is executed in an interactive shell,
  876. .CW rc
  877. updates the contents of
  878. .CW /dev/wdir
  879. and plumbing can proceed with local file names.]
  880. .LP
  881. Of course, users can plumb image file names, process ids, URLs, and other items\(emany string
  882. whose syntax and disposition are defined in the plumbing rules file.
  883. An example of how the pieces fit together is the way Plan 9 now handles mail, particularly
  884. MIME-encoded messages.
  885. .LP
  886. When a new mail message arrives, the mail receiver process sends a plumbing message to the
  887. .CW newmail
  888. port, which notifies any interested process that new mail is here.
  889. The plumbing message contains information about the mail, including
  890. its sender, date, and current location in the file system.
  891. The interested processes include a program,
  892. .CW faces ,
  893. that gives a graphical display of the mail box using
  894. faces to represent the senders of messages [PiPr85],
  895. as well as interactive mail programs such as the Acme mail viewer [Pike94].
  896. The user can then click on the face that appears, and the
  897. .CW faces
  898. program will send another plumbing message, this time to the
  899. .CW showmail
  900. port.
  901. Here is the rule for that port:
  902. .P1
  903. # faces -> new mail window for message
  904. type is text
  905. data matches '[a-zA-Z0-9_\e-./]+'
  906. data matches '/mail/fs/[a-zA-Z0-9/]+/[0-9]+'
  907. plumb to showmail
  908. plumb start window edmail -s $0
  909. .P2
  910. If a program, such as the Acme mail reader, is reading that port, it will open a new window
  911. in which to display the message.
  912. If not, the
  913. .CW plumb
  914. .CW start
  915. rule will create a new window and run
  916. .CW edmail ,
  917. a conventional mail reading process, to examine it.
  918. Notice how the plumbing connects the components of the interface together the same way
  919. regardless of which components are actually being used to view mail.
  920. .LP
  921. There is more to the mail story.
  922. Naturally, mail boxes in Plan 9 are treated as little file systems, which are synthesized
  923. on demand by a special-purpose file server that takes a flat mail box file and converts
  924. it into a set of directories, one per message, with component files containing the header,
  925. body, MIME information, and so on.
  926. Multi-part MIME messages are unpacked into multi-level directories, like this:
  927. .P1
  928. % ls -l /mail/fs/mbox/25
  929. d-r-xr-xr-x M 20 rob rob 0 Nov 21 13:06 /mail/fs/mbox/25/1
  930. d-r-xr-xr-x M 20 rob rob 0 Nov 21 13:06 /mail/fs/mbox/25/2
  931. --r--r--r-- M 20 rob rob 28678 Nov 21 13:06 /mail/fs/mbox/25/body
  932. --r--r--r-- M 20 rob rob 0 Nov 21 13:06 /mail/fs/mbox/25/cc
  933. \&...
  934. % mail
  935. 25 messages
  936. : 25
  937. From: presotto
  938. Date: Sun Nov 21 13:05:51 EST 1999
  939. To: rob
  940. Check this out.
  941. ===> 2/ (image/jpeg) [inline]
  942. /mail/fs/mbox/25/2/fabio.jpg
  943. :
  944. .P2
  945. Since the components are all (synthetic) files, the user can plumb the pieces
  946. to view embedded pictures, URLs, and so on.
  947. Note that the mail program can plumb the contents of
  948. .CW inline
  949. attachments automatically, without user interaction;
  950. in other words, plumbing lets the mailer handle multimedia data
  951. without itself interpreting it.
  952. .LP
  953. At a more mundane level, a shell command,
  954. .CW plumb ,
  955. can be used to send messages:
  956. .P1
  957. % cd /usr/rob/src
  958. % plumb mem.c
  959. .P2
  960. will send the appropriate message to the
  961. .CW edit
  962. port.
  963. A surprising use of the
  964. .CW plumb
  965. command is in actions within the plumbing rules file.
  966. In our lab, we commonly receive Microsoft Word documents by mail,
  967. but we do not run Microsoft operating systems on our machines so we cannot
  968. view them without at least rebooting.
  969. Therefore, when a Word document arrives in mail, we could plumb the
  970. .CW .doc
  971. file but the text editor could not decode it.
  972. However, we have a program,
  973. .CW doc2txt ,
  974. that decodes the Word file format to extract and format the embedded text.
  975. The solution is to use
  976. .CW plumb
  977. in a
  978. .CW plumb
  979. .CW start
  980. action to invoke
  981. .CW doc2txt
  982. on
  983. .CW .doc
  984. files and synthesize a plain text file:
  985. .P1
  986. # rule set for microsoft word documents
  987. type is text
  988. data matches '[a-zA-Z0-9_\e-./]+'
  989. data matches '([a-zA-Z0-9_\e-./]+)\e.doc'
  990. arg isfile $0
  991. plumb start doc2txt $data | \e
  992. plumb -i -d edit -a action=showdata -a filename=$0
  993. .P2
  994. The arguments to
  995. .CW plumb
  996. tell it to take standard input as its data rather than the text of the arguments
  997. .CW -i ), (
  998. define the destination port
  999. .CW -d "" (
  1000. .CW edit ),
  1001. and set a conventional attribute so the editor knows to show the message data
  1002. itself rather than interpret it as a file name
  1003. .CW -a "" (
  1004. .CW action=showdata )
  1005. and provide the original file name
  1006. .CW -a "" (
  1007. .CW filename=$0 ).
  1008. Now when a user plumbs a
  1009. .CW .doc
  1010. file the plumbing rules run a process to extract the text and send it as a
  1011. temporary file to the editor for viewing.
  1012. It's imperfect, but it's easy and it beats rebooting.
  1013. .LP
  1014. Another simple example is a rule that turns man pages into hypertext.
  1015. Manual page entries of the form
  1016. .CW plumber(1)
  1017. can be clicked on to pop up a window containing the formatted `man page'.
  1018. That man page will in turn contain more such citations, which will also be clickable.
  1019. The rule is a little like that for Word documents:
  1020. .P1
  1021. # man index entries are synthesized
  1022. type is text
  1023. data matches '([a-zA-Z0-9_\e-./]+)\e(([0-9])\e)'
  1024. plumb start man $2 $1 | \e
  1025. plumb -i -d edit -a action=showdata -a filename=/man/$1($2)
  1026. .P2
  1027. .LP
  1028. There are many other inventive uses of plumbing.
  1029. One more should give some of the flavor.
  1030. We have a shell script,
  1031. .CW src ,
  1032. that takes as argument the name of an executable binary file.
  1033. It examines the symbol table of the binary to find the source file
  1034. from which it was compiled.
  1035. Since the Plan 9 compilers place full source path names in the symbol table,
  1036. .CW src
  1037. can discover the complete file name.
  1038. That is then passed to
  1039. .CW plumb ,
  1040. complete with the line number to find the
  1041. symbol
  1042. .CW main .
  1043. For example,
  1044. .P1
  1045. % src plumb
  1046. .P2
  1047. is all it takes to pop up an editor window on the
  1048. .CW main
  1049. routine of the
  1050. .CW plumb
  1051. command, beginning at line 39 of
  1052. .CW /sys/src/cmd/plumb/plumb.c .
  1053. Like most uses of plumbing,
  1054. this is not a breakthrough in functionality, but it is a great convenience.
  1055. .SH
  1056. Why This Architecture?
  1057. .LP
  1058. The design of the plumbing system is peculiar:
  1059. a centralized language-based file server does most of the work,
  1060. while compared to other systems the applications themselves
  1061. contribute relatively little.
  1062. This architecture is deliberate, of course.
  1063. .LP
  1064. That the plumber's behavior is derived from a linguistic description
  1065. gives the system great flexibility and dynamism\(emrules can be added
  1066. and changed at will, without rebooting\(embut the existence of a central library of rules
  1067. ensures that, for most users, the environment behaves in well-established ways.
  1068. .LP
  1069. That the plumber is a file server is perhaps the most unusual aspect of its design,
  1070. but is also one of the most important.
  1071. Messages are passed by regular I/O operations on files, so no extra technology
  1072. such as remote procedure call or request brokers needs to be provided;
  1073. messages are transmitted by familiar means.
  1074. Almost every service in Plan 9 is a file server, so services can be exported
  1075. trivially using the system's remote file system operations [Pike93].
  1076. The plumber is no exception;
  1077. plumbing messages pass routinely across the network to remote applications without
  1078. any special provision,
  1079. in contrast to some commercial IPC mechanisms that become
  1080. significantly more complex when they involve multiple machines.
  1081. As I write this, my window system is talking to applications running on three
  1082. different machines, but they all share a single instance of the plumber and so
  1083. can interoperate to integrate my environment.
  1084. Plan 9 uses a shared file name space
  1085. to combine multiple networked machines\(emcompute servers,
  1086. file servers, and interactive workstations\(eminto a single
  1087. computing environment; plumbing's design as a file server
  1088. is a natural by-product of, and contributor to, the overall system architecture
  1089. [Pike92].
  1090. .LP
  1091. The centrality of the plumber is also unusual.
  1092. Other systems tend to let the applications determine where messages will go;
  1093. consider mail readers that recognize and highlight URLs in the messages.
  1094. Why should just the mail readers do this, and why should they just do it for URLs?
  1095. (Acme was guilty of similar crimes.)
  1096. The plumber, by removing such decisions to a central authority,
  1097. guarantees that all applications behave the same and simultaneously
  1098. frees them all from figuring out what's important.
  1099. The ability for the plumber to excerpt useful data from within a message
  1100. is critical to the success of this model.
  1101. .LP
  1102. The entire system is remarkably small.
  1103. The plumber itself is only about two thousand lines of C code.
  1104. Most applications work fine in a plumbing environment without knowing about it at all;
  1105. some need trivial changes such as to standardize their error output;
  1106. a few need to generate and receive plumbing messages.
  1107. But even to add the ability to send and receive messages in a program such as text editor is short work,
  1108. involving typically a few dozen lines of code.
  1109. Plumbing fits well into the existing environment.
  1110. .LP
  1111. But plumbing is new and it hasn't been pushed far enough yet.
  1112. Most of the work so far has been with textual messages, although
  1113. the underlying system is capable of handling general data.
  1114. We plan to reimplement some of the existing data movement operations,
  1115. such as cut and paste or drag and drop, to use plumbing as their exchange mechanism.
  1116. Since the plumber is a central message handler, it is an obvious place to store the `clipboard'.
  1117. The clipboard could be built as a special port that holds onto messages rather than
  1118. deleting them after delivery.
  1119. Since the clipboard would then be holding a plumbing
  1120. message rather than plain text, as in the current Plan 9 environment,
  1121. it would become possible to cut and paste arbitrary data without
  1122. providing new mechanism.
  1123. In effect, we would be providing a new user interface to the existing plumbing facilities.
  1124. .LP
  1125. Another possible extension is the ability to override plumbing operations interactively.
  1126. Originally, the plan was to provide a mechanism, perhaps a pop-up menu, that one could
  1127. use to direct messages, for example to send a PostScript file to the editor rather than the
  1128. PostScript viewer by naming an explicit destination in the message.
  1129. Although this deficiency should one day be addressed, it should be done without
  1130. complicating the interface for invoking the default behavior.
  1131. Meanwhile, in practice the default behavior seems to work very well in practice\(emas it
  1132. must if plumbing is to be successful\(emso the lack of
  1133. overrides is not keenly felt.
  1134. .SH
  1135. Comparison with Other Systems
  1136. .LP
  1137. The ideas of the plumbing system grew from an
  1138. attempt to generalize the way Acme acquires files and data.
  1139. Systems further from that lineage also share some properties with plumbing.
  1140. Most, however, require explicit linking or message passing rather than
  1141. plumbing's implicit, context-based pattern matching, and none
  1142. has the plumber's design of a language-based file server.
  1143. .LP
  1144. Reiss's FIELD system [Reis95] probably comes the closest to providing the facilities of the plumber.
  1145. It has a central message-passing mechanism that connects applications together through
  1146. a combination of a library and a pattern-matching central message dispatcher that handles
  1147. message send and reply.
  1148. The main differences between FIELD's message dispatcher and the plumber are first
  1149. that the plumber is based on a special-purpose language while the FIELD
  1150. system uses an object-oriented library, second that the plumber has no concept
  1151. of a reply to a message, and finally that the FIELD system
  1152. has no concept of port.
  1153. But the key distinction is probably in the level of use.
  1154. In FIELD, the message dispatcher is a critical integrating force of the underlying
  1155. programming environment, handling everything from debugging events to
  1156. changing the working directory of a program.
  1157. Plumbing, by contrast, is intended primarily for integrating the user interface
  1158. of existing tools; it is more modest and very much simpler.
  1159. The central advantage of the plumber is its convenience and dynamism;
  1160. the FIELD system does not share the ease with which
  1161. message dispatch rules can be added or modified.
  1162. .LP
  1163. The inspiration for Acme was
  1164. the user interface to the object-oriented Oberon system [WiGu92].
  1165. Oberon's user interface interprets mouse clicks on strings such as
  1166. .CW Obj.meth
  1167. to invoke calls to the method
  1168. .CW meth
  1169. of the object
  1170. .CW Obj .
  1171. This was the starting point for Acme's middle-button execution [Pike94],
  1172. but nothing in Oberon is much like Acme's right-button `acquisition',
  1173. which was the starting point for the plumber.
  1174. Oberon's implicit method-based linking is not nearly as general as the pattern-matched
  1175. linking of the plumber, nor does its style of user-triggered method call
  1176. correspond well to the more general idea of inter-application communication
  1177. of plumbing messages.
  1178. .LP
  1179. Microsoft's OLE interface is another relative.
  1180. It allows one application to
  1181. .I embed
  1182. its own data within another's,
  1183. for example to place an Excel spreadsheet within a Frame document;
  1184. when Frame needs to format the page, it will start Excel itself, or at least some of its
  1185. DLLs, to format the spreadsheet.
  1186. OLE data can only be understood by the application that created it;
  1187. plumbing messages, by contrast, contain arbitrary data with a rigidly formatted header
  1188. that will be interpreted by the pattern matcher and the destination application.
  1189. The plumber's simplified message format may limit its
  1190. flexibility but makes messages easy and efficient to dispatch and to interpret.
  1191. At least for the cut-and-paste style of exchange OLE encourages,
  1192. plumbing gives up some power in return for simplicity, while avoiding
  1193. the need to invoke a vestigial program (if Excel can be called a vestige) every time
  1194. the pasted data is examined.
  1195. Plumbing is also better suited to
  1196. other styles of data exchange, such as connecting compiler errors to the
  1197. text editor.
  1198. .LP
  1199. The Hyperbole [Wein] package for Emacs adds hypertext facilities to existing documents.
  1200. It includes explicit links and, like plumbing, a rule-driven way to form implicit links.
  1201. Since Emacs is purely textual, like Acme, Hyperbole does not easily extend to driving
  1202. graphical applications, nor does it provide a general interprocess communication method.
  1203. For instance, although Hyperbole provides some integration for mail applications,
  1204. it cannot provide the glue that allows a click on a face icon in an external program to open a
  1205. mail message within the viewer.
  1206. Moreover, since it is not implemented as a file server,
  1207. Hyperbole does not share the advantages of that architecture.
  1208. .LP
  1209. Henry's
  1210. .CW error
  1211. program in 4BSD echoes a small but common use of plumbing.
  1212. It takes the error messages produced by a compiler and drives a text editor
  1213. through the steps of looking at each one in turn; the notion is to quicken the
  1214. compile/edit/debug cycle.
  1215. Similar results are achieved in EMACS by writing special M-LISP
  1216. macros to parse the error messages from various compilers.
  1217. Although for this particular purpose they may be more convenient than plumbing,
  1218. these are specific solutions to a specific problem and lack plumbing's generality.
  1219. .LP
  1220. Of course, the resource forks in MacOS and the association rules for
  1221. file name extensions in Windows also provide some of the functionality of
  1222. the plumber, although again without the generality or dynamic nature.
  1223. .LP
  1224. Closer to home, Ousterhout's Tcl (Tool Command Language) [Oust90]
  1225. was originally designed to embed a little command interpreter
  1226. in each application to control interprocess communication and
  1227. provide a level of integration.
  1228. Plumbing, on the other hand, provides minimal support within
  1229. the application, offloading most of the message handling and all the
  1230. command execution to the central plumber.
  1231. .LP
  1232. The most obvious relative to plumbing is perhaps the hypertext links of a web browser.
  1233. Plumbing differs by synthesizing
  1234. the links on demand.
  1235. Rather than constructing links within a document as in HTML,
  1236. plumbing uses the context of a button click to derive what it should link to.
  1237. That the rules for this decision can be modified dynamically gives it a more
  1238. fluid feel than a standard web browsing world.
  1239. One possibility for future work is to adapt a web browser to use
  1240. plumbing as its link-following engine, much as Acme used plumbing to offload
  1241. its acquisition rules.
  1242. This would connect the web browser to the existing tools, rather than the
  1243. current trend in most systems of replacing the tools by a browser.
  1244. .LP
  1245. Each of these prior systems\(emand there are others, e.g. [Pasa93, Free93]\(emaddresses
  1246. a particular need or subset of the
  1247. issues of system integration.
  1248. Plumbing differs because its particular choices were different.
  1249. It focuses on two key issues:
  1250. centralizing and automating the handling of interprocess communication
  1251. among interactive programs,
  1252. and maximizing the convenience (or minimizing the trouble) for the human user
  1253. of its services.
  1254. Moreover, the plumber's implementation as a file server, with messages
  1255. passed over files it controls,
  1256. permits the architecture to work transparently across a network.
  1257. None of the other systems discussed here integrates distributed systems
  1258. as smoothly as local ones without the addition of significant extra technology.
  1259. .SH
  1260. Discussion
  1261. .LP
  1262. There were a few surprises during the development of plumbing.
  1263. The first version of plumbing was done for the Inferno system [Dorw97a,Dorw97b],
  1264. using its file-to-channel mechanism to mediate the IPC.
  1265. Although it was very simple to build, it encountered difficulties because
  1266. the plumber was too disconnected from its clients; in particular, there was
  1267. no way to discover whether a port was in use.
  1268. When plumbing was implemented afresh for Plan 9, it was provided through a true file server.
  1269. Although this was much more work, it paid off handsomely.
  1270. The plumber now knows whether a port is open, which makes it easy to decide whether
  1271. a new program must be started to handle a message,
  1272. and the ability to edit the rules file dynamically is a major advantage.
  1273. Other advantages arise from the file-server design,
  1274. such as
  1275. the ease of exporting plumbing ports across the network to remote machines
  1276. and the implicit security model a file-based interface provides: no one has
  1277. permission to open my private plumbing files.
  1278. .LP
  1279. On the other hand, Inferno was an all-new environment and the user interface for plumbing was
  1280. able to be made uniform for all applications.
  1281. This was impractical for Plan 9, so more
  1282. .I "ad hoc
  1283. interfaces had to be provided for that environment.
  1284. Yet even in Plan 9 the advantages of efficient,
  1285. convenient, dynamic interprocess communication outweigh the variability of
  1286. the user interface.
  1287. In fact, it is perhaps a telling point that the system works well for a variety of interfaces;
  1288. the provision of a central, convenient message-passing
  1289. service is a good idea regardless of how the programs use it.
  1290. .LP
  1291. Plumbing's rule language uses only regular expressions and a few special
  1292. rules such as
  1293. .CW isfile
  1294. for matching text.
  1295. There is much more that could be done. For example, in the current system a JPEG
  1296. file can be recognized by a
  1297. .CW .jpg
  1298. suffix but not by its contents, since the plumbing language has no facility
  1299. for examining the
  1300. .I contents
  1301. of files named in its messages.
  1302. To address this issue without adding more special rules requires rethinking
  1303. the language itself.
  1304. Although the current system seems a good balance of complexity
  1305. and functionality,
  1306. perhaps a richer, more general-purpose language would
  1307. permit more exotic applications of the plumbing model.
  1308. .LP
  1309. In conclusion, plumbing adds an effective, easy-to-use inter-application
  1310. communication mechanism to the Plan 9
  1311. user interface.
  1312. Its unusual design as a language-driven file server makes it easy to add
  1313. context-dependent, dynamically interpreted, general-purpose hyperlinks
  1314. to the desktop, for both existing tools and new ones.
  1315. .SH
  1316. Acknowledgements
  1317. .LP
  1318. Dave Presotto wrote the mail file system and
  1319. .CW edmail .
  1320. He, Russ Cox, Sape Mullender, and Cliff Young influenced the design, offered useful suggestions,
  1321. and suffered early versions of the software.
  1322. They also made helpful comments on this paper, as did Dennis Ritchie and Brian Kernighan.
  1323. .SH
  1324. References
  1325. .LP
  1326. [Dorw97a]
  1327. Sean Dorward, Rob Pike, David Leo Presotto, Dennis M. Ritchie,
  1328. Howard W. Trickey, and Philip Winterbottom,
  1329. ``Inferno'',
  1330. .I "Proceedings of the IEEE Compcon 97 Conference" ,
  1331. San Jose, 1997, pp. 241-244.
  1332. .LP
  1333. [Dorw97b]
  1334. Sean Dorward, Rob Pike, David Leo Presotto, Dennis M. Ritchie,
  1335. Howard W. Trickey, and Philip Winterbottom,
  1336. ``The Inferno Operating System'',
  1337. .I "Bell Labs Technical Journal" ,
  1338. .B 2 ,
  1339. 1, Winter, 1997.
  1340. .LP
  1341. [Free93]
  1342. FreeBSD,
  1343. Syslog configuration file manual
  1344. .I syslog.conf (0).
  1345. .LP
  1346. [Kill84]
  1347. T. J. Killian,
  1348. ``Processes as Files'',
  1349. .I "Proceedings of the Summer 1984 USENIX Conference" ,
  1350. Salt Lake City, 1984, pp. 203-207.
  1351. .LP
  1352. [Oust90]
  1353. John K. Ousterhout,
  1354. ``Tcl: An Embeddable Command Languages'',
  1355. .I "Proceedings of the Winter 1990 USENIX Conference" ,
  1356. Washington, 1990, pp. 133-146.
  1357. .LP
  1358. [Pasa93]
  1359. Vern Paxson and Chris Saltmarsh,
  1360. "Glish: A User-Level Software Bus for Loosely-Coupled Distributed Systems" ,
  1361. .I "Proceedings of the Winter 1993 USENIX Conference" ,
  1362. San Diego, 1993, pp. 141-155.
  1363. .LP
  1364. [Pike87a]
  1365. Rob Pike,
  1366. ``Structural Regular Expressions'',
  1367. .I "EUUG Spring 1987 Conference Proceedings" ,
  1368. Helsinki, May 1987, pp. 21-28.
  1369. .LP
  1370. [Pike87b]
  1371. Rob Pike,
  1372. ``The Text Editor sam'',
  1373. .I "Software - Practice and Experience" ,
  1374. .B 17 ,
  1375. 5, Nov. 1987, pp. 813-845.
  1376. .LP
  1377. [Pike91]
  1378. Rob Pike,
  1379. ``8½, the Plan 9 Window System'',
  1380. .I "Proceedings of the Summer 1991 USENIX Conference" ,
  1381. Nashville, 1991, pp. 257-265.
  1382. .LP
  1383. [Pike93]
  1384. Rob Pike, Dave Presotto, Ken Thompson, Howard Trickey, and Phil Winterbottom,
  1385. ``The Use of Name Spaces in Plan 9'',
  1386. .I "Operating Systems Review" ,
  1387. .B 27 ,
  1388. 2, April 1993, pp. 72-76.
  1389. .LP
  1390. [Pike94]
  1391. Rob Pike,
  1392. ``Acme: A User Interface for Programmers'',
  1393. .I "Proceedings of the Winter 1994 USENIX Conference",
  1394. San Francisco, 1994, pp. 223-234.
  1395. .LP
  1396. [PiPr85]
  1397. Rob Pike and Dave Presotto,
  1398. ``Face the Nation'',
  1399. .I "Proceedings of the USENIX Summer 1985 Conference" ,
  1400. Portland, 1985, pg. 81.
  1401. .LP
  1402. [Reis95]
  1403. Steven P. Reiss,
  1404. .I "The FIELD Programming Environment: A Friendly Integrated Environment for Learning and Development" ,
  1405. Kluwer, Boston, 1995.
  1406. .LP
  1407. [Wein]
  1408. Bob Weiner,
  1409. .I "Hyperbole User Manual" ,
  1410. .CW http://www.cs.indiana.edu/elisp/hyperbole/hyperbole_1.html
  1411. .LP
  1412. [Wint94]
  1413. Philip Winterbottom,
  1414. ``ACID: A Debugger based on a Language'',
  1415. .I "Proceedings of the USENIX Winter Conference" ,
  1416. San Francisco, CA, 1994.
  1417. .LP
  1418. [WiGu92]
  1419. Niklaus Wirth and Jurg Gutknecht,
  1420. .I "Project Oberon: The Design of an Operating System and Compilers" ,
  1421. Addison-Wesley, Reading, 1992.