nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1diff --git a/back.c b/back.c
2index f364e31..c1810dc 100644
3--- a/back.c
4+++ b/back.c
5@@ -26,7 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
6 #include "cmd.h"
7
8 #define CFGFILE "/etc/spnavrc"
9-#define PIDFILE "/var/run/spnavd.pid"
10
11 int get_daemon_pid(void);
12 static int update_cfg(void);
13@@ -97,11 +96,26 @@ int get_daemon_pid(void)
14 {
15 FILE *fp;
16 char buf[64];
17+ char* xdg_runtime_dir;
18+ char* pidfile;
19
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");
23+ return -1;
24+ }
25+ pidfile = malloc(strlen(xdg_runtime_dir) + strlen("/spnavd.pid") + 1);
26+ if (pidfile == NULL) {
27+ fprintf(stderr, "failed to allocate memory\n");
28+ return -1;
29+ }
30+ sprintf(pidfile, "%s/spnavd.pid", xdg_runtime_dir);
31+
32+ if(!(fp = fopen(pidfile, "r"))) {
33 fprintf(stderr, "no spacenav pid file, can't find daemon\n");
34+ free(pidfile);
35 return -1;
36 }
37+ free(pidfile);
38 if(!fgets(buf, sizeof buf, fp) || !isdigit(buf[0])) {
39 fprintf(stderr, "corrupted pidfile, can't find the daemon\n");
40 fclose(fp);