File mouseemu.pidfile.patch of Package mouseemu

#! /bin/sh /usr/share/dpatch/dpatch-run
## 63_pidfile.dpatch.dpatch by Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: create pidfile in /var/run/mouseemu.pid

@DPATCH@
---
 mouseemu.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

--- a/mouseemu.c
+++ b/mouseemu.c
@@ -755,6 +755,7 @@ int main(int argc, char *argv[])
 			
 		struct sigaction sa;
 		sigset_t mask, oldmask;
+		FILE *pidfile;
 			       
 		/* SIGHUP and SIGALRM are only useful in the child */
 		memset(&sa, 0, sizeof(sa));
@@ -762,6 +763,15 @@ int main(int argc, char *argv[])
 		sigaction(SIGHUP, &sa, NULL);
 		sigaction(SIGALRM, &sa, NULL);
 
+		/* write PID file so the user can signal us for device rescans */
+		pidfile = fopen("/var/run/mouseemu.pid", "w");
+		if (!pidfile) {
+			perror("mouseemu: can't open /var/run/mouseemu.pid");
+			exit(1);
+		}
+		fprintf(pidfile, "%d\n", pid);
+		fclose(pidfile);
+
 		/*we start only after we received the first sigusr1 from child:*/
 
 		sigemptyset(&mask);