Blob Blame History Raw
diff --git a/ampr-ripd.c b/ampr-ripd.c
index a9c75c3..d376961 100644
--- a/ampr-ripd.c
+++ b/ampr-ripd.c
@@ -110,6 +110,8 @@
 
 #define RTAB_FILE	"/etc/iproute2/rt_tables"	/* route tables */
 
+#define PID_FILE	"/var/run/ampr-ripd.pid"	/* pid file */
+
 #define	BUFFERSIZE	8192
 #define MYIPSIZE	25	/* max number of local interface IPs */
 #define MAXIGNORE	10	/* max number of hosts in the ignore list */
@@ -1474,6 +1476,7 @@ static void on_term(int sig)
 #ifdef HAVE_DEBUG
 	if (debug && verbose) fprintf(stderr, "SIGTERM/SIGKILL received.\n");
 #endif
+	unlink(PID_FILE);
 	close(fwsd);
 	close(tunsd);
 	route_delete_all();
@@ -1615,6 +1618,7 @@ int main(int argc, char **argv)
 	char *pload;
 	int len, plen;
 	int lval;
+	FILE *pidfile;
 
 	while ((p = getopt(argc, argv, "dvsrh?i:a:p:t:m:w:f:e:x:")) != -1)
 	{
@@ -1848,6 +1852,10 @@ int main(int argc, char **argv)
 	signal(SIGHUP, on_hup);
 	signal(SIGALRM, on_alarm);
 
+	pidfile = fopen(PID_FILE, "w");
+	fprintf(pidfile, "%d\n", (int)getpid());
+	fclose(pidfile);
+
 	alarm(30);
 
 	/* daemon or debug */