From 62252daffe43bba7438808c5f0d3d07cc18c6e7d Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Fri, 12 Nov 2021 10:15:14 +0100 Subject: [PATCH] index pid/lock file: use /run/user/$uid/ if it exists even if XDG_RUNTIME_DIR is not set: else cron-launched and desktop-lauchned indexers could use a different lockfile --- src/common/rclconfig.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index 0dcd415c..69c613ae 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -1398,7 +1398,19 @@ string RclConfig::getIdxStatusFile() const // Thanks to user Madhu for this fix. string RclConfig::getPidfile() const { + string fn; +#ifndef _WIN32 const char *p = getenv("XDG_RUNTIME_DIR"); + string rundir; + if (nullptr == p) { + // Problem is, we may have been launched outside the desktop, maybe by cron. Basing + // everything on XDG_RUNTIME_DIR was a mistake, sometimes resulting in different pidfiles + // being used by recollindex instances. So explicitely test for /run/user/$uid + rundir = path_cat("/run/user", lltodecstr(getuid())); + if (path_isdir(rundir)) { + p = rundir.c_str(); + } + } if (p) { string base = path_canon(p); string digest, hex; @@ -1406,9 +1418,15 @@ string RclConfig::getPidfile() const path_catslash(cfdir); MD5String(cfdir, digest); MD5HexPrint(digest, hex); - return path_cat(base, "/recoll-" + hex + "-index.pid"); - } - return path_cat(getCacheDir(), "index.pid"); + fn = path_cat(base, "recoll-" + hex + "-index.pid"); + goto out; + } +#endif // ! _WIN32 + + fn = path_cat(getCacheDir(), "index.pid"); +out: + LOGINF("RclConfig: pid/lock file: " << fn << "\n"); + return fn; }