about summary refs log tree commit diff
path: root/pkgs/misc/drivers
diff options
context:
space:
mode:
authorsohalt <sohalt@sohalt.net>2021-04-06 19:21:21 +0200
committerGabriel Ebner <gebner@gebner.org>2021-05-22 12:48:38 +0200
commitdfb36eed7694f46c7eaf5a04c2a774a81715df65 (patch)
tree481684ab6c1d05eb4f669ee3147538e81d404cc9 /pkgs/misc/drivers
parentbe01cb8b97bc0e449e44da7a79e1dabde204fd8c (diff)
spacenavd: pidfile in $XDG_RUNTIME_DIR
Diffstat (limited to 'pkgs/misc/drivers')
-rw-r--r--pkgs/misc/drivers/spacenavd/configure-pidfile-path.patch82
-rw-r--r--pkgs/misc/drivers/spacenavd/default.nix3
2 files changed, 85 insertions, 0 deletions
diff --git a/pkgs/misc/drivers/spacenavd/configure-pidfile-path.patch b/pkgs/misc/drivers/spacenavd/configure-pidfile-path.patch
new file mode 100644
index 0000000000000..bc2cad9784cbe
--- /dev/null
+++ b/pkgs/misc/drivers/spacenavd/configure-pidfile-path.patch
@@ -0,0 +1,82 @@
+diff --git a/src/spnavd.c b/src/spnavd.c
+index 03080da..2d4eca6 100644
+--- a/src/spnavd.c
++++ b/src/spnavd.c
+@@ -42,12 +42,14 @@ static void cleanup(void);
+ static void daemonize(void);
+ static int write_pid_file(void);
+ static int find_running_daemon(void);
++static char *pidfile_path(void);
+ static void handle_events(fd_set *rset);
+ static void sig_handler(int s);
+ static char *fix_path(char *str);
+ 
+ static char *cfgfile = DEF_CFGFILE;
+ static char *logfile = DEF_LOGFILE;
++static char *pidpath = NULL;
+ 
+ int main(int argc, char **argv)
+ {
+@@ -270,7 +272,7 @@ static void cleanup(void)
+ 		remove_device(tmp);
+ 	}
+ 
+-	remove(PIDFILE);
++	remove(pidfile_path());
+ }
+ 
+ static void daemonize(void)
+@@ -314,7 +316,7 @@ static int write_pid_file(void)
+ 	FILE *fp;
+ 	int pid = getpid();
+ 
+-	if(!(fp = fopen(PIDFILE, "w"))) {
++	if(!(fp = fopen(pidfile_path(), "w"))) {
+ 		return -1;
+ 	}
+ 	fprintf(fp, "%d\n", pid);
+@@ -329,7 +331,7 @@ static int find_running_daemon(void)
+ 	struct sockaddr_un addr;
+ 
+ 	/* try to open the pid-file */
+-	if(!(fp = fopen(PIDFILE, "r"))) {
++	if(!(fp = fopen(pidfile_path(), "r"))) {
+ 		return -1;
+ 	}
+ 	if(fscanf(fp, "%d\n", &pid) != 1) {
+@@ -356,6 +358,22 @@ static int find_running_daemon(void)
+ 	return pid;
+ }
+ 
++char *pidfile_path(void)
++{
++	char *xdg_runtime_dir;
++	if((xdg_runtime_dir = getenv("XDG_RUNTIME_DIR"))) {
++		if ( pidpath == NULL ) {
++			pidpath = malloc(strlen(xdg_runtime_dir) + strlen("/spnavd.pid") + 1);
++			if ( pidpath != NULL ) {
++				sprintf(pidpath, "%s/spnavd.pid", xdg_runtime_dir);
++			}
++		};
++		return pidpath;
++	} else {
++		return DEFAULT_PIDFILE;
++	}
++}
++
+ static void handle_events(fd_set *rset)
+ {
+ 	int dev_fd, hotplug_fd;
+diff --git a/src/spnavd.h b/src/spnavd.h
+index 2d1c48b..17d22d3 100644
+--- a/src/spnavd.h
++++ b/src/spnavd.h
+@@ -26,7 +26,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ #define DEF_CFGFILE		"/etc/spnavrc"
+ #define DEF_LOGFILE		"/var/log/spnavd.log"
+ 
+-#define PIDFILE		"/var/run/spnavd.pid"
++#define DEFAULT_PIDFILE		"/run/spnavd.pid"
+ #define DEFAULT_SOCK_NAME	"/run/spnav.sock"
+ #define SYSLOG_ID	"spnavd"
+ 
diff --git a/pkgs/misc/drivers/spacenavd/default.nix b/pkgs/misc/drivers/spacenavd/default.nix
index 9970c97780973..feb00c8b39928 100644
--- a/pkgs/misc/drivers/spacenavd/default.nix
+++ b/pkgs/misc/drivers/spacenavd/default.nix
@@ -20,6 +20,9 @@ stdenv.mkDerivation rec {
     # Changes the socket path from /run/spnav.sock to $XDG_RUNTIME_DIR/spnav.sock
     # to allow for a user service
     ./configure-socket-path.patch
+    # Changes the pidfile path from /run/spnavd.pid to $XDG_RUNTIME_DIR/spnavd.pid
+    # to allow for a user service
+    ./configure-pidfile-path.patch
   ];
 
   buildInputs = [ libX11 ]