Skip to content

Commit

Permalink
XDG base directory: lock file in XDG_RUNTIME_DIR
Browse files Browse the repository at this point in the history
Continuation of nicm#96 implementation.

From https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html:

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

This also may provide slight performance benefits to this as
XDG_RUNTIME_DIR is often set to a directory under /tmp which some
systems configure to be mounted as tmpfs.

If XDG_RUNTIME_DIR is not set or is an empty string, the old behaviour
of the user's home directory is used.
  • Loading branch information
mikejzx committed Dec 1, 2023
1 parent ab3dbb6 commit 677e191
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions fdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ main(int argc, char **argv)
/* Find the config file. */
if (conf.conf_file == NULL) {
/* If no file specified, try $XDG_CONFIG_HOME, then ~ then /etc. */
if ((s = getenv("XDG_CONFIG_HOME")) != NULL) {
s = getenv("XDG_CONFIG_HOME");
if (s != NULL && *s != '\0') {
xasprintf(&conf.conf_file, "%s/%s", s, CONFFILE);
if (access(conf.conf_file, R_OK) != 0) {
xfree(conf.conf_file);
Expand Down Expand Up @@ -711,7 +712,15 @@ main(int argc, char **argv)
if (geteuid() == 0)
lock = xstrdup(SYSLOCKFILE);
else
xasprintf(&lock, "%s/%s", conf.user_home, LOCKFILE_HOME);
{
/* Lockfile is stored in XDG_RUNTIME_DIR if provided.
* If not, we store it in the user's home directory. */
s = getenv("XDG_RUNTIME_DIR");
if (s != NULL && *s != '\0')
xasprintf(&lock, "%s/%s", s, LOCKFILE);
else
xasprintf(&lock, "%s/%s", conf.user_home, LOCKFILE_HOME);
}
}
retry:
if (*lock != '\0' && !conf.allow_many) {
Expand Down

0 comments on commit 677e191

Please sign in to comment.