1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-16 07:22:43 +01:00

Fix thread-safety issue with ptsname() usage

Replace non-thread-safe ptsname() calls with a new getPtsName() helper
function that:
- Uses thread-safe ptsname_r() on Linux/BSD platforms
- Uses mutex-protected ptsname() on macOS (which lacks ptsname_r())
This commit is contained in:
Jörg Thalheim 2025-09-29 12:01:45 +02:00
parent 7cbc0f97e7
commit a9ffa42dda
3 changed files with 39 additions and 3 deletions

View file

@ -18,6 +18,7 @@
#include "nix/store/user-lock.hh"
#include "nix/store/globals.hh"
#include "nix/store/build/derivation-env-desugar.hh"
#include "nix/util/terminal.hh"
#include <queue>
@ -808,8 +809,7 @@ std::optional<Descriptor> DerivationBuilderImpl::startBuild()
if (!builderOut)
throw SysError("opening pseudoterminal master");
// FIXME: not thread-safe, use ptsname_r
std::string slaveName = ptsname(builderOut.get());
std::string slaveName = getPtsName(builderOut.get());
if (buildUser) {
if (chmod(slaveName.c_str(), 0600))
@ -923,7 +923,7 @@ void DerivationBuilderImpl::prepareSandbox()
void DerivationBuilderImpl::openSlave()
{
std::string slaveName = ptsname(builderOut.get());
std::string slaveName = getPtsName(builderOut.get());
AutoCloseFD builderOut = open(slaveName.c_str(), O_RDWR | O_NOCTTY);
if (!builderOut)