@@ -22,6 +22,7 @@ pub use self::imp::Lock;
22
22
mod imp {
23
23
use std:: ffi:: CString ;
24
24
use libc;
25
+ use std:: os as stdos;
25
26
26
27
#[ cfg( target_os = "linux" ) ]
27
28
mod os {
@@ -116,7 +117,8 @@ mod imp {
116
117
libc:: open ( buf. as_ptr ( ) , libc:: O_RDWR | libc:: O_CREAT ,
117
118
libc:: S_IRWXU )
118
119
} ;
119
- assert ! ( fd > 0 ) ;
120
+ assert ! ( fd > 0 , "failed to open lockfile: [{}] {}" ,
121
+ stdos:: errno( ) , stdos:: last_os_error( ) ) ;
120
122
let flock = os:: flock {
121
123
l_start : 0 ,
122
124
l_len : 0 ,
@@ -129,8 +131,10 @@ mod imp {
129
131
libc:: fcntl ( fd, os:: F_SETLKW , & flock as * const os:: flock )
130
132
} ;
131
133
if ret == -1 {
134
+ let errno = stdos:: errno ( ) ;
132
135
unsafe { libc:: close ( fd) ; }
133
- panic ! ( "could not lock `{}`" , p. display( ) )
136
+ panic ! ( "could not lock `{}`: [{}] {}" , p. display( ) ,
137
+ errno, stdos:: error_string( errno) )
134
138
}
135
139
Lock { fd : fd }
136
140
}
@@ -199,17 +203,19 @@ mod imp {
199
203
ptr:: null_mut ( ) )
200
204
} ;
201
205
if handle == libc:: INVALID_HANDLE_VALUE {
202
- panic ! ( "create file error: {}" , os:: last_os_error( ) ) ;
206
+ panic ! ( "create file error: [{}] {}" ,
207
+ os:: errno( ) , os:: last_os_error( ) ) ;
203
208
}
204
209
let mut overlapped: libc:: OVERLAPPED = unsafe { mem:: zeroed ( ) } ;
205
210
let ret = unsafe {
206
211
LockFileEx ( handle, LOCKFILE_EXCLUSIVE_LOCK , 0 , 100 , 0 ,
207
212
& mut overlapped)
208
213
} ;
209
214
if ret == 0 {
215
+ let errno = os:: errno ( ) ;
210
216
unsafe { libc:: CloseHandle ( handle) ; }
211
- panic ! ( "could not lock `{}`: {}" , p. display( ) ,
212
- os:: last_os_error ( ) )
217
+ panic ! ( "could not lock `{}`: [{}] {}" , p. display( ) ,
218
+ errno , os:: error_string ( errno ) ) ;
213
219
}
214
220
Lock { handle : handle }
215
221
}
0 commit comments