about summary refs log tree commit diff
path: root/pkgs/misc/drivers
diff options
context:
space:
mode:
authorsohalt <sohalt@sohalt.net>2021-04-20 20:41:56 +0200
committerGabriel Ebner <gebner@gebner.org>2021-05-22 12:48:57 +0200
commitc66caa6a90bd856ca630f6ad4dd876dbf3313d59 (patch)
tree90191365ef52877323fe7dc0b9986caba61422d1 /pkgs/misc/drivers
parentdfb36eed7694f46c7eaf5a04c2a774a81715df65 (diff)
spaacenavd: config file in $XDG_CONFIG_HOME
Diffstat (limited to 'pkgs/misc/drivers')
-rw-r--r--pkgs/misc/drivers/spacenavd/configure-cfgfile-path.patch63
-rw-r--r--pkgs/misc/drivers/spacenavd/default.nix3
2 files changed, 66 insertions, 0 deletions
diff --git a/pkgs/misc/drivers/spacenavd/configure-cfgfile-path.patch b/pkgs/misc/drivers/spacenavd/configure-cfgfile-path.patch
new file mode 100644
index 0000000000000..268282e96eae6
--- /dev/null
+++ b/pkgs/misc/drivers/spacenavd/configure-cfgfile-path.patch
@@ -0,0 +1,63 @@
+diff --git a/src/spnavd.c b/src/spnavd.c
+index 2d4eca6..a5227ed 100644
+--- a/src/spnavd.c
++++ b/src/spnavd.c
+@@ -27,6 +27,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ #include <sys/select.h>
+ #include <sys/socket.h>
+ #include <sys/un.h>
++#include <sys/types.h>
++#include <pwd.h>
+ #include "spnavd.h"
+ #include "logger.h"
+ #include "dev.h"
+@@ -47,13 +49,39 @@ 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* config_path;
++char* cfg_path()
++{
++	char* buf;
++	if((buf = getenv("XDG_CONFIG_HOME"))) {
++		if(config_path == NULL) {
++			config_path = malloc(strlen(buf) + strlen("/spnavrc") + 1);
++			if ( config_path != NULL) {
++				sprintf(config_path, "%s/spnavrc", buf);
++			}
++		};
++		return config_path;
++	} else {
++		if (!(buf = getenv("HOME"))) {
++			struct passwd *pw = getpwuid(getuid());
++			buf = pw->pw_dir;
++		}
++		config_path = malloc(strlen(buf) + strlen("/.config/spnavrc") + 1);
++		if ( config_path != NULL) {
++			sprintf(config_path, "%s/.config/spnavrc", buf);
++		}
++		return config_path;
++	}
++}
++
++static char *cfgfile = NULL;
+ static char *logfile = DEF_LOGFILE;
+ static char *pidpath = NULL;
+ 
+ int main(int argc, char **argv)
+ {
+ 	int i, pid, ret, become_daemon = 1;
++	cfgfile = cfg_path();
+ 
+ 	for(i=1; i<argc; i++) {
+ 		if(argv[i][0] == '-') {
+@@ -247,7 +275,7 @@ static void print_usage(const char *argv0)
+ 	printf("usage: %s [options]\n", argv0);
+ 	printf("options:\n");
+ 	printf(" -d: do not daemonize\n");
+-	printf(" -c <file>: config file path (default: " DEF_CFGFILE ")\n");
++	printf(" -c <file>: config file path (default: %s)\n", cfg_path());
+ 	printf(" -l <file>|syslog: log file path or log to syslog (default: " DEF_LOGFILE ")\n");
+ 	printf(" -v: verbose output\n");
+ 	printf(" -V,-version: print version number and exit\n");
diff --git a/pkgs/misc/drivers/spacenavd/default.nix b/pkgs/misc/drivers/spacenavd/default.nix
index feb00c8b39928..5cc1b46013322 100644
--- a/pkgs/misc/drivers/spacenavd/default.nix
+++ b/pkgs/misc/drivers/spacenavd/default.nix
@@ -23,6 +23,9 @@ stdenv.mkDerivation rec {
     # Changes the pidfile path from /run/spnavd.pid to $XDG_RUNTIME_DIR/spnavd.pid
     # to allow for a user service
     ./configure-pidfile-path.patch
+    # Changes the config file path from /etc/spnavrc to $XDG_CONFIG_HOME/spnavrc or $HOME/.config/spnavrc
+    # to allow for a user service
+    ./configure-cfgfile-path.patch
   ];
 
   buildInputs = [ libX11 ]