提交 9006c3c0 编写于 作者: B bors

Auto merge of #21287 - alexcrichton:issue-19872, r=huonw

cc #19872, this may help give some insight
......@@ -22,6 +22,7 @@
mod imp {
use std::ffi::CString;
use libc;
use std::os as stdos;
#[cfg(target_os = "linux")]
mod os {
......@@ -116,7 +117,8 @@ pub fn new(p: &Path) -> Lock {
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,
......@@ -129,8 +131,10 @@ pub fn new(p: &Path) -> Lock {
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 }
}
......@@ -199,7 +203,8 @@ pub fn new(p: &Path) -> Lock {
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 {
......@@ -207,9 +212,10 @@ pub fn new(p: &Path) -> Lock {
&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 }
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册