Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
prefer XDG_RUNTIME_DIR over /tmp for the socket #2222
$XDG_RUNTIME_DIR is the place where to put socket files these days.
It seems good practice to create a sub-directory as well, perhaps we
The fallback to write in /tmp remains for the rare occasions where
$XDG_RUNTIME_DIR is the place where to put socket files these days. It seems good practice to create a sub-directory as well, perhaps we create more files there in the future. The fallback to write in /tmp remains for the rare occasions where $XDG_RUNTIME_DIR cannot be used.
I like the idea, but I'm a little worried about what the spec says on lifetime of files in that directory:
This suggests our socket link could disappear on us after 6 hours if we're not careful, doesn't it? That could be a problem and the source of weird bugs.
Good point. I didn't find exact information unfortunately. Just this one SO discussion: https://unix.stackexchange.com/questions/356302/sticky-bit-and-socket-files-in-xdg-runtime-dir
That suggests that 1) the 6h requirement applies to real files (and I tend to follow since the spec makes a distinction between files and file objects in the same paragraph), and 2) no implementation actually implements the periodic cleanup (which is a MAY requirement).
On the other hand, the spec guarantees that $XDG_RUNTIME_DIR itself exists until the last logout.
So given that and that the spec expressively tells to put sockets in that directory, I would say it's not an issue to worry about.