1 diff --git a/back.c b/back.c
2 index f364e31..c1810dc 100644
5 @@ -26,7 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
8 #define CFGFILE "/etc/spnavrc"
9 -#define PIDFILE "/var/run/spnavd.pid"
11 int get_daemon_pid(void);
12 static int update_cfg(void);
13 @@ -97,11 +96,26 @@ int get_daemon_pid(void)
17 + char* xdg_runtime_dir;
20 - if(!(fp = fopen(PIDFILE, "r"))) {
21 + if(!(xdg_runtime_dir = getenv("XDG_RUNTIME_DIR"))){
22 + fprintf(stderr, "XDG_RUNTIME_DIR not set, can't find spacenav pid file\n");
25 + pidfile = malloc(strlen(xdg_runtime_dir) + strlen("/spnavd.pid") + 1);
26 + if (pidfile == NULL) {
27 + fprintf(stderr, "failed to allocate memory\n");
30 + sprintf(pidfile, "%s/spnavd.pid", xdg_runtime_dir);
32 + if(!(fp = fopen(pidfile, "r"))) {
33 fprintf(stderr, "no spacenav pid file, can't find daemon\n");
38 if(!fgets(buf, sizeof buf, fp) || !isdigit(buf[0])) {
39 fprintf(stderr, "corrupted pidfile, can't find the daemon\n");