python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / misc / drivers / spacenavd / configure-pidfile-path.patch
blobbc2cad9784cbe2f952472cbb92c8d9d334d23eca
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);
14 static char *cfgfile = DEF_CFGFILE;
15 static char *logfile = DEF_LOGFILE;
16 +static char *pidpath = NULL;
18 int main(int argc, char **argv)
20 @@ -270,7 +272,7 @@ static void cleanup(void)
21 remove_device(tmp);
24 - remove(PIDFILE);
25 + remove(pidfile_path());
28 static void daemonize(void)
29 @@ -314,7 +316,7 @@ static int write_pid_file(void)
30 FILE *fp;
31 int pid = getpid();
33 - if(!(fp = fopen(PIDFILE, "w"))) {
34 + if(!(fp = fopen(pidfile_path(), "w"))) {
35 return -1;
37 fprintf(fp, "%d\n", pid);
38 @@ -329,7 +331,7 @@ static int find_running_daemon(void)
39 struct sockaddr_un addr;
41 /* try to open the pid-file */
42 - if(!(fp = fopen(PIDFILE, "r"))) {
43 + if(!(fp = fopen(pidfile_path(), "r"))) {
44 return -1;
46 if(fscanf(fp, "%d\n", &pid) != 1) {
47 @@ -356,6 +358,22 @@ static int find_running_daemon(void)
48 return pid;
51 +char *pidfile_path(void)
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 + }
67 static void handle_events(fd_set *rset)
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"
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"