diff --git a/ampr-ripd.c b/ampr-ripd.c
index b9609f6..9ec7058 100644
--- a/ampr-ripd.c
+++ b/ampr-ripd.c
@@ -114,6 +114,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 */
@@ -1454,6 +1456,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();
@@ -1594,6 +1597,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)
{
@@ -1752,6 +1756,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 */