pcp
[Top] [All Lists]

Re: Unix Domain Sockets

To: Dave Brolley <brolley@xxxxxxxxxx>
Subject: Re: Unix Domain Sockets
From: "Frank Ch. Eigler" <fche@xxxxxxxxxx>
Date: Wed, 5 Jun 2013 17:00:00 -0400
Cc: Nathan Scott <nathans@xxxxxxxxxx>, pcp@xxxxxxxxxxx
Delivered-to: pcp@xxxxxxxxxxx
In-reply-to: <51AFA054.8030005@xxxxxxxxxx>
References: <51AD5434.9090200@xxxxxxxxxx> <1004356284.18217432.1370333038213.JavaMail.root@xxxxxxxxxx> <51AE0706.9010507@xxxxxxxxxx> <y0mvc5telx2.fsf@xxxxxxxx> <51AE4DD8.1070406@xxxxxxxxxx> <20130604203516.GB15065@xxxxxxxxxx> <2144455046.18771690.1370384108925.JavaMail.root@xxxxxxxxxx> <51AFA054.8030005@xxxxxxxxxx>
User-agent: Mutt/1.4.2.2i
Hi -

On Wed, Jun 05, 2013 at 04:32:20PM -0400, Dave Brolley wrote:

> [...]  Indeed, experimentation shows that failing to call
> remove/unlink on the object results in EADDRINUSE the next time pmcd
> tries to bind to this address.

Correct, canonical unix-domain-socket code examples do unlink(2)
*before* the bind(2) for this reason.  (They can also do an unlink at
program shutdown, just for filesystem cleanliness.)


> The problem is one of euid and file system permissions when running as a 
> daemon, as installed. /var/run/pcp is 'drwxr-xr-x. 2 root root' [...]

Ah indeed.

> I have 2 solutions and would like some help in choosing or perhaps there 
> is another solution:
> 
> 1) unlink/remove the object immediately after binding while we are still 
> root. 

(Note that it's not just the unlink that should require such privilege
but also the initial bind.)

> In this case, according to remove(3) (which calls unlink(3) in 
> this case) and Unix(7), the object's name is removed from the directory 
> listing, but the object continues to exist and the socket remains 
> available until it is closed. [...]

Does this mean that *new* clients can connect to the unix-domain
socket even after it's unlinked?  That'd be very strange, and would
seem to make it unnecessary to have all these unix-domain sockets sit
around in a filesystem for longer than a split second.


> 2) Rework the permissions of /var/run/pcp so that they are 'drwxrwxr-x. 
> 2 root pcp'. In this case, the object is visible in /var/run/pcp and can 
> be successfully removed at shutdown time.

This is plausible to me.


- FChE

<Prev in Thread] Current Thread [Next in Thread>