From ab184eb33c36d9a04c489c74c75678adacc80f9d Mon Sep 17 00:00:00 2001 From: David Levine Date: Sat, 1 Dec 2012 10:52:27 -0600 Subject: [PATCH] Copied atexit() code from fakesmtp.c to fakepop.c so that its pid file gets cleaned up. Also copied the sig handler. --- test/fakepop.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/fakepop.c b/test/fakepop.c index 7ff62a8..389588d 100644 --- a/test/fakepop.c +++ b/test/fakepop.c @@ -36,6 +36,8 @@ 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); @@ -183,6 +185,9 @@ main(int argc, char *argv[]) fprintf(pid, "%ld\n", (long) getpid()); fclose(pid); + signal(SIGTERM, handleterm); + atexit(killpidfile); + FD_ZERO(&readfd); FD_SET(l, &readfd); @@ -412,3 +417,27 @@ readmessage(FILE *file) 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); +} -- 1.7.10.4