-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(init): prevent binfmt_misc handler loss on distro termination #14443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6042cde
c1f7ef0
dc158f8
0c91217
c885173
5d6c831
6ee9050
2fb2767
c37d546
a5a9aa3
201ee95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -374,33 +374,38 @@ ExecStart=/bin/mount -o bind,ro,X-mount.mkdir -t none /mnt/wslg/.X11-unix /tmp/. | |
|
|
||
| if (interopEnabled && protectBinfmt) | ||
| { | ||
| // N.B. ExecStop is required to prevent distributions from removing the WSL binfmt entry on shutdown. | ||
| auto systemdBinfmtContent = std::format( | ||
| R"(# Note: This file is generated by WSL to prevent binfmt.d from overriding WSL's binfmt interpreter. | ||
| constexpr auto* binfmtConfigDirectory = "/run/binfmt.d"; | ||
| constexpr auto* binfmtConfigPath = "/run/binfmt.d/WSLInterop.conf"; | ||
| const auto binfmtConfigContent = std::format("{}\n", BINFMT_INTEROP_REGISTRATION_STRING_VM(LX_INIT_BINFMT_NAME)); | ||
| const auto serviceOverrideContent = std::format( | ||
| R"(# Note: This file is generated by WSL to prevent distributions from removing the WSL binfmt entry on shutdown. | ||
| # To disable this unit, add the following to /etc/wsl.conf: | ||
| # [boot] | ||
| # protectBinfmt=false | ||
|
|
||
| [Service] | ||
| ExecStop= | ||
| ExecStart=/bin/sh -c '(echo -1 > {}/{}) ; (echo "{}" > {})' )", | ||
| ExecStartPost=/bin/sh -c '(echo -1 > {}/{} 2>/dev/null || true) ; echo "{}" > {}' | ||
| )", | ||
| BINFMT_MISC_MOUNT_TARGET, | ||
| LX_INIT_BINFMT_NAME, | ||
| BINFMT_INTEROP_REGISTRATION_STRING(LX_INIT_BINFMT_NAME), | ||
| BINFMT_INTEROP_REGISTRATION_STRING_VM(LX_INIT_BINFMT_NAME), | ||
| BINFMT_MISC_REGISTER_FILE); | ||
| THROW_LAST_ERROR_IF(UtilMkdirPath(binfmtConfigDirectory, 0755) < 0); | ||
| THROW_LAST_ERROR_IF(WriteToFile(binfmtConfigPath, binfmtConfigContent.c_str()) < 0); | ||
|
|
||
|
yeelam-gordon marked this conversation as resolved.
Comment on lines
375
to
396
|
||
| // Install the override for systemd-binfmt.service. | ||
| { | ||
| auto overrideFolder = std::format("{}/systemd-binfmt.service.d", installPath); | ||
| THROW_LAST_ERROR_IF(UtilMkdirPath(overrideFolder.c_str(), 0755) < 0); | ||
| THROW_LAST_ERROR_IF(WriteToFile(std::format("{}/override.conf", overrideFolder).c_str(), systemdBinfmtContent.c_str()) < 0); | ||
| THROW_LAST_ERROR_IF(WriteToFile(std::format("{}/override.conf", overrideFolder).c_str(), serviceOverrideContent.c_str()) < 0); | ||
| } | ||
|
|
||
| // Install the override for binfmt-support.service. | ||
| { | ||
| auto overrideFolder = std::format("{}/binfmt-support.service.d", installPath); | ||
| THROW_LAST_ERROR_IF(UtilMkdirPath(overrideFolder.c_str(), 0755) < 0); | ||
| THROW_LAST_ERROR_IF(WriteToFile(std::format("{}/override.conf", overrideFolder).c_str(), systemdBinfmtContent.c_str()) < 0); | ||
| THROW_LAST_ERROR_IF(WriteToFile(std::format("{}/override.conf", overrideFolder).c_str(), serviceOverrideContent.c_str()) < 0); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benhillis: This sounds like something that we want. Any concerns with this flag ?