lol

spacenavd: pidfile in $XDG_RUNTIME_DIR

authored by

sohalt and committed by
Gabriel Ebner
dfb36eed be01cb8b

+85
+82
pkgs/misc/drivers/spacenavd/configure-pidfile-path.patch
··· 1 + diff --git a/src/spnavd.c b/src/spnavd.c 2 + index 03080da..2d4eca6 100644 3 + --- a/src/spnavd.c 4 + +++ b/src/spnavd.c 5 + @@ -42,12 +42,14 @@ static void cleanup(void); 6 + static void daemonize(void); 7 + static int write_pid_file(void); 8 + static int find_running_daemon(void); 9 + +static char *pidfile_path(void); 10 + static void handle_events(fd_set *rset); 11 + static void sig_handler(int s); 12 + static char *fix_path(char *str); 13 + 14 + static char *cfgfile = DEF_CFGFILE; 15 + static char *logfile = DEF_LOGFILE; 16 + +static char *pidpath = NULL; 17 + 18 + int main(int argc, char **argv) 19 + { 20 + @@ -270,7 +272,7 @@ static void cleanup(void) 21 + remove_device(tmp); 22 + } 23 + 24 + - remove(PIDFILE); 25 + + remove(pidfile_path()); 26 + } 27 + 28 + static void daemonize(void) 29 + @@ -314,7 +316,7 @@ static int write_pid_file(void) 30 + FILE *fp; 31 + int pid = getpid(); 32 + 33 + - if(!(fp = fopen(PIDFILE, "w"))) { 34 + + if(!(fp = fopen(pidfile_path(), "w"))) { 35 + return -1; 36 + } 37 + fprintf(fp, "%d\n", pid); 38 + @@ -329,7 +331,7 @@ static int find_running_daemon(void) 39 + struct sockaddr_un addr; 40 + 41 + /* try to open the pid-file */ 42 + - if(!(fp = fopen(PIDFILE, "r"))) { 43 + + if(!(fp = fopen(pidfile_path(), "r"))) { 44 + return -1; 45 + } 46 + if(fscanf(fp, "%d\n", &pid) != 1) { 47 + @@ -356,6 +358,22 @@ static int find_running_daemon(void) 48 + return pid; 49 + } 50 + 51 + +char *pidfile_path(void) 52 + +{ 53 + + char *xdg_runtime_dir; 54 + + if((xdg_runtime_dir = getenv("XDG_RUNTIME_DIR"))) { 55 + + if ( pidpath == NULL ) { 56 + + pidpath = malloc(strlen(xdg_runtime_dir) + strlen("/spnavd.pid") + 1); 57 + + if ( pidpath != NULL ) { 58 + + sprintf(pidpath, "%s/spnavd.pid", xdg_runtime_dir); 59 + + } 60 + + }; 61 + + return pidpath; 62 + + } else { 63 + + return DEFAULT_PIDFILE; 64 + + } 65 + +} 66 + + 67 + static void handle_events(fd_set *rset) 68 + { 69 + int dev_fd, hotplug_fd; 70 + diff --git a/src/spnavd.h b/src/spnavd.h 71 + index 2d1c48b..17d22d3 100644 72 + --- a/src/spnavd.h 73 + +++ b/src/spnavd.h 74 + @@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. 75 + #define DEF_CFGFILE "/etc/spnavrc" 76 + #define DEF_LOGFILE "/var/log/spnavd.log" 77 + 78 + -#define PIDFILE "/var/run/spnavd.pid" 79 + +#define DEFAULT_PIDFILE "/run/spnavd.pid" 80 + #define DEFAULT_SOCK_NAME "/run/spnav.sock" 81 + #define SYSLOG_ID "spnavd" 82 +
+3
pkgs/misc/drivers/spacenavd/default.nix
··· 20 20 # Changes the socket path from /run/spnav.sock to $XDG_RUNTIME_DIR/spnav.sock 21 21 # to allow for a user service 22 22 ./configure-socket-path.patch 23 + # Changes the pidfile path from /run/spnavd.pid to $XDG_RUNTIME_DIR/spnavd.pid 24 + # to allow for a user service 25 + ./configure-pidfile-path.patch 23 26 ]; 24 27 25 28 buildInputs = [ libX11 ]