mirror of
https://github.com/moonlight-stream/Internet-Hosting-Tool.git
synced 2025-07-01 15:26:54 +00:00
Revert "Don't crash if the log file can't be opened"
We don't have a stdout to _dup2() into when run as a service. This reverts commit e9ddf91157a8903128d3030acd9985eb3c98a755.
This commit is contained in:
parent
c8e8af7d4b
commit
771e34f199
@ -11,8 +11,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <io.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
#include "relay.h"
|
#include "relay.h"
|
||||||
#include "..\version.h"
|
#include "..\version.h"
|
||||||
@ -836,27 +834,15 @@ void ResetLogFile(bool standaloneExe)
|
|||||||
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-old.log", oldLogFilePath, sizeof(oldLogFilePath));
|
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-old.log", oldLogFilePath, sizeof(oldLogFilePath));
|
||||||
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-current.log", currentLogFilePath, sizeof(currentLogFilePath));
|
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-current.log", currentLogFilePath, sizeof(currentLogFilePath));
|
||||||
|
|
||||||
|
// Close the existing stdout handle. This is important because otherwise
|
||||||
|
// it may still be open as stdout when we try to MoveFileEx below.
|
||||||
|
fclose(stdout);
|
||||||
|
|
||||||
// Rotate the current to the old log file
|
// Rotate the current to the old log file
|
||||||
MoveFileExA(currentLogFilePath, oldLogFilePath, MOVEFILE_REPLACE_EXISTING);
|
MoveFileExA(currentLogFilePath, oldLogFilePath, MOVEFILE_REPLACE_EXISTING);
|
||||||
|
|
||||||
// Open the new log file
|
|
||||||
HANDLE newLogHandle = CreateFileA(currentLogFilePath,
|
|
||||||
GENERIC_WRITE,
|
|
||||||
FILE_SHARE_READ | FILE_SHARE_DELETE,
|
|
||||||
nullptr,
|
|
||||||
CREATE_ALWAYS,
|
|
||||||
FILE_ATTRIBUTE_NORMAL,
|
|
||||||
nullptr);
|
|
||||||
if (newLogHandle == INVALID_HANDLE_VALUE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert the HANDLE to an fd (transfers ownership too)
|
|
||||||
int fd = _open_osfhandle((intptr_t)newLogHandle, _O_WRONLY);
|
|
||||||
|
|
||||||
// Redirect stdout to this new file
|
// Redirect stdout to this new file
|
||||||
_dup2(fd, _fileno(stdout));
|
freopen(currentLogFilePath, "w", stdout);
|
||||||
_close(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print a log header
|
// Print a log header
|
||||||
|
Loading…
x
Reference in New Issue
Block a user