#include <netdb.h>
#include <errno.h>
#include <sys/socket.h>
+#include <netinet/in.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/stat.h>
continue; \
}
+static void killpidfile(void);
+static void handleterm(int);
static void putpop(int, char *);
static void putpopbulk(int, char *);
static int getpop(int, char *, ssize_t);
fprintf(pid, "%ld\n", (long) getpid());
fclose(pid);
+ signal(SIGTERM, handleterm);
+ atexit(killpidfile);
+
FD_ZERO(&readfd);
FD_SET(l, &readfd);
return buffer;
}
+
+/*
+ * Handle a SIGTERM
+ */
+
+static void
+handleterm(int signal)
+{
+ (void) signal;
+
+ killpidfile();
+ fflush(NULL);
+ _exit(1);
+}
+
+/*
+ * Get rid of our pid file
+ */
+
+static void
+killpidfile(void)
+{
+ unlink(PIDFILE);
+}