From 5476ad8b5f9f87d9d7b6158e85bd114a04f3393e Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Fri, 25 Oct 2019 13:42:07 -0700 Subject: [PATCH] 1. added 'slaveKvmLog' flag to msh, to enable Linux Child KVM logging 2. added support for child process core dumps in Linux (Note: core location must be writable by the process) --- meshcore/KVM/Linux/linux_kvm.c | 19 ++++++++++++++++++- meshcore/agentcore.c | 4 ++++ meshcore/agentcore.h | 1 + microscript/ILibDuktape_ScriptContainer.c | 7 +++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/meshcore/KVM/Linux/linux_kvm.c b/meshcore/KVM/Linux/linux_kvm.c index f0a30ee..6988df4 100644 --- a/meshcore/KVM/Linux/linux_kvm.c +++ b/meshcore/KVM/Linux/linux_kvm.c @@ -29,12 +29,17 @@ limitations under the License. #include #include +#if !defined(_FREEBSD) + #include +#endif + #include "linux_events.h" #include "linux_compression.h" #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 extern uint32_t crc32c(uint32_t crc, const unsigned char* buf, uint32_t len); +extern char* g_ILibCrashDump_path; typedef enum KVM_MouseCursors { @@ -617,7 +622,6 @@ void* kvm_server_mainloop(void* parm) } } } - g_messageQ = ILibQueue_Create(); // Init the kvm @@ -1010,6 +1014,19 @@ void* kvm_relay_restart(int paused, void *processPipeMgr, ILibKVM_WriteHandler w if (SLAVELOG != 0) { logFile = fopen("/tmp/slave", "w"); } if (uid != 0) { ignore_result(setuid(uid)); } + if (g_ILibCrashDump_path != NULL) + { +#if !defined(_FREEBSD) + prctl(PR_SET_DUMPABLE, 1); + if (logFile) { fprintf(logFile, "SLAVE/KVM DUMPABLE: %s\n", prctl(PR_GET_DUMPABLE, 0)?"YES":"NO"); fflush(logFile); } +#endif + } + else + { + if (logFile) { fprintf(logFile, "SLAVE/KVM CoreDumps DISABLED\n"); fflush(logFile); } + } + + //fprintf(logFile, "Starting kvm_server_mainloop\n"); if (authToken != NULL) { setenv("XAUTHORITY", authToken, 1); } if (dispid != NULL) { setenv("DISPLAY", dispid, 1); } diff --git a/meshcore/agentcore.c b/meshcore/agentcore.c index 3d9ee2a..29727b5 100644 --- a/meshcore/agentcore.c +++ b/meshcore/agentcore.c @@ -3389,6 +3389,10 @@ void MeshServer_Connect(MeshAgentHostContainer *agent) agent->logUpdate = ILibSimpleDataStore_Get(agent->masterDb, "logUpdate", NULL, 0); agent->fakeUpdate = ILibSimpleDataStore_Get(agent->masterDb, "fakeUpdate", NULL, 0); agent->controlChannelDebug = ILibSimpleDataStore_Get(agent->masterDb, "controlChannelDebug", NULL, 0); + +#if defined(_LINKVM) && defined(_POSIX) && !defined(__APPLE__) + SLAVELOG = ILibSimpleDataStore_Get(agent->masterDb, "slaveKvmLog", NULL, 0); +#endif if (agent->logUpdate != 0) { ILIBLOGMESSAGEX("PLATFORM_TYPE: %d\n", agent->platformType); } if (agent->logUpdate != 0) { ILIBLOGMESSAGEX("Running as Service: %d\n", agent->JSRunningAsService); } diff --git a/meshcore/agentcore.h b/meshcore/agentcore.h index 01d2d91..2f33b79 100644 --- a/meshcore/agentcore.h +++ b/meshcore/agentcore.h @@ -258,6 +258,7 @@ 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 +slaveKvmLog: [Linux] If set, will enable logging inside the Child KVM Process. WebProxy: Manually specify proxy configuration webSocketMaskOverride: If set, will disable the optimzation to skip WebSocket Masking for TLS protected Web Sockets * diff --git a/microscript/ILibDuktape_ScriptContainer.c b/microscript/ILibDuktape_ScriptContainer.c index 1391851..f077e5a 100644 --- a/microscript/ILibDuktape_ScriptContainer.c +++ b/microscript/ILibDuktape_ScriptContainer.c @@ -35,6 +35,10 @@ limitations under the License. #include #endif +#if defined(_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD) + #include +#endif + #include "duktape.h" #if defined(WIN32) && !defined(_WIN32_WCE) && !defined(_MINCORE) @@ -1021,6 +1025,9 @@ duk_ret_t ILibDuktape_ScriptContainer_Process_coreDumpLocation_setter(duk_contex duk_put_prop_string(ctx, -2, ILibDuktape_ScriptContainer_Process_CoreDumpPath); // [process] duk_pop(ctx); // ... #ifndef WIN32 +#if defined(_POSIX) && !defined(__APPLE__) && !defined(_FREEBSD) + prctl(PR_SET_DUMPABLE, 1); +#endif duk_eval_string_noresult(ctx, "process.rlimit.set(process.RLIMITS.CORE, {soft: -1, hard: -1});"); #endif }