libstore: open build directory as a dirfd as well

We now keep around a proper AutoCloseFD around the temporary directory
which we plan to use for openat operations and avoiding the build
directory being swapped out while we are doing something else.

Change-Id: I18d387b0f123ebf2d20c6405cd47ebadc5505f2a
Signed-off-by: Raito Bezarius <raito@lix.systems>
This commit is contained in:
Raito Bezarius
2025-06-23 16:53:12 +02:00
parent e9f0354f7a
commit 1a4cb13411
2 changed files with 10 additions and 0 deletions
@@ -489,6 +489,11 @@ try {
false,
0700
);
/* The TOCTOU between the previous mkdir call and this open call is unavoidable due to
* POSIX semantics.*/
tmpDirFd = AutoCloseFD{open(tmpDir.c_str(), O_RDONLY | O_NOFOLLOW | O_DIRECTORY)};
if (!tmpDirFd)
throw SysError("failed to open the build temporary directory descriptor '%1%'", tmpDir);
chownToBuilder(tmpDir);
@@ -31,6 +31,11 @@ struct LocalDerivationGoal : public DerivationGoal
*/
Path tmpDir;
/**
* The temporary directory file descriptor
*/
AutoCloseFD tmpDirFd;
/**
* The path of the temporary directory in the sandbox.
*/