Skip to content

Commit

Permalink
[host] windows: move the service log to the temp directory
Browse files Browse the repository at this point in the history
Often this log is provided instead of the actual host log, as this
log is largely useless for debugging this moves it to the temp
directory out of view of the user.
  • Loading branch information
gnif committed Mar 6, 2024
1 parent 9123984 commit 6a72633
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions host/platform/Windows/src/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct AppState

char executable[MAX_PATH + 1];
char systemLogDir[MAX_PATH];
char systemTempDir[MAX_PATH];
char * osVersion;
HWND messageWnd;
UINT shellHookMsg;
Expand Down Expand Up @@ -299,6 +300,11 @@ static BOOL WINAPI CtrlHandler(DWORD dwCtrlType)
return FALSE;
}

const char * getSystemTempDirectory(void)
{
return app.systemTempDir;
}

const char *getSystemLogDirectory(void)
{
return app.systemLogDir;
Expand Down Expand Up @@ -340,6 +346,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine

GetModuleFileName(NULL, app.executable, sizeof(app.executable));
populateSystemLogDirectory();
GetTempPathA(sizeof(app.systemTempDir), app.systemTempDir);

if (HandleService(app.argc, app.argv))
return LG_HOST_EXIT_FAILED;
Expand Down
3 changes: 2 additions & 1 deletion host/platform/Windows/src/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ struct MSG_CALL_FUNCTION
};

bool windowsSetupAPI(void);
const char *getSystemLogDirectory(void);
const char * getSystemTempDirectory(void);
const char * getSystemLogDirectory(void);
LRESULT sendAppMessage(UINT Msg, WPARAM wParam, LPARAM lParam);
8 changes: 7 additions & 1 deletion host/platform/Windows/src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ void doLogReal(const char * fmt, ...)
static void setupLogging(void)
{
char logFilePath[MAX_PATH];
if (!PathCombineA(logFilePath, getSystemLogDirectory(), LOG_NAME))

// remove the old service log file if it exists
if (PathCombineA(logFilePath, getSystemLogDirectory(), LOG_NAME))
unlink(logFilePath);

// open the service file in the temp directory as we usually do not need it
if (!PathCombineA(logFilePath, getSystemTempDirectory(), LOG_NAME))
strcpy(logFilePath, LOG_NAME);
service.logFile = fopen(logFilePath, "a+");
setbuf(service.logFile, NULL);
Expand Down

0 comments on commit 6a72633

Please sign in to comment.