spnavcfg: pidfile in $XDG_RUNTIME_DIR

authored by

sohalt and committed by
Gabriel Ebner
6172e51f c66caa6a

+46
+40
pkgs/applications/misc/spnavcfg/configure-pidfile-path.patch
···
··· 1 + diff --git a/back.c b/back.c 2 + index 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);
+6
pkgs/applications/misc/spnavcfg/default.nix
··· 11 sha256 = "180mkdis15gxs79rr3f7hpwa1p6v81bybw37pzzdjnmqwqrc08a0"; 12 }; 13 14 postPatch = '' 15 sed -i s/4775/775/ Makefile.in 16 '';
··· 11 sha256 = "180mkdis15gxs79rr3f7hpwa1p6v81bybw37pzzdjnmqwqrc08a0"; 12 }; 13 14 + patches = [ 15 + # Changes the pidfile path from /run/spnavd.pid to $XDG_RUNTIME_DIR/spnavd.pid 16 + # to allow for a user service 17 + ./configure-pidfile-path.patch 18 + ]; 19 + 20 postPatch = '' 21 sed -i s/4775/775/ Makefile.in 22 '';