diff --git a/ampr-ripd.c b/ampr-ripd.c
index 697a48e..3af51dc 100644
--- a/ampr-ripd.c
+++ b/ampr-ripd.c
@@ -102,6 +102,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 */
@@ -1423,6 +1425,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();
@@ -1496,6 +1499,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:")) != -1)
{
@@ -1730,6 +1734,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);
+
/* daemon or debug */
if (debug) fprintf(stderr, "Waiting for RIPv2 broadcasts...\n");