home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / protocol / tcpip / 5758 < prev    next >
Encoding:
Internet Message Format  |  1992-12-29  |  2.6 KB

  1. Path: sparky!uunet!pipex!bnr.co.uk!uknet!gdt!aber!fronta.aber.ac.uk!pcg
  2. From: pcg@aber.ac.uk (Piercarlo Grandi)
  3. Newsgroups: comp.protocols.tcp-ip
  4. Subject: Re: what to do with those pesky Unix domain socket files
  5. Message-ID: <PCG.92Dec29163641@decb.aber.ac.uk>
  6. Date: 29 Dec 92 16:36:41 GMT
  7. References: <d4Um03o6c5UD00@amdahl.uts.amdahl.com>
  8. Sender: news@aber.ac.uk (USENET news service)
  9. Reply-To: pcg@aber.ac.uk (Piercarlo Grandi)
  10. Organization: Prifysgol Cymru, Aberystwyth
  11. Lines: 41
  12. In-Reply-To: wjq@uts.amdahl.com's message of 23 Dec 92 00: 31:24 GMT
  13. Nntp-Posting-Host: decb.aber.ac.uk
  14.  
  15. On 23 Dec 92 00:31:24 GMT, wjq@uts.amdahl.com (Bill Quigley) said:
  16.  
  17. wjq> In our new SVR4 kernel, bind() to a unix domain socket creates a
  18. wjq> file with the name specified in the bind call.  But if the process
  19. wjq> is killed, the file stays around, and when the process comes up
  20. wjq> again, it cannot bind to the same name, and gets EADDRINUSE, even
  21. wjq> though there isn't a valid socket using that name.
  22.  
  23. wjq> How do others get around this problem?
  24.  
  25. There is absolutely no direct way. Some naive and innocent soul will
  26. advise unlinking the socket file before bind, but this of course means
  27. only that you will not get any error notificaton if you start multiple
  28. copies of the daemon.
  29.  
  30. Simply put, the socket file acts both as a named endpoint and as a lock
  31. that ensure only one daemon serves the socket at one time.
  32.  
  33. A method which is prone to races is to check for the existence of
  34. another server process before doing the unbind, by trying to open the
  35. socket file and seeing if it is bound to anybody.
  36.  
  37. A more reliable method is to use a central socket broker; when a daemon
  38. wants to start listening on a socket, it asks the broker by opening a
  39. connection to it; if the broker has no record of a previous request, it
  40. grants it; if it has, it knows whether the server is dead or not (it has
  41. dropped or not the connection to the broker) and then if dead unlinks
  42. the socket file and goes on, if not returns a message to the requestor
  43. saying "already taken".
  44.  
  45. You could also do an inetd style broker for the Unix domain; then the
  46. broker would know of the death of a server by way of SIGCLD.
  47.  
  48. If you are thinking of Unix domain sockets for X, then they are usually
  49. associated with a display, and no checking is then necessary, as it is
  50. very rare that the user tries to run two servers on the same display,
  51. and if he does, damn.
  52. --
  53. Piercarlo Grandi, Dept of CS, PC/UW@Aberystwyth <pcg@aber.ac.uk>
  54.   E l'italiano cantava, cantava. E le sue disperate invocazioni giunsero
  55.   alle orecchie del suo divino protettore, il dio della barzelletta
  56.