Diff for /rat/lonuserstate.pm between versions 1.128.2.3 and 1.132

version 1.128.2.3, 2009/11/16 20:26:04 version 1.132, 2009/11/15 14:08:53
Line 645  sub readmap { Line 645  sub readmap {
     my $uri;      my $uri;
     $short=~s/\//\_/g;      $short=~s/\//\_/g;
     unless ($uri=$cenv{'url'}) {       unless ($uri=$cenv{'url'}) { 
  &Apache::lonnet::logthis('<font color="blue">WARNING: '.   &Apache::lonnet::logthis("<font color=blue>WARNING: ".
  "Could not load course $short.</font>");    "Could not load course $short.</font>"); 
  return ('',&mt('No course data available.'));;   return ('',&mt('No course data available.'));;
     }      }
     @cond=('true:normal');      @cond=('true:normal');
   
     unless (open(LOCKFILE,">$fn.db.lock")) {      open(LOCKFILE,">$fn.db.lock");
         $errtext.='<br />'.&mt('Map not loaded - Lock file could not be opened when reading map:').' <tt>'.$fn.'</tt>.';  
         $retfurl = '';  
         return ($retfurl,$errtext);  
     }  
     my $lock=0;      my $lock=0;
     my $gotstate=0;      my $gotstate=0;
     if (flock(LOCKFILE,LOCK_EX|LOCK_NB)) {      if (flock(LOCKFILE,LOCK_EX|LOCK_NB)) {
Line 688  sub readmap { Line 684  sub readmap {
                     'Could not untie coursemap hash '.$fn.' for '.$uri.'.</font>');                      'Could not untie coursemap hash '.$fn.' for '.$uri.'.</font>');
             }              }
         }          }
         flock(LOCKFILE,LOCK_UN);   flock(LOCKFILE,LOCK_UN);
    close(LOCKFILE);
     }      }
     unless ($lock && $tiedhash && $tiedparmhash) {      unless ($lock && $tiedhash && $tiedparmhash) { 
  # if we are here it is likely because we are already trying to    # if we are here it is likely because we are already trying to 
  # initialize the course in another child, busy wait trying to    # initialize the course in another child, busy wait trying to 
  # tie the hashes for the next 90 seconds, if we succeed forward    # tie the hashes for the next 90 seconds, if we succeed forward 
Line 703  sub readmap { Line 700  sub readmap {
  }   }
         if ($tiedhash) {          if ($tiedhash) {
             unless($untiedhash) {              unless($untiedhash) {
                 untie(%hash);          untie(%hash);
             }              }
         }          }
         if ($tiedparmhash) {          if ($tiedparmhash) {
Line 711  sub readmap { Line 708  sub readmap {
                 untie(%parmhash);                  untie(%parmhash);
             }              }
         }          }
         &Apache::lonnet::logthis('<font color="blue">WARNING: '.   &Apache::lonnet::logthis("<font color=blue>WARNING: ".
                                  "Could not tie coursemap $fn for $uri.</font>");   "Could not tie coursemap $fn for $uri.</font>");
         $tiedhash = '';          $tiedhash = '';
         $tiedparmhash = '';          $tiedparmhash = '';
  my $i=0;   my $i=0;
Line 728  sub readmap { Line 725  sub readmap {
                         if (-e "$fn.state") {                          if (-e "$fn.state") {
             $retfurl='/adm/navmaps';              $retfurl='/adm/navmaps';
             &Apache::lonnet::appenv({"request.course.id"  => $short,              &Apache::lonnet::appenv({"request.course.id"  => $short,
              "request.course.fn"  => $fn,                 "request.course.fn"  => $fn,
              "request.course.uri" => $uri});               "request.course.uri" => $uri});
                             $untiedhash = untie(%hash);              $untiedhash = untie(%hash);
                             $untiedparmhash = untie(%parmhash);              $untiedparmhash = untie(%parmhash);
                             $gotstate = 1;                              $gotstate = 1;
             last;              last;
                         }          }
                         $untiedparmhash = untie(%parmhash);                          $untiedparmhash = untie(%parmhash);
                     }              }
                     $untiedhash = untie(%hash);              $untiedhash = untie(%hash);
  }                  }
     }              }
  }   }
         if ($lock) {          if ($lock) {
             flock(LOCKFILE,LOCK_UN);              flock(LOCKFILE,LOCK_UN);
             $lock = 0;  
             if ($tiedparmhash) {              if ($tiedparmhash) {
                 unless ($untiedparmhash) {                  unless ($untiedparmhash) {
                     &Apache::lonnet::logthis('<font color="blue">WARNING: '.                      &Apache::lonnet::logthis('<font color="blue">WARNING: '.
Line 759  sub readmap { Line 755  sub readmap {
         }          }
     }      }
     unless ($gotstate) {      unless ($gotstate) {
         $lock = 0;  
         &Apache::lonnet::logthis('<font color="blue">WARNING: '.          &Apache::lonnet::logthis('<font color="blue">WARNING: '.
                      'Could not read statemap '.$fn.' for '.$uri.'.</font>');                       'Could not read statemap '.$fn.' for '.$uri.'.</font>');
         &unlink_tmpfiles($fn);          &unlink_tmpfiles($fn);
         if (flock(LOCKFILE,LOCK_EX|LOCK_NB)) {          if (open(LOCKFILE,">$fn.db.lock")) {
             $lock=1;              my $lock=0;
         }              if (flock(LOCKFILE,LOCK_EX|LOCK_NB)) {
         undef %randompick;                  $lock=1;
         undef %hiddenurl;                  &unlink_tmpfiles($fn);
         undef %encurl;              }
         $retfrid='';              undef %randompick;
         if ($lock) {              undef %hiddenurl;
             if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_WRCREAT(),0640)) {              undef %encurl;
                 if (tie(%parmhash,'GDBM_File',$fn.'_parms.db',&GDBM_WRCREAT(),0640)) {              $retfrid='';
                     $gotstate = &build_tmp_hashes($uri,$fn,$short,\%cenv);              if ($lock) {
                     unless ($gotstate) {                  if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_WRCREAT(),0640)) {
                       if (tie(%parmhash,'GDBM_File',$fn.'_parms.db',&GDBM_WRCREAT(),0640)) {
                           $gotstate = &build_tmp_hashes($uri,$fn,$short,\%cenv);
                           unless ($gotstate) {
                               &Apache::lonnet::logthis('<font color="blue">WARNING: '.
                                   'Failed to write statemap at second attempt '.$fn.' for '.$uri.'.</font>');
                           }
                           unless (untie(%parmhash)) {
                               &Apache::lonnet::logthis('<font color="blue">WARNING: '.
                                   'Could not untie coursemap parmhash '.$fn.'.db for '.$uri.'.</font>');
                           }
                       } else {
                         &Apache::lonnet::logthis('<font color="blue">WARNING: '.                          &Apache::lonnet::logthis('<font color="blue">WARNING: '.
                             'Failed to write statemap at second attempt '.$fn.' for '.$uri.'.</font>');                              'Could not tie coursemap '.$fn.'__parms.db for '.$uri.'.</font>');
                     }                      }
                     unless (untie(%parmhash)) {                      unless (untie(%hash)) {
                         &Apache::lonnet::logthis('<font color="blue">WARNING: '.                          &Apache::lonnet::logthis('<font color="blue">WARNING: '.
                             'Could not untie coursemap parmhash '.$fn.'.db for '.$uri.'.</font>');                              'Could not untie coursemap hash '.$fn.'.db for '.$uri.'.</font>');
                     }                      }
                 } else {                 } else {
                     &Apache::lonnet::logthis('<font color="blue">WARNING: '.                     &Apache::lonnet::logthis('<font color="blue">WARNING: '.
                         'Could not tie coursemap '.$fn.'__parms.db for '.$uri.'.</font>');                         'Could not tie coursemap '.$fn.'.db for '.$uri.'.</font>');
                 }                 }
                 unless (untie(%hash)) {                 flock(LOCKFILE,LOCK_UN);
                     &Apache::lonnet::logthis('<font color="blue">WARNING: '.                 close(LOCKFILE);
                         'Could not untie coursemap hash '.$fn.'.db for '.$uri.'.</font>');  
                 }  
             } else {              } else {
                &Apache::lonnet::logthis('<font color="blue">WARNING: '.                  &Apache::lonnet::logthis('<font color="blue">WARNING: '.
                    'Could not tie coursemap '.$fn.'.db for '.$uri.'.</font>');                  'Could not obtain lock to tie coursemap hash '.$fn.'.db for '.$uri.'.</font>');
             }              }
             flock(LOCKFILE,LOCK_UN);      close(LOCKFILE);
             $lock = 0;  
         } else {  
             &Apache::lonnet::logthis('<font color="blue">WARNING: '.  
             'Could not obtain lock to tie coursemap hash '.$fn.'.db for '.$uri.'.</font>');  
         }          }
     }      }
     close(LOCKFILE);  
     unless (($errtext eq '') || ($env{'request.course.uri'} =~ m{^/uploaded/})) {      unless (($errtext eq '') || ($env{'request.course.uri'} =~ m{^/uploaded/})) {
         &Apache::lonmsg::author_res_msg($env{'request.course.uri'},          &Apache::lonmsg::author_res_msg($env{'request.course.uri'},
                                         $errtext);                                          $errtext);
Line 1002  of course for user. Line 1001  of course for user.
 This is part of the LearningOnline Network with CAPA project  This is part of the LearningOnline Network with CAPA project
 described at http://www.lon-capa.org.  described at http://www.lon-capa.org.
   
 =head1 HANDLER SUBROUTINE  =head1 SUBROUTINES
   
 There is no handler subroutine.  
   
 =head1 OTHER SUBROUTINES  
   
 =over 4  =over
   
 =item *  =item loadmap()
   
 loadmap() : Loads map from disk  Loads map from disk
   
 =item *  =item simplify()
   
 simplify() : Simplify expression  Simplify expression
   
 =item *  =item traceroute()
   
 traceroute() : Build condition hash  Build condition hash
   
 =item *  =item accinit()
   
 accinit() : Cascading conditions, quick access, parameters  Cascading conditions, quick access, parameters
   
 =item *  =item readmap()
   
 readmap() : Read map and all submaps  Read map and all submaps
   
 =item *  =item evalstate()
   
 evalstate() : Evaluate state string  Evaluate state string
   
 =back  =back
   

Removed from v.1.128.2.3  
changed lines
  Added in v.1.132


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