Hacker News new | ask | show | jobs
by searealist 1388 days ago
For many applications it is enough. For others, such as placing a UDS in a user's home directory or temp folder, it may not be. Often times you don't know ahead of time what the path may be.
1 comments

Unix sockets should definitely not be in any non-tmpfs filesystem, subdirectories of /run are the sole place they should be.
Care to justify your advice?
They are ephemeral, they hold no data after being closed and backups of them aren't useful. Only the name is needed, therefore a tmpfs is the place to store them.
The name of the socket file/the fact that it exists contains data.

As a result, it's useful to keep them in non-tmpfs paths that can survive a reboot. That way, very simple programs can use them as sort of a config file: `$XDG_HOME/myprogram/do_xyz.sock`.

Additionally, persistent sockets created once at program install time can help coordinate multiple launches of whatever uses them (e.g. by having servers flock(2) the socket or fight over binding to it as a mutex). For programs whose "server" component isn't managed by a service manager, but can instead be launched many times in response to some user action, that can simplify things.

And if I want to run a daemon as a user where should the socket go?
For example the OpenSSH agent uses this path:

/run/user/$UID/openssh_agent

Several things place sockets there, some other stuff places the socket in a subdirectory.