From: Eric S. Raymond Date: Fri, 26 May 2017 11:22:24 +0000 (-0400) Subject: Flush log on interrupt, just for convenience. X-Git-Tag: seed~41 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=5c4fdc35ebeb58655c8d6ae7a2f883395f49ca0c;p=open-adventure.git Flush log on interrupt, just for convenience. --- diff --git a/main.c b/main.c index 881578d..7834084 100644 --- a/main.c +++ b/main.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "main.h" #include "misc.h" @@ -48,6 +49,14 @@ extern void initialise(); extern void score(long); extern int action(FILE *, long); +void sig_handler(int signo) +{ + if (signo == SIGINT) + if (logfp != NULL) + fflush(logfp); + exit(0); +} + /* * MAIN PROGRAM */ @@ -75,6 +84,7 @@ int main(int argc, char *argv[]) { fprintf(stderr, "advent: can't open logfile %s for write\n", optarg); + signal(SIGINT, sig_handler); break; case 'o': oldstyle = true;