--- ow-shared.pl.orig	Fri Apr  4 00:25:17 2003
+++ ow-shared.pl	Fri Apr  4 00:24:05 2003
@@ -2784,12 +2784,42 @@
 ########################## END HOSTNAME ##########################
 
 ########################## FILELOCK ############################
+use vars qw(%lockcount);
+local %lockcount=();
 sub filelock {
+   my $ret;
+
+   my $str;
+   if ($_[1] & LOCK_UN) {
+      $str="unlock"; $lockcount{$_[0]}--;
+   } elsif ($_[1] & LOCK_EX) {
+      $str="W lock"; $lockcount{$_[0]}++;
+   } elsif ($_[1] & LOCK_SH) {
+      $str="R lock"; $lockcount{$_[0]}++;
+   } else {
+      $str="UNKNOW";
+   }
+   log_time ("[$$] $str $lockcount{$_[0]}:", @_);
+
    if ( $config{'use_dotlockfile'} ) {
-      return openwebmail::filelock::dotfile_lock(@_);
+      $ret=openwebmail::filelock::dotfile_lock(@_);
    } else {
-      return openwebmail::filelock::flock_lock(@_);
+      $ret=openwebmail::filelock::flock_lock(@_);
+   }
+
+   if ($ret==0) {
+      my ($origruid, $origeuid)=($<, $>);
+      my $prog="/usr/local/sbin/lsof $_[0]";
+      ($prog =~ /^(.+)$/) && ($prog = $1);
+
+      $>=0; $<=$>;			# set ruid/euid to root before exec
+      my $lsof=`$prog`;
+      $<=$origruid; $>=$origeuid;	# fall back to original ruid/euid
+
+      log_time("[$$] LOCK ERROR: locks on file =>\n", $lsof);
    }
+
+   return($ret);
 }
 ########################## END FILELOCK ############################
 
