diff options
author | sohalt <sohalt@sohalt.net> | 2021-04-20 20:46:08 +0200 |
---|---|---|
committer | Gabriel Ebner <gebner@gebner.org> | 2021-05-22 12:48:58 +0200 |
commit | 6172e51fa99d3a6bebca3801c764e9aa76526f8a (patch) | |
tree | 1cdfee7639f41765a837314a73450b96b31e44ab /pkgs/applications/misc/spnavcfg | |
parent | c66caa6a90bd856ca630f6ad4dd876dbf3313d59 (diff) |
spnavcfg: pidfile in $XDG_RUNTIME_DIR
Diffstat (limited to 'pkgs/applications/misc/spnavcfg')
-rw-r--r-- | pkgs/applications/misc/spnavcfg/configure-pidfile-path.patch | 40 | ||||
-rw-r--r-- | pkgs/applications/misc/spnavcfg/default.nix | 6 |
2 files changed, 46 insertions, 0 deletions
diff --git a/pkgs/applications/misc/spnavcfg/configure-pidfile-path.patch b/pkgs/applications/misc/spnavcfg/configure-pidfile-path.patch new file mode 100644 index 0000000000000..a420fcbc07b82 --- /dev/null +++ b/pkgs/applications/misc/spnavcfg/configure-pidfile-path.patch @@ -0,0 +1,40 @@ +diff --git a/back.c b/back.c +index f364e31..c1810dc 100644 +--- a/back.c ++++ b/back.c +@@ -26,7 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. + #include "cmd.h" + + #define CFGFILE "/etc/spnavrc" +-#define PIDFILE "/var/run/spnavd.pid" + + int get_daemon_pid(void); + static int update_cfg(void); +@@ -97,11 +96,26 @@ int get_daemon_pid(void) + { + FILE *fp; + char buf[64]; ++ char* xdg_runtime_dir; ++ char* pidfile; + +- if(!(fp = fopen(PIDFILE, "r"))) { ++ if(!(xdg_runtime_dir = getenv("XDG_RUNTIME_DIR"))){ ++ fprintf(stderr, "XDG_RUNTIME_DIR not set, can't find spacenav pid file\n"); ++ return -1; ++ } ++ pidfile = malloc(strlen(xdg_runtime_dir) + strlen("/spnavd.pid") + 1); ++ if (pidfile == NULL) { ++ fprintf(stderr, "failed to allocate memory\n"); ++ return -1; ++ } ++ sprintf(pidfile, "%s/spnavd.pid", xdg_runtime_dir); ++ ++ if(!(fp = fopen(pidfile, "r"))) { + fprintf(stderr, "no spacenav pid file, can't find daemon\n"); ++ free(pidfile); + return -1; + } ++ free(pidfile); + if(!fgets(buf, sizeof buf, fp) || !isdigit(buf[0])) { + fprintf(stderr, "corrupted pidfile, can't find the daemon\n"); + fclose(fp); diff --git a/pkgs/applications/misc/spnavcfg/default.nix b/pkgs/applications/misc/spnavcfg/default.nix index 253549099de85..1d01b99a4afb7 100644 --- a/pkgs/applications/misc/spnavcfg/default.nix +++ b/pkgs/applications/misc/spnavcfg/default.nix @@ -11,6 +11,12 @@ stdenv.mkDerivation rec { sha256 = "180mkdis15gxs79rr3f7hpwa1p6v81bybw37pzzdjnmqwqrc08a0"; }; + patches = [ + # Changes the pidfile path from /run/spnavd.pid to $XDG_RUNTIME_DIR/spnavd.pid + # to allow for a user service + ./configure-pidfile-path.patch + ]; + postPatch = '' sed -i s/4775/775/ Makefile.in ''; |