diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2022-10-07 16:51:06 -0400 |
|---|---|---|
| committer | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2022-10-07 16:54:20 -0400 |
| commit | bb0beaecdee1a2315a1269b1746d238c8ab0e699 (patch) | |
| tree | 0802f5eded41b618dbc13fa31ae9cb843d1085b0 | |
| parent | 00ef6c18d5c6b22874221e9be74f3ba0641c0034 (diff) | |
nix: Guard against removing temporary roots of living processes.
Fixes <https://issues.guix.gnu.org/25018>.
* nix/libstore/gc.cc (readTempRoots): Add a check to guard against removing
the temporary roots of a living process.
Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
| -rw-r--r-- | nix/libstore/gc.cc | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/nix/libstore/gc.cc b/nix/libstore/gc.cc index 16519116e4f..f101de92d6b 100644 --- a/nix/libstore/gc.cc +++ b/nix/libstore/gc.cc | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | #include "misc.hh" | 2 | #include "misc.hh" |
| 3 | #include "local-store.hh" | 3 | #include "local-store.hh" |
| 4 | 4 | ||
| 5 | #include <string> | ||
| 5 | #include <functional> | 6 | #include <functional> |
| 6 | #include <queue> | 7 | #include <queue> |
| 7 | #include <algorithm> | 8 | #include <algorithm> |
| @@ -226,10 +227,10 @@ static void readTempRoots(PathSet & tempRoots, FDs & fds) | |||
| 226 | //FDPtr fd(new AutoCloseFD(openLockFile(path, false))); | 227 | //FDPtr fd(new AutoCloseFD(openLockFile(path, false))); |
| 227 | //if (*fd == -1) continue; | 228 | //if (*fd == -1) continue; |
| 228 | 229 | ||
| 229 | /* Try to acquire a write lock without blocking. This can | 230 | /* Try to acquire a write lock without blocking. This can only |
| 230 | only succeed if the owning process has died. In that case | 231 | succeed if the owning process has died, in which case we don't care |
| 231 | we don't care about its temporary roots. */ | 232 | about its temporary roots, or if we are the owning process. */ |
| 232 | if (lockFile(*fd, ltWrite, false)) { | 233 | if (i.name != std::to_string(getpid()) && lockFile(*fd, ltWrite, false)) { |
| 233 | printMsg(lvlError, format("removing stale temporary roots file `%1%'") % path); | 234 | printMsg(lvlError, format("removing stale temporary roots file `%1%'") % path); |
| 234 | unlink(path.c_str()); | 235 | unlink(path.c_str()); |
| 235 | writeFull(*fd, "d"); | 236 | writeFull(*fd, "d"); |
