diff --git a/meshcore/KVM/Windows/input.c b/meshcore/KVM/Windows/input.c index a73e966..513fb1a 100644 --- a/meshcore/KVM/Windows/input.c +++ b/meshcore/KVM/Windows/input.c @@ -24,7 +24,6 @@ limitations under the License. #include "microstack/ILibCrypto.h" #include "meshcore/meshdefines.h" -extern void ILibAppendStringToDiskEx(char *FileName, char *data, int dataLen); extern ILibQueue gPendingPackets; extern int gRemoteMouseRenderDefault; extern int gRemoteMouseMoved; diff --git a/meshcore/agentcore.c b/meshcore/agentcore.c index f9da8d9..62544e0 100644 --- a/meshcore/agentcore.c +++ b/meshcore/agentcore.c @@ -1874,6 +1874,8 @@ void ILibDuktape_MeshAgent_PUSH(duk_context *ctx, void *chain) ILibDuktape_CreateEventWithGetter_SetEnumerable(ctx, "ServerInfo", ILibDuktape_MeshAgent_ServerInfo,1); + duk_push_number(ctx, (duk_double_t)ILibCriticalLog_MaxSize); + ILibDuktape_CreateReadonlyProperty_SetEnumerable(ctx, "maxLogSize", 1); ILibDuktape_CreateEventWithGetter_SetEnumerable(ctx, "isControlChannelConnected", ILibDuktape_MeshAgent_isControlChannelConnected,1); ILibDuktape_EventEmitter_AddHook(emitter, "Ready", ILibDuktape_MeshAgent_Ready); @@ -4595,6 +4597,16 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char ** } } + if(ILibSimpleDataStore_Get(agentHost->masterDb, "maxLogSize", NULL, 0) != 0) + { + int len = ILibSimpleDataStore_Get(agentHost->masterDb, "maxLogSize", ILibScratchPad, sizeof(ILibScratchPad)); + if (len < sizeof(ILibScratchPad)) + { + uint64_t val = 0; + if (ILib_atoi_uint64(&val, ILibScratchPad, len) == 0) { ILibCriticalLog_MaxSize = val; } + } + } + #ifdef WIN32 if (agentHost->noCertStore == 0) { agentHost->noCertStore = ILibSimpleDataStore_Get(agentHost->masterDb, "nocertstore", NULL, 0); } #endif diff --git a/meshcore/agentcore.h b/meshcore/agentcore.h index ad5d7c6..5d37a51 100644 --- a/meshcore/agentcore.h +++ b/meshcore/agentcore.h @@ -283,7 +283,10 @@ forceUpdate: If set, will cause the agent to perform a self-update on next st ignoreProxyFile: If set, will cause the agent to ignore any proxy settings logUpdate: If set, will cause the agent to log self-update status jsDebugPort: Specify a JS Debugger Port +maxLogSize: Specifies the maximum size of the error log file. nocertstore: If set on Windows, will force the Agent to use OpenSSL instead of WinCrypto for cert generation/storage. +readonly: If set, forces the agent to open the database in readonly mode +readmsh: If set while db is in readonly mode, it will cache the local msh file in the readonly db remoteMouseRender: If set, will always render the remote mouse cursor for KVM showModuleNames: If set, will display the name of modules when they are loaded for the first time skipmaccheck: If set, the agent will not change NodeID on local mac address changes. diff --git a/microstack/ILibParsers.c b/microstack/ILibParsers.c index a071e42..bb41ad3 100644 --- a/microstack/ILibParsers.c +++ b/microstack/ILibParsers.c @@ -9424,7 +9424,7 @@ void ILibWriteStringToDiskEx(char *FileName, char *data, int dataLen) fclose(SourceFile); } } -void ILibAppendStringToDiskEx(char *FileName, char *data, int dataLen) +void ILibAppendStringToDiskEx2(char *FileName, char *data, int dataLen, uint64_t maxSize) { FILE *SourceFile = NULL; @@ -9433,10 +9433,25 @@ void ILibAppendStringToDiskEx(char *FileName, char *data, int dataLen) #else SourceFile = fopen(FileName, "ab"); #endif - + if (SourceFile != NULL) { - if (fwrite(data, sizeof(char), dataLen, SourceFile)) {} + if (maxSize != 0) + { + fseek(SourceFile, 0, SEEK_END); +#ifdef WIN32 + if ((uint64_t)_ftelli64(SourceFile) < maxSize) +#else + if((uint64_t)ftell(SourceFile) < maxSize) +#endif + { + if (fwrite(data, sizeof(char), dataLen, SourceFile)) {} + } + } + else + { + if (fwrite(data, sizeof(char), dataLen, SourceFile)) {} + } fclose(SourceFile); } } @@ -10752,6 +10767,8 @@ void ILib6to4(struct sockaddr* addr) // Log a critical error to file char ILibCriticalLogBuffer[sizeof(ILibScratchPad)]; +uint64_t ILibCriticalLog_MaxSize = ILIBCRITICALLOG_DEFAULT_MAXSIZE; + char* ILibCriticalLog (const char* msg, const char* file, int line, int user1, int user2) { char timeStamp[32]; @@ -10764,7 +10781,7 @@ char* ILibCriticalLog (const char* msg, const char* file, int line, int user1, i { len = sprintf_s(ILibCriticalLogBuffer, sizeof(ILibCriticalLogBuffer), "\r\n[%s] [%s] %s", timeStamp, g_ILibCrashID_HASH != NULL ? g_ILibCrashID_HASH : "", msg); } - if (len > 0 && len < (int)sizeof(ILibCriticalLogBuffer) && ILibCriticalLogFilename != NULL) ILibAppendStringToDiskEx(ILibCriticalLogFilename, ILibCriticalLogBuffer, len); + if (len > 0 && len < (int)sizeof(ILibCriticalLogBuffer) && ILibCriticalLogFilename != NULL) ILibAppendStringToDiskEx2(ILibCriticalLogFilename, ILibCriticalLogBuffer, len, ILibCriticalLog_MaxSize); if (file != NULL) { ILibRemoteLogging_printf(ILibChainGetLogger(gILibChain), ILibRemoteLogging_Modules_Microstack_Generic, ILibRemoteLogging_Flags_VerbosityLevel_1, "%s:%d (%d,%d) %s", file, line, user1, user2, msg); diff --git a/microstack/ILibParsers.h b/microstack/ILibParsers.h index 0c5967f..24118f6 100644 --- a/microstack/ILibParsers.h +++ b/microstack/ILibParsers.h @@ -930,11 +930,12 @@ int ILibIsRunningOnChainThread(void* chain); char *ILibReadFileFromDisk(char *FileName); int ILibReadFileFromDiskEx(char **Target, char *FileName); void ILibWriteStringToDisk(char *FileName, char *data); - void ILibAppendStringToDiskEx(char *FileName, char *data, int dataLen); + void ILibAppendStringToDiskEx2(char *FileName, char *data, int dataLen, uint64_t maxSize); void ILibWriteStringToDiskEx(char *FileName, char *data, int dataLen); void ILibDeleteFileFromDisk(char *FileName); void ILibGetDiskFreeSpace(void *i64FreeBytesToCaller, void *i64TotalBytes); int ILibFile_CopyTo(char *source, char *destination); + #define ILibAppendStringToDiskEx(FileName, data, dataLen) ILibAppendStringToDiskEx2(FileName, data, dataLen, 0) /*! \defgroup StackGroup Stack \ingroup DataStructures @@ -1594,6 +1595,8 @@ int ILibIsRunningOnChainThread(void* chain); char* ILib_POSIX_InstallCrashHandler(char *exename); #endif +#define ILIBCRITICALLOG_DEFAULT_MAXSIZE 8388608 + extern uint64_t ILibCriticalLog_MaxSize; #define ILIBCRITICALEXITMSG(code, msg) {printf("%s", ILibCriticalLog(msg, __FILE__, __LINE__, 0, 0)); exit(code);} #define ILIBLOGMESSSAGE(msg) ILibCriticalLog(msg, __FILE__, __LINE__, 0, 0) void ILIBLOGMESSAGEX(char *format, ...);