Handle log file in parent properly

This commit is contained in:
James R 2019-12-13 16:51:49 -08:00
parent f460e83846
commit 2a016332c4
3 changed files with 20 additions and 3 deletions

View file

@ -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

View file

@ -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");

View file

@ -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()");