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