Diff for /loncom/lond between versions 1.312 and 1.313

version 1.312, 2006/01/31 15:56:46 version 1.313, 2006/01/31 16:12:12
Line 53  use LONCAPA::ConfigFileEdit; Line 53  use LONCAPA::ConfigFileEdit;
 use LONCAPA::lonlocal;  use LONCAPA::lonlocal;
 use LONCAPA::lonssl;  use LONCAPA::lonssl;
 use Fcntl qw(:flock);  use Fcntl qw(:flock);
   use Symbol;
   
 my $DEBUG = 0;       # Non zero to enable debug log entries.  my $DEBUG = 0;       # Non zero to enable debug log entries.
   
 my $status='';  my $status='';
 my $lastlog='';  my $lastlog='';
   my $lond_max_wait_time = 13;
   
 my $VERSION='$Revision$'; #' stupid emacs  my $VERSION='$Revision$'; #' stupid emacs
 my $remoteVERSION;  my $remoteVERSION;
Line 972  sub tie_domain_hash { Line 974  sub tie_domain_hash {
     my $user_top_dir   = $perlvar{'lonUsersDir'};      my $user_top_dir   = $perlvar{'lonUsersDir'};
     my $domain_dir     = $user_top_dir."/$domain";      my $domain_dir     = $user_top_dir."/$domain";
     my $resource_file  = $domain_dir."/$namespace";      my $resource_file  = $domain_dir."/$namespace";
     return &_do_hash_tie($resource_file,$namespace,$how,$loghead,$logtail);      return &_locking_hash_tie($resource_file,$namespace,$how,$loghead,$logtail);
 }  }
   
 sub untie_domain_hash {  sub untie_domain_hash {
     return &_do_hash_untie(@_);      return &_locking_hash_untie(@_);
 }  }
 #  #
 #   Ties a user's resource file to a hash.    #   Ties a user's resource file to a hash.  
Line 1005  sub tie_user_hash { Line 1007  sub tie_user_hash {
     my $proname     = propath($domain, $user);      my $proname     = propath($domain, $user);
   
     my $file_prefix="$proname/$namespace";      my $file_prefix="$proname/$namespace";
     return &_do_hash_tie($file_prefix,$namespace,$how,$loghead,$what);      return &_locking_hash_tie($file_prefix,$namespace,$how,$loghead,$what);
 }  }
   
 sub untie_user_hash {  sub untie_user_hash {
     return &_do_hash_untie(@_);      return &_locking_hash_untie(@_);
 }  }
   
 # internal routines that handle the actual tieing and untieing process  # internal routines that handle the actual tieing and untieing process
Line 1041  sub _do_hash_untie { Line 1043  sub _do_hash_untie {
     my $result = untie(%$hashref);      my $result = untie(%$hashref);
     return $result;      return $result;
 }  }
   
   {
       my $sym;
   
       sub _locking_hash_tie {
    my ($file_prefix,$namespace,$how,$loghead,$what) = @_;
   
    my ($lock);
       
    if ($how eq &GDBM_READER()) {
       $lock=LOCK_SH;
       $how=$how|&GDBM_NOLOCK();
       #if the db doesn't exist we can't read from it
       if (! -e "$file_prefix.db") {
    $! = 2;
    return undef;
       }
    } elsif ($how eq &GDBM_WRCREAT()) {
       $lock=LOCK_EX;
       $how=$how|&GDBM_NOLOCK();
       if (! -e "$file_prefix.db") {
    # doesn't exist but we need it to in order to successfully
                   # lock it so bring it into existance
    open(TOUCH,">>$file_prefix.db");
    close(TOUCH);
       }
    } else {
       &logthis("Unknown method $how for $file_prefix");
       die();
    }
       
    &logthis("$$ for $namespace");
    $sym=&Symbol::gensym();
    open($sym,"$file_prefix.db");
    &logthis("$$ for $namespace attempt lock");
    my $failed=0;
    eval {
       local $SIG{__DIE__}='DEFAULT';
       local $SIG{ALRM}=sub { 
    $failed=1;
    die("failed lock");
       };
       alarm($lond_max_wait_time);
       flock($sym,$lock);
       alarm(0);
    };
    if ($failed) {
       &logthis("$$ for $namespace got failed lock");
       $! = 100; # throwing error # 100
       return undef;
    }
    &logthis("$$ for $file_prefix.db got lock");
    return &_do_hash_tie($file_prefix,$namespace,$how,$loghead,$what);
       }
   
       sub _locking_hash_untie {
    my ($hashref) = @_;
    my $result = untie(%$hashref);
    flock($sym,LOCK_UN);
    close($sym);
    undef($sym);
    return $result;
       }
   }
   
 #   read_profile  #   read_profile
 #  #
 #   Returns a set of specific entries from a user's profile file.  #   Returns a set of specific entries from a user's profile file.

Removed from v.1.312  
changed lines
  Added in v.1.313


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>