home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / protocol / tcpip / 5058 < prev    next >
Encoding:
Text File  |  1992-11-05  |  5.3 KB  |  121 lines

  1. Newsgroups: comp.protocols.tcp-ip
  2. Path: sparky!uunet!gatech!destroyer!cs.ubc.ca!unixg.ubc.ca!kakwa.ucs.ualberta.ca!alberta!cpsc.ucalgary.ca!xenlink!newt.cuc.ab.ca!deraadt
  3. From: deraadt@newt.cuc.ab.ca (Theo de Raadt)
  4. Subject: Re: rpc process chewing up resources
  5. In-Reply-To: gsa@easyaspi.udev.cdc.com's message of 3 Nov 92 21: 58:41 GMT
  6. Message-ID: <DERAADT.92Nov5044404@newt.newt.cuc.ab.ca>
  7. Sender: news@newt.cuc.ab.ca
  8. Nntp-Posting-Host: newt
  9. Organization: little lizard city
  10. References: <rsbtguk@rhyolite.wpd.sgi.com> <49256@shamash.cdc.com>
  11. Date: Thu, 5 Nov 1992 11:44:04 GMT
  12. Lines: 107
  13.  
  14. I'm currently implimenting YP client functionality for 386bsd. So far,
  15. it's been an enjoyable and frustrating time....
  16.  
  17. In article <49256@shamash.cdc.com> gsa@easyaspi.udev.cdc.com (gary s anderson) writes:
  18. >  |> > |> > sits within the "yp" library code (you need to ask SUN why "pinging"
  19. >  |> > |> > the portmapper from within "yp" is useful).  This has the wonderful
  20. >  |> > |> Hmmmph!
  21. >  |> > |> What would you do if you wanted to discover if ypbind is running?
  22.  
  23. Well, on some systems (including my code at the moment) that's exactly
  24. why TCP is used. It's faster than UDP.
  25.  
  26. My first code used UDP to find out if ypbind was running. Well, if you
  27. don't get an answer, even in talking to 127.0.0.1, well, the kernel's
  28. buffers could just be swamped at the moment. So you have to try a few
  29. times. Not pretty.
  30.  
  31. So, I started using TCP. Immediate response yes/no whether YP is
  32. running. I had no real concerns with whether the portmapper is
  33. running.
  34.  
  35. I'm have a Sun too. A few minutes ago, I went and looked to see why
  36. the file /etc/ypbind.lock exist... a bit of snooping and following a
  37. hunch...
  38.  
  39.   4835 -rw-------  1 root            0 Nov  2 21:46 /etc/ypbind.lock
  40.   ^^^^
  41.  inode
  42.  
  43. pstat -i | grep 4835
  44.  f23f9a8    R     7,  0  4835 100600   1    0         0   E     2   0   1 VREG
  45.                               ^^^
  46. That little 'E' is an exclusive lock.
  47.  
  48. Could someone explain exactly what is going on here? What I suspect
  49. follows: ypbind maintains the exclusive lock on /etc/ypbind.lock
  50. Processes that are interested can find out if ypbind is running by
  51. doing a lockf(fd, F_TEST).  Sun's ypbind also puts an exclusive lock
  52. on /var/yp/binding/domainname.2 and /var/yp/binding/domainname.1.  I
  53. suspect the 2 is YPBINDVERS.
  54.  
  55. Just trying to get a flock() on that file seems to work. This is so much
  56. easier than what it appears the entire argument here is about.
  57.  
  58. Here's what happens if I trace a program that needs to check YP.
  59.  
  60.     open ("/var/yp/binding/cuc.ab.ca.2", 0, 036736173730) = 4
  61.     flock (4, 06) = -1 EWOULDBLOCK (Operation would block)
  62.     mmap (0x8ab8, 14, 0x1, 0x80000001, 4, 0) = 0xf7710000
  63.     close (4) = 0
  64.  
  65. Aha. The fact that the flock() failed tells us that ypbind is running.
  66. Sun places into the binding file the actual (struct sockaddr_in) at
  67. which the current ypserver can be found (It could be ypbind's address,
  68. but it makes more sense to be ypserv's address). So they mmap() the
  69. (struct sockaddr_in) and continue.
  70.  
  71. >  |> > 
  72. >  |> > I would send a UDP RPC request to the portmapper to find out
  73. >  |> > if ypbind was registered.  The problem is that there is code
  74. >  |> > which creates a "dummy" TCP connection just to see if the
  75. >  |> > portmapper is running (i.e. doesn't trust UDP time-outs as 
  76. >  |> > sufficient evidence that the portmapper is not running).
  77.  
  78. I would not trust a UDP timeout on "localhost" as meaning that the
  79. portmapper is dead. It might take 5 seconds for a busy portmapper to
  80. answer. Someone in Timbuktu, at the end of a very slow link, may have
  81. been spraying the portmapper. Packets may have convoyed, and the
  82. portmapper may be swamped! How long are you going to wait around?
  83.  
  84. >  |> > If the connection succeeds, it is immediately closed and then
  85. >  |> > the UDP RPC request is made to the portmapper to get the 
  86. >  |> > information about ypbind.
  87. >  |> 
  88. >  |> Perhaps my point was not clear.
  89. >  |> 
  90. >  |> By using TCP you avoid having to wait for a UDP time-out to expire when
  91. >  |> things are not present.  Which would make you more unhappy?  Having an
  92. >  |> anonymous TCP port number tied up for a little while or having to wait
  93. >  |> a large part of a second (or more if you allow remote access over slow
  94. >  |> links) to discover that the portmapper is not running?
  95.  
  96. With TCP, your connection will succeed immediately, well, as long as
  97. the listen queue has room for you....
  98.  
  99.  
  100. Really, I prefer Sun's method of checking for yellow. A flock() on a
  101. locked file means you are talking to an inode that is already in the
  102. buffer cache. That's got to be faster and more reliable than talking
  103. to portmap & ypbind.
  104.  
  105. Anyways, I'm going to impliment my routines much like Sun's did!
  106.  
  107. Only one thing bothers me with the RPC programming I am doing. Sun's
  108. ypbind is not multithreaded; rather, it forks when it gets a request
  109. for a currently unbound domain. I decided to make my ypbind much more
  110. multithreaded. What I have come to discover to my disgust is that if
  111. you wish to write a properly multithreaded RPC application you have to
  112. give up all the juicy RPC and SVC routines and dig right into the XDR
  113. level. What a pain. And, boy, I could scream because I have found no
  114. way to access msg->msg_xid from the SVC/RPC level! For a proper
  115. multi-threaded application, you are going to need to save a copy of
  116. that for the later reply!
  117.  <tdr.
  118. --
  119.  
  120. This space not left unintentionally unblank.        deraadt@newt.cuc.ab.ca
  121.