Skip to content

rustdoc: Improve diagnostics on lockfile failures #21287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/librustdoc/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub use self::imp::Lock;
mod imp {
use std::ffi::CString;
use libc;
use std::os as stdos;

#[cfg(target_os = "linux")]
mod os {
Expand Down Expand Up @@ -116,7 +117,8 @@ mod imp {
libc::open(buf.as_ptr(), libc::O_RDWR | libc::O_CREAT,
libc::S_IRWXU)
};
assert!(fd > 0);
assert!(fd > 0, "failed to open lockfile: [{}] {}",
stdos::errno(), stdos::last_os_error());
let flock = os::flock {
l_start: 0,
l_len: 0,
Expand All @@ -129,8 +131,10 @@ mod imp {
libc::fcntl(fd, os::F_SETLKW, &flock as *const os::flock)
};
if ret == -1 {
let errno = stdos::errno();
unsafe { libc::close(fd); }
panic!("could not lock `{}`", p.display())
panic!("could not lock `{}`: [{}] {}", p.display(),
errno, stdos::error_string(errno))
}
Lock { fd: fd }
}
Expand Down Expand Up @@ -199,17 +203,19 @@ mod imp {
ptr::null_mut())
};
if handle == libc::INVALID_HANDLE_VALUE {
panic!("create file error: {}", os::last_os_error());
panic!("create file error: [{}] {}",
os::errno(), os::last_os_error());
}
let mut overlapped: libc::OVERLAPPED = unsafe { mem::zeroed() };
let ret = unsafe {
LockFileEx(handle, LOCKFILE_EXCLUSIVE_LOCK, 0, 100, 0,
&mut overlapped)
};
if ret == 0 {
let errno = os::errno();
unsafe { libc::CloseHandle(handle); }
panic!("could not lock `{}`: {}", p.display(),
os::last_os_error())
panic!("could not lock `{}`: [{}] {}", p.display(),
errno, os::error_string(errno));
}
Lock { handle: handle }
}
Expand Down