From: David Levine Date: Sat, 1 Dec 2012 16:52:27 +0000 (-0600) Subject: Copied atexit() code from fakesmtp.c to fakepop.c so that its X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=ab184eb33c36d9a04c489c74c75678adacc80f9d;p=mmh Copied atexit() code from fakesmtp.c to fakepop.c so that its pid file gets cleaned up. Also copied the sig handler. --- 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); +}