Skip to content

Commit 23bda7c

Browse files
authored
Fix dmesg warning from enable crash dump collection (#14035)
* Do not write write to core_pattern after chroot * Recreate symlink
1 parent 0491cb6 commit 23bda7c

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/linux/init/WSLAInit.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,21 @@ struct WSLAState
6363

6464
static WSLAState g_state;
6565

66-
void WSLAEnableCrashDumpCollection()
66+
int CreateCaptureCrashSymlink()
6767
{
6868
if (symlink("/wsl-init", "/" LX_INIT_WSL_CAPTURE_CRASH) < 0)
6969
{
7070
LOG_ERROR("symlink({}, {}) failed {}", "/wsl-init", "/" LX_INIT_WSL_CAPTURE_CRASH, errno);
71+
return errno;
72+
}
73+
74+
return 0;
75+
}
76+
77+
void WSLAEnableCrashDumpCollection()
78+
{
79+
if (CreateCaptureCrashSymlink() < 0)
80+
{
7181
return;
7282
}
7383

@@ -614,8 +624,8 @@ void HandleMessageImpl(wsl::shared::SocketChannel& Channel, const WSLA_MOUNT& Me
614624
{
615625
THROW_LAST_ERROR_IF(Chroot(target) < 0);
616626

617-
// Reconfigure crash dump collection after chroot so symlink & core_pattern resolve correctly.
618-
WSLAEnableCrashDumpCollection();
627+
// Recreate the crash dump symlink inside the new root.
628+
CreateCaptureCrashSymlink();
619629
}
620630

621631
response.Result = 0;
@@ -863,9 +873,6 @@ int WSLAEntryPoint(int Argc, char* Argv[])
863873
return -1;
864874
}
865875

866-
// Enable crash dump collection.
867-
WSLAEnableCrashDumpCollection();
868-
869876
//
870877
// Open kmesg for logging and ensure that the file descriptor is not set to one of the standard file descriptors.
871878
//
@@ -907,6 +914,11 @@ int WSLAEntryPoint(int Argc, char* Argv[])
907914
return -1;
908915
}
909916

917+
//
918+
// Enable dump collection when processes crash.
919+
//
920+
WSLAEnableCrashDumpCollection();
921+
910922
//
911923
// Enable logging when processes receive fatal signals.
912924
//

0 commit comments

Comments
 (0)