cod icon indicating copy to clipboard operation
cod copied to clipboard

Move socket to `$XDG_RUNTIME_DIR/cod`

Open BurnerWah opened this issue 4 years ago • 4 comments

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_DIR is 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.

BurnerWah avatar Oct 18 '21 01:10 BurnerWah

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?

dim-an avatar Oct 18 '21 16:10 dim-an

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.

dim-an avatar Oct 18 '21 16:10 dim-an

I could try and figure that out during the weekend.

BurnerWah avatar Oct 21 '21 16:10 BurnerWah

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.

SuperSandro2000 avatar Jan 21 '22 01:01 SuperSandro2000