diff --git a/src/linux/init/WSLAInit.cpp b/src/linux/init/WSLAInit.cpp index 7f2da7276..a1fb8eaa8 100644 --- a/src/linux/init/WSLAInit.cpp +++ b/src/linux/init/WSLAInit.cpp @@ -63,11 +63,21 @@ struct WSLAState static WSLAState g_state; -void WSLAEnableCrashDumpCollection() +int CreateCaptureCrashSymlink() { if (symlink("/wsl-init", "/" LX_INIT_WSL_CAPTURE_CRASH) < 0) { LOG_ERROR("symlink({}, {}) failed {}", "/wsl-init", "/" LX_INIT_WSL_CAPTURE_CRASH, errno); + return errno; + } + + return 0; +} + +void WSLAEnableCrashDumpCollection() +{ + if (CreateCaptureCrashSymlink() < 0) + { return; } @@ -514,8 +524,8 @@ void HandleMessageImpl(wsl::shared::SocketChannel& Channel, const WSLA_MOUNT& Me { THROW_LAST_ERROR_IF(Chroot(target) < 0); - // Reconfigure crash dump collection after chroot so symlink & core_pattern resolve correctly. - WSLAEnableCrashDumpCollection(); + // Recreate the crash dump symlink inside the new root. + CreateCaptureCrashSymlink(); } response.Result = 0; @@ -816,9 +826,6 @@ int WSLAEntryPoint(int Argc, char* Argv[]) return -1; } - // Enable crash dump collection. - WSLAEnableCrashDumpCollection(); - // // Open kmesg for logging and ensure that the file descriptor is not set to one of the standard file descriptors. // @@ -860,6 +867,11 @@ int WSLAEntryPoint(int Argc, char* Argv[]) return -1; } + // + // Enable dump collection when processes crash. + // + WSLAEnableCrashDumpCollection(); + // // Enable logging when processes receive fatal signals. //