Move socket to `$XDG_RUNTIME_DIR/cod`
Currently, cod's socket and lock file are placed at $XDG_DATA_DIR/cod/var, which isn't a particularly standard location for them.
The XDG Base Directory Specification specifies the locations which various files should be stored at. It states:
There is a single base directory relative to which user-specific runtime files and other file objects should be placed. This directory is defined by the environment variable
$XDG_RUNTIME_DIR.
It further states a fallback for when the variable isn't set:
If
$XDG_RUNTIME_DIRis not set applications should fall back to a replacement directory with similar capabilities and print a warning message.
This PR changes it so that cod will use $XDG_RUNTIME_DIR/cod for the socket & lockfile when $XDG_RUNTIME_DIR is set, and will fall back upon $XDG_DATA_DIR/cod/var.
Since $XDG_RUNTIME_DIR has no default value, falling back upon the old seems like the best choice there.
In my experience, $XDG_RUNTIME_DIR is usually set by pam_systemd, and ends up being set to /run/user/$UID (which it creates it as a tmpfs). However, I'd prefer to just go with general spec compliance here.
I'm probably not the best with Go programming, but I think this implementation should work fine.
I like you patch, but I have one concern.
If someone is running version before your change and updates cod binary to version containing your patch. cod will go crazy I believe. Am I right? Can we do something with this?
I mean old running version of cod will continue to listen old socket, and new cod binary will try to connect to new socket and I believe two version of cod working on the same DB will run in parallel. That's not good.
I could try and figure that out during the weekend.
You will get an error like this:
openstack --help
cod: error: dial unix /home/user/.local/share/cod/var/cod.sock: connect: no such file or directory
cod: error: dial unix /home/user/.local/share/cod/var/cod.sock: connect: no such file or directory
closing and reopeing your shell or sourcing your rc file fixes that.