Skip to content

Commit 4ad6176

Browse files
committed
Added file locking to the append writes using fs2.
1 parent 911a4b0 commit 4ad6176

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dynamic_instrumentation/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ camino = "1.0"
1818
# Used for parsing `rust-toolchain.toml`.
1919
# We don't need to edit at all, but `cargo` uses `toml-edit`, so we want to match it.
2020
toml_edit = "0.14"
21+
fs2 = "0.4"
2122

2223
[build-dependencies]
2324
rustc-private-link = { path = "../rustc-private-link" }

dynamic_instrumentation/src/instrument.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use anyhow::Context;
22
use c2rust_analysis_rt::metadata::Metadata;
33
use c2rust_analysis_rt::mir_loc::{self, EventMetadata, Func, MirLoc, MirLocId, TransferKind};
44
use c2rust_analysis_rt::HOOK_FUNCTIONS;
5+
use fs2::FileExt;
56
use fs_err::OpenOptions;
67
use indexmap::IndexSet;
78
use log::debug;
@@ -76,7 +77,10 @@ impl Instrumenter {
7677
.write(true)
7778
.open(metadata_path)
7879
.context("Could not open metadata file")?;
79-
file.write_all(&bytes)?;
80+
file.file_mut().lock_exclusive()?;
81+
let e = file.write_all(&bytes);
82+
file.file_mut().unlock()?;
83+
e?;
8084
Ok(())
8185
}
8286

0 commit comments

Comments
 (0)