Don't display a warning when the binfmt process doesn't have a controlling terminal (#13176)

Blue committed Jun 23, 2025 at 16:24 UTC c1d6ad1d1556ec0cd55fbe2073f2831487fcc10a
2 files changed +19 -1
src/linux/init/binfmt.cpp
+8 -1
@@ -678,12 +678,19 @@ Return Value:
678
679 //
680 // Ensure that stdin represents the foreground process group.
681 + // N.B. It's possible that standard file descriptors point to tty while the process
682 + // has no controlling terminal (in case its parent called setsid() without opening a new terminal for instance).
683 + // See https://github.com/microsoft/WSL/issues/13173.
684 //
685
686 auto processGroup = tcgetpgrp(0);
687 if (processGroup < 0)
688 {
686 - LOG_STDERR("tcgetpgrp failed");
689 + if (errno != ENOTTY)
690 + {
691 + LOG_STDERR("tcgetpgrp failed");
692 + }
693 +
694 return;
695 }
696
test/windows/UnitTests.cpp
+11
@@ -6119,5 +6119,16 @@ Error code: Wsl/InstallDistro/WSL_E_INVALID_JSON\r\n",
6119 VERIFY_ARE_EQUAL(err, L"");
6120 }
6121
6122 + // Validate that calling the binfmt interpreter with tty fd's but not controlling terminal doesn't display a warning.
6123 + // See https://github.com/microsoft/WSL/issues/13173.
6124 + TEST_METHOD(SetSidNoWarning)
6125 + {
6126 + auto [out, err] =
6127 + LxsstuLaunchWslAndCaptureOutput(L"socat - 'EXEC:setsid --wait cmd.exe /c echo OK',pty,setsid,ctty,stderr");
6128 +
6129 + VERIFY_ARE_EQUAL(out, L"OK\r\r\n");
6130 + VERIFY_ARE_EQUAL(err, L"");
6131 + }
6132 +
6133 }; // namespace UnitTests
6134 } // namespace UnitTests