version 1.80, 2007/04/03 17:51:45
|
version 1.81, 2007/04/12 00:00:55
|
Line 105 use lib '/home/httpd/lib/perl/';
|
Line 105 use lib '/home/httpd/lib/perl/';
|
use LONCAPA; |
use LONCAPA; |
use LONCAPA::Configuration; |
use LONCAPA::Configuration; |
use LONCAPA::lonmetadata(); |
use LONCAPA::lonmetadata(); |
|
use Apache::lonnet; |
|
|
use IO::Socket; |
use IO::Socket; |
use Symbol; |
use Symbol; |
use POSIX; |
use POSIX; |
use IO::Select; |
use IO::Select; |
use IO::File; |
|
use Socket; |
|
use Fcntl; |
|
use Tie::RefHash; |
|
use DBI; |
use DBI; |
use File::Find; |
use File::Find; |
use localenroll; |
use localenroll; |
use GDBM_File; |
use GDBM_File; |
use Storable qw(thaw); |
|
|
|
######################################################## |
######################################################## |
######################################################## |
######################################################## |
Line 206 my $run =0; # running count
|
Line 202 my $run =0; # running count
|
# |
# |
# Read loncapa_apache.conf and loncapa.conf |
# Read loncapa_apache.conf and loncapa.conf |
# |
# |
my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf'); |
my %perlvar=%{&LONCAPA::Configuration::read_conf('loncapa.conf')}; |
my %perlvar=%{$perlvarref}; |
|
# |
# |
# Write the /home/www/.my.cnf file |
# Write the /home/www/.my.cnf file |
my $conf_file = '/home/www/.my.cnf'; |
my $conf_file = '/home/www/.my.cnf'; |
Line 253 unless ($dbh = DBI->connect("DBI:mysql:l
|
Line 248 unless ($dbh = DBI->connect("DBI:mysql:l
|
# |
# |
my $pidfile="$perlvar{'lonDaemons'}/logs/lonsql.pid"; |
my $pidfile="$perlvar{'lonDaemons'}/logs/lonsql.pid"; |
if (-e $pidfile) { |
if (-e $pidfile) { |
my $lfh=IO::File->new("$pidfile"); |
open(my $lfh,"$pidfile"); |
my $pide=<$lfh>; |
my $pide=<$lfh>; |
chomp($pide); |
chomp($pide); |
if (kill 0 => $pide) { die "already running"; } |
if (kill 0 => $pide) { die "already running"; } |
} |
} |
|
|
# |
|
# Read hosts file |
|
# |
|
my $thisserver; |
|
my %hostname; |
|
my $PREFORK=4; # number of children to maintain, at least four spare |
my $PREFORK=4; # number of children to maintain, at least four spare |
open (CONFIG,"$perlvar{'lonTabDir'}/hosts.tab") || die "Can't read host file"; |
|
while (my $configline=<CONFIG>) { |
|
my ($id,$domain,$role,$name)=split(/:/,$configline); |
|
$name=~s/\s//g; |
|
$thisserver=$name if ($id eq $perlvar{'lonHostID'}); |
|
$hostname{$id}=$name; |
|
#$PREFORK++; |
|
} |
|
close(CONFIG); |
|
# |
# |
#$PREFORK=int($PREFORK/4); |
#$PREFORK=int($PREFORK/4); |
|
|
Line 399 sub make_new_child {
|
Line 380 sub make_new_child {
|
my $query=unescape($query); |
my $query=unescape($query); |
# |
# |
#send query id which is pid_unixdatetime_runningcounter |
#send query id which is pid_unixdatetime_runningcounter |
my $queryid = $thisserver; |
my $queryid = &Apache::lonnet::hostname($perlvar{'lonHostID'}); |
$queryid .="_".($$)."_"; |
$queryid .="_".($$)."_"; |
$queryid .= time."_"; |
$queryid .= time."_"; |
$queryid .= $run; |
$queryid .= $run; |
print $client "$queryid\n"; |
print $client "$queryid\n"; |
# |
# |
# &logthis("QUERY: $query - $arg1 - $arg2 - $arg3"); |
# &logthis("QUERY: $query - $arg1 - $arg2 - $arg3 - $queryid"); |
sleep 1; |
sleep 1; |
# |
# |
my $result=''; |
my $result=''; |
Line 485 sub make_new_child {
|
Line 466 sub make_new_child {
|
# result does not need to be escaped because it has already been |
# result does not need to be escaped because it has already been |
# escaped. |
# escaped. |
#$result=&escape($result); |
#$result=&escape($result); |
&reply("queryreply:$queryid:$result",$conserver); |
&Apache::lonnet::reply("queryreply:$queryid:$result",$conserver); |
} |
} |
# tidy up gracefully and finish |
# tidy up gracefully and finish |
# |
# |
Line 602 sub do_sql_query {
|
Line 583 sub do_sql_query {
|
my $customresult=''; |
my $customresult=''; |
my @results; |
my @results; |
foreach my $metafile (@metalist) { |
foreach my $metafile (@metalist) { |
my $fh=IO::File->new($metafile); |
open(my $fh,$metafile); |
my @lines=<$fh>; |
my @lines=<$fh>; |
my $stuff=join('',@lines); |
my $stuff=join('',@lines); |
if ($stuff=~/$custom/s) { |
if ($stuff=~/$custom/s) { |
Line 737 sub get_access_hash {
|
Line 718 sub get_access_hash {
|
while (my ($key,$value) = each(%$hashref)) { |
while (my ($key,$value) = each(%$hashref)) { |
$key = &unescape($key); |
$key = &unescape($key); |
next if ($key =~ /^error: 2 /); |
next if ($key =~ /^error: 2 /); |
$curr_perms{$key}=&thaw_unescape($value); |
$curr_perms{$key}=&Apache::lonnet::thaw_unescape($value); |
} |
} |
if (!&untie_user_hash($hashref)) { |
if (!&untie_user_hash($hashref)) { |
&logthis("error: ".($!+0)." untie (GDBM) Failed"); |
&logthis("error: ".($!+0)." untie (GDBM) Failed"); |
Line 755 sub get_access_hash {
|
Line 736 sub get_access_hash {
|
return %access; |
return %access; |
} |
} |
|
|
sub thaw_unescape { |
|
my ($value)=@_; |
|
if ($value =~ /^__FROZEN__/) { |
|
substr($value,0,10,undef); |
|
$value=&unescape($value); |
|
return &thaw($value); |
|
} |
|
return &unescape($value); |
|
} |
|
|
|
########################################### |
########################################### |
sub check_table { |
sub check_table { |
my ($table_id) = @_; |
my ($table_id) = @_; |
Line 821 Writes $message to the logfile.
|
Line 792 Writes $message to the logfile.
|
sub logthis { |
sub logthis { |
my $message=shift; |
my $message=shift; |
my $execdir=$perlvar{'lonDaemons'}; |
my $execdir=$perlvar{'lonDaemons'}; |
my $fh=IO::File->new(">>$execdir/logs/lonsql.log"); |
open(my $fh,">>$execdir/logs/lonsql.log"); |
my $now=time; |
my $now=time; |
my $local=localtime($now); |
my $local=localtime($now); |
print $fh "$local ($$): $message\n"; |
print $fh "$local ($$): $message\n"; |
} |
} |
|
|
# -------------------------------------------------- Non-critical communication |
|
|
|
######################################################## |
|
######################################################## |
|
|
|
=pod |
|
|
|
=item &subreply |
|
|
|
Sends a command to a server. Called only by &reply. |
|
|
|
Inputs: $cmd,$server |
|
|
|
Returns: The results of the message or 'con_lost' on error. |
|
|
|
=cut |
|
|
|
######################################################## |
|
######################################################## |
|
sub subreply { |
|
my ($cmd,$server)=@_; |
|
my $peerfile="$perlvar{'lonSockDir'}/".$hostname{$server}; |
|
my $sclient=IO::Socket::UNIX->new(Peer =>"$peerfile", |
|
Type => SOCK_STREAM, |
|
Timeout => 10) |
|
or return "con_lost"; |
|
print $sclient "sethost:$server:$cmd\n"; |
|
my $answer=<$sclient>; |
|
chomp($answer); |
|
$answer="con_lost" if (!$answer); |
|
return $answer; |
|
} |
|
|
|
######################################################## |
|
######################################################## |
|
|
|
=pod |
|
|
|
=item &reply |
|
|
|
Sends a command to a server. |
|
|
|
Inputs: $cmd,$server |
|
|
|
Returns: The results of the message or 'con_lost' on error. |
|
|
|
=cut |
|
|
|
######################################################## |
|
######################################################## |
|
sub reply { |
|
my ($cmd,$server)=@_; |
|
my $answer; |
|
if ($server ne $perlvar{'lonHostID'}) { |
|
$answer=subreply($cmd,$server); |
|
if ($answer eq 'con_lost') { |
|
$answer=subreply("ping",$server); |
|
$answer=subreply($cmd,$server); |
|
} |
|
} else { |
|
$answer='self_reply'; |
|
$answer=subreply($cmd,$server); |
|
} |
|
return $answer; |
|
} |
|
|
|
######################################################## |
######################################################## |
######################################################## |
######################################################## |
|
|
Line 925 sub ishome {
|
Line 830 sub ishome {
|
|
|
######################################################## |
######################################################## |
######################################################## |
######################################################## |
|
|
=pod |
|
|
|
=item &propath |
|
|
|
Inputs: user name, user domain |
|
|
|
Returns: The full path to the users directory. |
|
|
|
=cut |
|
|
|
######################################################## |
|
######################################################## |
|
sub propath { |
|
my ($udom,$uname)=@_; |
|
$udom=~s/\W//g; |
|
$uname=~s/\W//g; |
|
my $subdir=$uname.'__'; |
|
$subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/; |
|
my $proname="$perlvar{'lonUsersDir'}/$udom/$subdir/$uname"; |
|
return $proname; |
|
} |
|
|
|
######################################################## |
|
######################################################## |
|
|
|
=pod |
=pod |
|
|