diff options
author | rubidium <rubidium@openttd.org> | 2013-11-25 09:20:35 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2013-11-25 09:20:35 +0000 |
commit | 43edd2409e62ef90c86c227893e04d1197bc8766 (patch) | |
tree | 46d39baba97b8c839064202f627b02d2086cadf6 /src/dedicated.cpp | |
parent | ee0aa389a8523a44475d192100b21b2f9b413082 (diff) | |
download | openttd-43edd2409e62ef90c86c227893e04d1197bc8766.tar.xz |
(svn r26098) -Fix: close the log file when OpenTTD was forked and finally closed
Diffstat (limited to 'src/dedicated.cpp')
-rw-r--r-- | src/dedicated.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/dedicated.cpp b/src/dedicated.cpp index 83c6c1d21..6342bc247 100644 --- a/src/dedicated.cpp +++ b/src/dedicated.cpp @@ -13,7 +13,8 @@ #ifdef ENABLE_NETWORK -char *_log_file; ///< File to reroute output of a forked OpenTTD to +char *_log_file = NULL; ///< File to reroute output of a forked OpenTTD to +FILE *_log_fd = NULL; ///< File to reroute output of a forked OpenTTD to #if defined(UNIX) && !defined(__MORPHOS__) @@ -39,20 +40,18 @@ void DedicatedFork() exit(1); case 0: { // We're the child - FILE *f; - /* Open the log-file to log all stuff too */ - f = fopen(_log_file, "a"); - if (f == NULL) { + _log_fd = fopen(_log_file, "a"); + if (_log_fd == NULL) { perror("Unable to open logfile"); exit(1); } /* Redirect stdout and stderr to log-file */ - if (dup2(fileno(f), fileno(stdout)) == -1) { + if (dup2(fileno(_log_fd), fileno(stdout)) == -1) { perror("Rerouting stdout"); exit(1); } - if (dup2(fileno(f), fileno(stderr)) == -1) { + if (dup2(fileno(_log_fd), fileno(stderr)) == -1) { perror("Rerouting stderr"); exit(1); } |