pid file gets cleaned up. Also copied the sig handler.
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);
+}