summaryrefslogtreecommitdiffstats
path: root/src/bootstrap/bin
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /src/bootstrap/bin
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/bootstrap/bin')
-rw-r--r--src/bootstrap/bin/main.rs61
1 files changed, 24 insertions, 37 deletions
diff --git a/src/bootstrap/bin/main.rs b/src/bootstrap/bin/main.rs
index a80379e85..30dfa81c6 100644
--- a/src/bootstrap/bin/main.rs
+++ b/src/bootstrap/bin/main.rs
@@ -5,7 +5,11 @@
//! parent directory, and otherwise documentation can be found throughout the `build`
//! directory in each respective module.
-use std::env;
+#[cfg(all(any(unix, windows), not(target_os = "solaris")))]
+use std::io::Write;
+#[cfg(all(any(unix, windows), not(target_os = "solaris")))]
+use std::process;
+use std::{env, fs};
#[cfg(all(any(unix, windows), not(target_os = "solaris")))]
use bootstrap::t;
@@ -20,22 +24,32 @@ fn main() {
#[cfg(all(any(unix, windows), not(target_os = "solaris")))]
let _build_lock_guard;
#[cfg(all(any(unix, windows), not(target_os = "solaris")))]
+ // Display PID of process holding the lock
+ // PID will be stored in a lock file
{
let path = config.out.join("lock");
- build_lock = fd_lock::RwLock::new(t!(std::fs::File::create(&path)));
+ let pid = match fs::read_to_string(&path) {
+ Ok(contents) => contents,
+ Err(_) => String::new(),
+ };
+
+ build_lock =
+ fd_lock::RwLock::new(t!(fs::OpenOptions::new().write(true).create(true).open(&path)));
_build_lock_guard = match build_lock.try_write() {
- Ok(lock) => lock,
+ Ok(mut lock) => {
+ t!(lock.write(&process::id().to_string().as_ref()));
+ lock
+ }
err => {
drop(err);
- if let Some(pid) = get_lock_owner(&path) {
- println!("warning: build directory locked by process {pid}, waiting for lock");
- } else {
- println!("warning: build directory locked, waiting for lock");
- }
- t!(build_lock.write())
+ println!("warning: build directory locked by process {pid}, waiting for lock");
+ let mut lock = t!(build_lock.write());
+ t!(lock.write(&process::id().to_string().as_ref()));
+ lock
}
};
}
+
#[cfg(any(not(any(unix, windows)), target_os = "solaris"))]
println!("warning: file locking not supported for target, not locking build directory");
@@ -73,7 +87,7 @@ fn main() {
// HACK: Since the commit script uses hard links, we can't actually tell if it was installed by x.py setup or not.
// We could see if it's identical to src/etc/pre-push.sh, but pre-push may have been modified in the meantime.
// Instead, look for this comment, which is almost certainly not in any custom hook.
- if std::fs::read_to_string(pre_commit).map_or(false, |contents| {
+ if fs::read_to_string(pre_commit).map_or(false, |contents| {
contents.contains("https://github.com/rust-lang/rust/issues/77620#issuecomment-705144570")
}) {
println!(
@@ -108,30 +122,3 @@ fn check_version(config: &Config) -> Option<String> {
Some(msg)
}
-
-/// Get the PID of the process which took the write lock by
-/// parsing `/proc/locks`.
-#[cfg(target_os = "linux")]
-fn get_lock_owner(f: &std::path::Path) -> Option<u64> {
- use std::fs::File;
- use std::io::{BufRead, BufReader};
- use std::os::unix::fs::MetadataExt;
-
- let lock_inode = std::fs::metadata(f).ok()?.ino();
- let lockfile = File::open("/proc/locks").ok()?;
- BufReader::new(lockfile).lines().find_map(|line| {
- // pid--vvvvvv vvvvvvv--- inode
- // 21: FLOCK ADVISORY WRITE 359238 08:02:3719774 0 EOF
- let line = line.ok()?;
- let parts = line.split_whitespace().collect::<Vec<_>>();
- let (pid, inode) = (parts[4].parse::<u64>().ok()?, &parts[5]);
- let inode = inode.rsplit_once(':')?.1.parse::<u64>().ok()?;
- if inode == lock_inode { Some(pid) } else { None }
- })
-}
-
-#[cfg(not(any(target_os = "linux", target_os = "solaris")))]
-fn get_lock_owner(_: &std::path::Path) -> Option<u64> {
- // FIXME: Implement on other OS's
- None
-}