File tree Expand file tree Collapse file tree 1 file changed +32
-2
lines changed Expand file tree Collapse file tree 1 file changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -395,8 +395,38 @@ mod sys {
395395
396396 #[ cfg( target_os = "solaris" ) ]
397397 fn flock ( file : & File , flag : libc:: c_int ) -> Result < ( ) > {
398- // Solaris lacks flock(), so simply succeed with a no-op
399- Ok ( ( ) )
398+ // Solaris lacks flock(), so try to emulate using fcntl()
399+ let mut flock = libc:: flock {
400+ l_type : 0 ,
401+ l_whence : 0 ,
402+ l_start : 0 ,
403+ l_len : 0 ,
404+ l_sysid : 0 ,
405+ l_pid : 0 ,
406+ l_pad : [ 0 , 0 , 0 , 0 ] ,
407+ } ;
408+ flock. l_type = if flag & libc:: LOCK_UN != 0 {
409+ libc:: F_RDLCK
410+ } else if flag & libc:: LOCK_EX != 0 {
411+ libc:: F_WRLCK
412+ } else if flag & libc:: LOCK_SH != 0 {
413+ libc:: F_RDLCK
414+ } else {
415+ panic ! ( "unexpected flock() operation" )
416+ } ;
417+
418+ let mut cmd = libc:: F_SETLKW ;
419+ if ( flag & libc:: LOCK_NB ) != 0 {
420+ cmd = libc:: F_SETLK ;
421+ }
422+
423+ let ret = unsafe { libc:: fcntl ( file. as_raw_fd ( ) , cmd, & flock) } ;
424+
425+ if ret < 0 {
426+ Err ( Error :: last_os_error ( ) )
427+ } else {
428+ Ok ( ( ) )
429+ }
400430 }
401431}
402432
You can’t perform that action at this time.
0 commit comments