UNIX domain socket hanging around when not closed
Hello,
I have a (possibly stupid) question. Is it OK, that dentries created by binding unix-domain sockets remain in filesystem?
What I do is create a unix socket in /tmp and wait for clients to connect in. The program removes the socket dentry when it shuts down, but it sometimes crashes and the socket remains there.
Is there some reason the socket should remain unless explicitely removed?
-------------------------------------------------------------------------------
Jan 'Bulb' Hudec <[email protected]>
Quoted 4 lines · Jan Hudec
Hello,
I have a (possibly stupid) question. Is it OK, that dentries created by binding unix-domain sockets remain in filesystem?
That is the classical behaviour, possibly because of tradition where they relate to named pipes created with mknod(1) command.
http://www.ecst.csuchico.edu/~beej/guide/ipc/usock.html
Quoted 6 lines
What I do is create a unix socket in /tmp and wait for clients to connect in. The program removes the socket dentry when it shuts down, but it sometimes crashes and the socket remains there.
Is there some reason the socket should remain unless explicitely removed?
Traditional is also to unlink() the socket name just prior
to bind(3):ing it just in case there is a left-over entity with that name.
The object name (it is NAMED entity, after all) space is
filesystem name space. I don't see any reason why not:
- There could pre-exist the named socket (at a R/O filesystem), and no new name needs to be allocated in the filesystem for it.
- The entire named entity would not be allowed to exist purely in VFS space, that is: creation wise the permission verification could ignore location directory being on a read/only file system, and just use directory permissions. (Questions about memory expenditure, etc. all kinds of trade-offs.)
What the new POSIX writes about the issue, that I haven't yet looked into.
Quoted 1 line
Jan 'Bulb' Hudec <[email protected]>
/Matti Aarnio
Quoted 10 lines · Matti Aarnio
- There could pre-exist the named socket (at a R/O filesystem), and no new name needs to be allocated in the filesystem for it.
- The entire named entity would not be allowed to exist purely in VFS space, that is: creation wise the permission verification could ignore location directory being on a read/only file system, and just use directory permissions. (Questions about memory expenditure, etc. all kinds of trade-offs.)
Linux has a non file system name space for AF_UNIX sockets too. But its a Linux extension
Quoted 6 lines · Jan Hudec
What I do is create a unix socket in /tmp and wait for clients to connect in. The program removes the socket dentry when it shuts down, but it sometimes crashes and the socket remains there.
Is there some reason the socket should remain unless explicitely removed?
Thats what is supposed to happen. If its dead then in your server you can remove it and create a new one.