diff --git a/src/doomdef.h b/src/doomdef.h index 24b52e8d..a0896094 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -138,6 +138,7 @@ #ifdef LOGMESSAGES extern FILE *logstream; +extern char logfilename[1024]; #endif //#define DEVELOP // Disable this for release builds to remove excessive cheat commands and enable MD5 checking and stuff, all in one go. :3 diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c index e7d87631..41874e9f 100644 --- a/src/sdl/i_main.c +++ b/src/sdl/i_main.c @@ -45,6 +45,7 @@ extern int SDL_main(int argc, char *argv[]); #ifdef LOGMESSAGES FILE *logstream = NULL; +char logfilename[1024]; #endif #ifndef DOXYGEN @@ -130,10 +131,12 @@ int main(int argc, char **argv) #ifdef LOGMESSAGES #ifdef DEFAULTDIR if (logdir) - logstream = fopen(va("%s/"DEFAULTDIR"/log.txt",logdir), "wt"); + strcpy(logfilename, va("%s/"DEFAULTDIR"/log.txt",logdir)); else #endif - logstream = fopen("./log.txt", "wt"); + strcpy(logfilename, "./log.txt"); + + logstream = fopen(logfilename, "wt"); #endif //I_OutputMsg("I_StartupSystem() ...\n"); diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 912e3fee..37d6dd79 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -3075,6 +3075,7 @@ static void I_Fork(void) int child; int status; int signum; + int c; child = fork(); @@ -3086,7 +3087,19 @@ static void I_Fork(void) case 0: break; default: - if (wait(&status) == -1) + if (logstream) + fclose(logstream);/* the child has this */ + + c = wait(&status); + +#ifdef LOGMESSAGES + /* By the way, exit closes files. */ + logstream = fopen(logfilename, "at"); +#else + logstream = 0; +#endif + + if (c == -1) { kill(child, SIGKILL); newsignalhandler_Warn("wait()");