From c1d6ad1d1556ec0cd55fbe2073f2831487fcc10a Mon Sep 17 00:00:00 2001 From: Blue Date: Mon, 23 Jun 2025 16:24:10 -0700 Subject: [PATCH] Don't display a warning when the binfmt process doesn't have a controlling terminal (#13176) --- src/linux/init/binfmt.cpp | 9 ++++++++- test/windows/UnitTests.cpp | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/linux/init/binfmt.cpp b/src/linux/init/binfmt.cpp index d4c6868..e32ebfc 100644 --- a/src/linux/init/binfmt.cpp +++ b/src/linux/init/binfmt.cpp @@ -678,12 +678,19 @@ Return Value: // // Ensure that stdin represents the foreground process group. + // N.B. It's possible that standard file descriptors point to tty while the process + // has no controlling terminal (in case its parent called setsid() without opening a new terminal for instance). + // See https://github.com/microsoft/WSL/issues/13173. // auto processGroup = tcgetpgrp(0); if (processGroup < 0) { - LOG_STDERR("tcgetpgrp failed"); + if (errno != ENOTTY) + { + LOG_STDERR("tcgetpgrp failed"); + } + return; } diff --git a/test/windows/UnitTests.cpp b/test/windows/UnitTests.cpp index 8a12a25..228baa5 100644 --- a/test/windows/UnitTests.cpp +++ b/test/windows/UnitTests.cpp @@ -6119,5 +6119,16 @@ Error code: Wsl/InstallDistro/WSL_E_INVALID_JSON\r\n", VERIFY_ARE_EQUAL(err, L""); } + // Validate that calling the binfmt interpreter with tty fd's but not controlling terminal doesn't display a warning. + // See https://github.com/microsoft/WSL/issues/13173. + TEST_METHOD(SetSidNoWarning) + { + auto [out, err] = + LxsstuLaunchWslAndCaptureOutput(L"socat - 'EXEC:setsid --wait cmd.exe /c echo OK',pty,setsid,ctty,stderr"); + + VERIFY_ARE_EQUAL(out, L"OK\r\r\n"); + VERIFY_ARE_EQUAL(err, L""); + } + }; // namespace UnitTests } // namespace UnitTests