home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / question / 9437 < prev    next >
Encoding:
Internet Message Format  |  1992-07-26  |  7.5 KB

  1. Xref: sparky comp.unix.questions:9437 comp.unix.programmer:3924 comp.unix.shell:3139 comp.unix.internals:1617 comp.unix.admin:4325
  2. Newsgroups: comp.unix.questions,comp.unix.programmer,comp.unix.shell,comp.unix.internals,comp.unix.admin
  3. Path: sparky!uunet!van-bc!rsoft!agate!ames!sun-barr!cs.utexas.edu!wupost!darwin.sura.net!convex!convex!tchrist
  4. From: Tom Christiansen <tchrist@convex.COM>
  5. Subject: named pipes (was: Finger and .plan, .project)
  6. Message-ID: <1992Jul26.165838.1278@news.eng.convex.com>
  7. Followup-To: comp.unix.programmer
  8. Originator: tchrist@pixel.convex.com
  9. Keywords: named pipes, fopen, popen, .plan, .profile, .signature
  10. Sender: usenet@news.eng.convex.com (news access account)
  11. Nntp-Posting-Host: pixel.convex.com
  12. Reply-To: tchrist@pixel.convex.COM (Tom Christiansen)
  13. Organization: CONVEX Realtime Development, Colorado Springs, CO
  14. References: <19076@fritz.filenet.com> <14u80cINNbd8@grasp1.univ-lyon1.fr>
  15. Date: Sun, 26 Jul 1992 16:58:38 GMT
  16. Expires: Wed, 12 Aug 1992 04:00:00 GMT
  17. X-Disclaimer: This message was written by a user at CONVEX Computer
  18.               Corp. The opinions expressed are those of the user and
  19.               not necessarily those of CONVEX.
  20. Lines: 130
  21.  
  22. From the keyboard of Christophe.Wolfhugel@univ-lyon1.fr (Christophe Wolfhugel):
  23. :scotth@felix.filenet.com (Scott Hopson) writes:
  24. :> [use a named pipe]
  25. :> You must be sure that this daemon gets started after your system
  26. :> is rebooted or readers like "finger" will hang.
  27. :
  28. :You can't be sure that the daemon will still be around when someone
  29. :will be fingering you.  It's not because you start it a boot time
  30. :(first you need priviledge to do this) that it will still be in the
  31. :air two days later.
  32.  
  33. You can deal with this using a moderately clever user-level cron 
  34. entry.   Hmm... do we need a user-level rc hook, or maybe a way
  35. to specify in cron that something should be run at boot time?
  36.  
  37. :Second, just imagine if I'd allow that to my 300+ users?  Do you really
  38. :except a SA can tolerate 300 permanent processes for just nothing?
  39. :
  40. :A viable solution would be to change the fingerd to something that
  41. :fits your need. It's as easy to do as the replacement code you have
  42. :proposed and it has the advantage to generate one active process
  43. :per finger!
  44. :
  45. :Please folks, don't use named pipes for you finger stuff, this is
  46. :not the good approach.
  47.  
  48.      Note: I've given this a wider crossposting because I've been
  49.      thinking about the matter for some time, and I'd like to incite
  50.      some discussion on it.  Followups are funnelled back to one group.
  51.  
  52. It may not be the optimal approach, but is certainly one available
  53. to the non-privileged user without modification of any system
  54. utilities.  
  55.  
  56. I don't believe that you'd ever have all 300 of your users running
  57. a program to service the named pipes which are their dot-plan or
  58. dot-project files.  And if they did, what could you do to improve
  59. this?  
  60.  
  61. What sorts of uses do people make of named pipes that they couldn't
  62. do with files? I tend to find them an idea that's only partially
  63. successful due to their drawbacks described several paragraphs below.
  64.  
  65. Two improvements come to mind: either run just one process all the time,
  66. or else run per-user temporary processes that last only for the duration
  67. of the read.
  68.  
  69. I'm not sure how to do a good named-pipe inetd.  I'd like to just
  70. do a listen, er, select on all the pipes, and dispatch a user process
  71. when one is opened.  But to select on them, you're going to have to
  72. have opened then, which makes you block for someone on the other end.
  73. Even if a workaround were found for this, you'd still have a lot
  74. of files open, which means it might work for multiplexing 10 of
  75. them, but almost certainly not 1000, since I don't know many
  76. systems that support 1000 concurrently open files in one process.
  77.  
  78. For one thing, they're used as rendezvous points for communications
  79. between unrelated processes.  If they were related, then regular,
  80. anonymous pipes would have worked.  I've seen then used in some shells for
  81. process redirection, although I've never quite seen why this couldn't have
  82. been implemented using temporary files.  I'm thinking of things like
  83.  
  84.     $ diff (tail file1) (tail file2)
  85.  
  86. which sometimes is implemented using temporary named pipes, or sometimes
  87. with the /dev/fd stuff if you're lucky enough to have it.  I'm not 
  88. sure why on systems without either you couldn't use a regular temp file.
  89.  
  90. Named pipes also used when someone wants a program to intercept I/O calls,
  91. allowing a file to produce more interesting output.  This is the case when
  92. people replace their dot-plan with a pipe, for instance.  An advantage of
  93. this method is that unlike a UNIX-domain socket, named pipes really look a
  94. good deal like files, allowing programs that are doing normal reads or
  95. writes (note "or" not "and") on them to function virtually transparently
  96. when you replace them with a named pipe.
  97.  
  98. As the poster above brought up, there are some problems with this.
  99. The main one is that you must have a PRE-EXISTING server process, or
  100. else the client will hang until one exists.  Another problem is
  101. that you have to know whether the pipe is intended to be read from
  102. or written to, so that your server can open it the other way.  Yet
  103. another problem is that having multiple readers and writers makes
  104. for intermixed and mangled.  Still another problem is that they
  105. don't work across NFS.  If you had a server for them on one machine,
  106. the next machine wouldn't know.  And in fact, on some systems, you
  107. can crash your kernel by attempting to access a remote named pipe.
  108.  
  109. At various times, I've wanted to have /etc/motd, my .signature, and my
  110. .plan and .project be hooks to programs, not regular files.  In the case
  111. of /etc/motd, I altered login to execute it if the execute bit is set.
  112. For my .signature, it reads from a named pipe, which means I have to run a
  113. program all the time. Ick, yes, but at least I didn't have to modify each
  114. and every program that would read my .signature, of which there are a few.
  115. That would have been even more bother.
  116.  
  117. Now, if we were running certain specialized versions of UNIX, or
  118. reasonably UNIX-like systems, better solutions could be devised.  
  119. With systems running with file watchdogs, it should be possible to come
  120. up with a general solution.  I'd try it on a Convex, but the watchdog
  121. stuff was designed by a kernel hacker, not a user-level guy, so it's
  122. a bit cumbersome to use, and certainly not in the least bit portable.
  123.  
  124. Furthermore, I believe that under both Plan9 and SunOS that you can have a 
  125. filesystem type that does the right thing, so if people did this:
  126.  
  127.     ln -s ~/.plan /plans/$USER
  128.  
  129. Then have /plans be a special filesystem type that triggers invocation
  130. of the right code.
  131.  
  132. One workaround for the rest of us is to relink your code (hey, better
  133. than modifying the kernel) such that an fopen() on a file with the
  134. execute bit set actually does a popen() of the appropriate mode.
  135. This still means tracking down all the programs that are going to
  136. try to do this, unless you alter your C library.  This might be
  137. the best solution.
  138.  
  139. What programs would break drastically if we changed the library fopen()
  140. call to either accept "rx"/"wx" to indicate a popen(), or else for the
  141. sake of transparency, to have it stat() the file and check for the execute
  142. bit?  (Should we to do it for open() as well?  Probably.)  Certainly editors
  143. would prefer the former solution, but most general purpose programs the
  144. latter one.
  145.  
  146. --tom
  147. -- 
  148.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  149.  
  150. "The number of UNIX installations has grown to 10, with more expected."
  151.     - _The UNIX Programmer's Manual_, Second Edition, June, 1972.
  152.