Diff for /loncom/lond between versions 1.105 and 1.109

version 1.105, 2003/01/13 21:52:11 version 1.109, 2003/03/01 04:18:22
Line 31 Line 31
 # 10/7,10/8,10/9,10/11,10/13,10/15,11/4,11/16,  # 10/7,10/8,10/9,10/11,10/13,10/15,11/4,11/16,
 # 12/7,12/15,01/06,01/11,01/12,01/14,2/8,  # 12/7,12/15,01/06,01/11,01/12,01/14,2/8,
 # 03/07,05/31 Gerd Kortemeyer  # 03/07,05/31 Gerd Kortemeyer
 # 06/26 Scott Harrison  
 # 06/29,06/30,07/14,07/15,07/17,07/20,07/25,09/18 Gerd Kortemeyer  # 06/29,06/30,07/14,07/15,07/17,07/20,07/25,09/18 Gerd Kortemeyer
 # 12/05 Scott Harrison  
 # 12/05,12/13,12/29 Gerd Kortemeyer  # 12/05,12/13,12/29 Gerd Kortemeyer
 # YEAR=2001  # YEAR=2001
 # Jan 01 Scott Harrison  
 # 02/12 Gerd Kortemeyer  # 02/12 Gerd Kortemeyer
 # 03/15 Scott Harrison  
 # 03/24 Gerd Kortemeyer  # 03/24 Gerd Kortemeyer
 # 04/02 Scott Harrison  
 # 05/11,05/28,08/30 Gerd Kortemeyer  # 05/11,05/28,08/30 Gerd Kortemeyer
 # 9/30,10/22,11/13,11/15,11/16 Scott Harrison  
 # 11/26,11/27 Gerd Kortemeyer  # 11/26,11/27 Gerd Kortemeyer
 # 12/20 Scott Harrison  
 # 12/22 Gerd Kortemeyer  # 12/22 Gerd Kortemeyer
 # YEAR=2002  # YEAR=2002
 # 01/20/02,02/05 Gerd Kortemeyer  # 01/20/02,02/05 Gerd Kortemeyer
 # 02/05 Guy Albertelli  # 02/05 Guy Albertelli
 # 02/07 Scott Harrison  
 # 02/12 Gerd Kortemeyer  # 02/12 Gerd Kortemeyer
 # 02/19 Matthew Hall  # 02/19 Matthew Hall
 # 02/25 Gerd Kortemeyer  # 02/25 Gerd Kortemeyer
 # 05/11 Scott Harrison  # 01/xx/2003 Ron Fox.. Remove preforking.  This makes the general daemon
   #      logic simpler (and there were problems maintaining the preforked
   #      population).  Since the time averaged connection rate is close to zero
   #      because lonc's purpose is to maintain near continuous connnections,
   #      preforking is not really needed.
 ###  ###
   
 # based on "Perl Cookbook" ISBN 1-56592-243-3  
 # preforker - server who forks first  
 # runs as a daemon  
 # HUPs  
 # uses IDEA encryption  
   
 use lib '/home/httpd/lib/perl/';  use lib '/home/httpd/lib/perl/';
 use LONCAPA::Configuration;  use LONCAPA::Configuration;
Line 491  close(PIDSAVE); Line 482  close(PIDSAVE);
 &logthis("<font color=red>CRITICAL: ---------- Starting ----------</font>");  &logthis("<font color=red>CRITICAL: ---------- Starting ----------</font>");
 &status('Starting');  &status('Starting');
   
 # ------------------------------------------------------- Now we are on our own  
       
 # Fork off our children.  
 for (1 .. $PREFORK) {  
     make_new_child();  
 }  
   
 # ----------------------------------------------------- Install signal handlers  # ----------------------------------------------------- Install signal handlers
   
 &status('Forked children');  
   
 $SIG{CHLD} = \&REAPER;  $SIG{CHLD} = \&REAPER;
 $SIG{INT}  = $SIG{TERM} = \&HUNTSMAN;  $SIG{INT}  = $SIG{TERM} = \&HUNTSMAN;
 $SIG{HUP}  = \&HUPSMAN;  $SIG{HUP}  = \&HUPSMAN;
 $SIG{USR1} = \&checkchildren;  $SIG{USR1} = \&checkchildren;
   
 # And maintain the population.  
   
   # --------------------------------------------------------------
   #   Accept connections.  When a connection comes in, it is validated
   #   and if good, a child process is created to process transactions
   #   along the connection.
   
 while (1) {  while (1) {
     &status('Sleeping');      $client = $server->accept() or next;
     sleep;                          # wait for a signal (i.e., child's death)      make_new_child($client);
     &logthis('Woke up');  
     &status('Woke up');  
     for ($i = $children; $i < $PREFORK; $i++) {  
         make_new_child();           # top up the child pool  
     }  
 }  }
   
 sub make_new_child {  sub make_new_child {
       my $client;
     my $pid;      my $pid;
     my $cipher;      my $cipher;
     my $sigset;      my $sigset;
   
       $client = shift;
     &logthis("Attempting to start child");          &logthis("Attempting to start child");    
     # block signal for fork      # block signal for fork
     $sigset = POSIX::SigSet->new(SIGINT);      $sigset = POSIX::SigSet->new(SIGINT);
Line 555  sub make_new_child { Line 544  sub make_new_child {
         &Authen::Krb5::init_context();          &Authen::Krb5::init_context();
         &Authen::Krb5::init_ets();          &Authen::Krb5::init_ets();
   
         # handle connections until we've reached $MAX_CLIENTS_PER_CHILD  
         for ($i=0; $i < $MAX_CLIENTS_PER_CHILD; $i++) {  
             &status('Idle, waiting for connection');  
             $client = $server->accept()     or last;  
             &status('Accepted connection');              &status('Accepted connection');
 # =============================================================================  # =============================================================================
             # do something with the connection              # do something with the connection
Line 566  sub make_new_child { Line 551  sub make_new_child {
     $client->sockopt(SO_KEEPALIVE, 1);# Enable monitoring of      $client->sockopt(SO_KEEPALIVE, 1);# Enable monitoring of
                                       # connection liveness.                                        # connection liveness.
             # see if we know client and check for spoof IP by challenge              # see if we know client and check for spoof IP by challenge
             my $caller=getpeername($client);   my $caller = getpeername($client);
             my ($port,$iaddr)=unpack_sockaddr_in($caller);              my ($port,$iaddr)=unpack_sockaddr_in($caller);
             my $clientip=inet_ntoa($iaddr);              my $clientip=inet_ntoa($iaddr);
             my $clientrec=($hostid{$clientip} ne undef);              my $clientrec=($hostid{$clientip} ne undef);
Line 870  sub make_new_child { Line 855  sub make_new_child {
                                $fpnow.='/'.$fpparts[$i];                                  $fpnow.='/'.$fpparts[$i]; 
                                unless (-e $fpnow) {                                 unless (-e $fpnow) {
    unless (mkdir($fpnow,0777)) {     unless (mkdir($fpnow,0777)) {
                                       $fperror="error:$!";                                        $fperror="error: ".($!+0)
     ." mkdir failed\n";
                                    }                                     }
                                }                                 }
                            }                             }
Line 1041  sub make_new_child { Line 1027  sub make_new_child {
                             print $hfh "$now:$hostid{$clientip}:$what\n";                              print $hfh "$now:$hostid{$clientip}:$what\n";
                             print $client "ok\n";                               print $client "ok\n"; 
  } else {   } else {
                             print $client "error:$!\n";                              print $client "error: ".($!+0)
    ." IO::File->new Failed\n";
         }          }
        }         }
 # ------------------------------------------------------------------------- put  # ------------------------------------------------------------------------- put
Line 1069  sub make_new_child { Line 1056  sub make_new_child {
    if (untie(%hash)) {     if (untie(%hash)) {
                               print $client "ok\n";                                print $client "ok\n";
                            } else {                             } else {
                               print $client "error:$!\n";                                print $client "error: ".($!+0)
     ." untie(GDBM) failed\n";
                            }                             }
                        } else {                         } else {
                            print $client "error:$!\n";                             print $client "error: ".($!)
          ." tie(GDBM) Failed\n";
                        }                         }
       } else {        } else {
                           print $client "refused\n";                            print $client "refused\n";
Line 1111  sub make_new_child { Line 1100  sub make_new_child {
    if (untie(%hash)) {     if (untie(%hash)) {
                               print $client "ok\n";                                print $client "ok\n";
                            } else {                             } else {
                               print $client "error:$!\n";                                print $client "error: ".($!+0)
     ." untie(GDBM) Failed\n";
                            }                             }
                        } else {                         } else {
                            print $client "error:$!\n";                             print $client "error: ".($!+0)
          ." tie(GDBM) Failed\n";
                        }                         }
       } else {        } else {
                           print $client "refused\n";                            print $client "refused\n";
Line 1137  sub make_new_child { Line 1128  sub make_new_child {
               $qresult=~s/\&$//;                $qresult=~s/\&$//;
                               print $client "$qresult\n";                                print $client "$qresult\n";
                            } else {                             } else {
                               print $client "error:$!\n";                                print $client "error: ".($!+0)
     ." untie(GDBM) Failed\n";
                            }                             }
                        } else {                         } else {
                            print $client "error:$!\n";                             print $client "error: ".($!+0)
          ." tie(GDBM) Failed\n";
                        }                         }
 # ------------------------------------------------------------------------ eget  # ------------------------------------------------------------------------ eget
                    } elsif ($userinput =~ /^eget/) {                     } elsif ($userinput =~ /^eget/) {
Line 1173  sub make_new_child { Line 1166  sub make_new_child {
         print $client "error:no_key\n";          print $client "error:no_key\n";
                               }                                }
                            } else {                             } else {
                               print $client "error:$!\n";                                print $client "error: ".($!+0)
     ." untie(GDBM) Failed\n";
                            }                             }
                        } else {                         } else {
                            print $client "error:$!\n";                             print $client "error: ".($!+0)
          ." tie(GDBM) Failed\n";
                        }                         }
 # ------------------------------------------------------------------------- del  # ------------------------------------------------------------------------- del
                    } elsif ($userinput =~ /^del/) {                     } elsif ($userinput =~ /^del/) {
Line 1201  sub make_new_child { Line 1196  sub make_new_child {
    if (untie(%hash)) {     if (untie(%hash)) {
                               print $client "ok\n";                                print $client "ok\n";
                            } else {                             } else {
                               print $client "error:$!\n";                                print $client "error: ".($!+0)
     ." untie(GDBM) Failed\n";
                            }                             }
                        } else {                         } else {
                            print $client "error:$!\n";                             print $client "error: ".($!+0)
          ." tie(GDBM) Failed\n";
                        }                         }
 # ------------------------------------------------------------------------ keys  # ------------------------------------------------------------------------ keys
                    } elsif ($userinput =~ /^keys/) {                     } elsif ($userinput =~ /^keys/) {
Line 1222  sub make_new_child { Line 1219  sub make_new_child {
               $qresult=~s/\&$//;                $qresult=~s/\&$//;
                               print $client "$qresult\n";                                print $client "$qresult\n";
                            } else {                             } else {
                               print $client "error:$!\n";                                print $client "error: ".($!+0)
     ." untie(GDBM) Failed\n";
                            }                             }
                        } else {                         } else {
                            print $client "error:$!\n";                             print $client "error: ".($!+0)
          ." tie(GDBM) Failed\n";
                        }                         }
 # ----------------------------------------------------------------- dumpcurrent  # ----------------------------------------------------------------- dumpcurrent
                    } elsif ($userinput =~ /^dumpcurrent/) {                     } elsif ($userinput =~ /^currentdump/) {
                        my ($cmd,$udom,$uname,$namespace)                         my ($cmd,$udom,$uname,$namespace)
                           =split(/:/,$userinput);                            =split(/:/,$userinput);
                        $namespace=~s/\//\_/g;                         $namespace=~s/\//\_/g;
Line 1250  sub make_new_child { Line 1249  sub make_new_child {
                               next if (exists($data{$symb}) &&                                 next if (exists($data{$symb}) && 
                                        exists($data{$symb}->{$param}) &&                                         exists($data{$symb}->{$param}) &&
                                        $data{$symb}->{'v.'.$param} > $v);                                         $data{$symb}->{'v.'.$param} > $v);
                               #&logthis("v = ".$v." p = ".$param." s = ".$symb);  
                               $data{$symb}->{$param}=$value;                                $data{$symb}->{$param}=$value;
                               $data{$symb}->{'v.'.$param}=$value;                                $data{$symb}->{'v.'.$param}=$v;
                            }                             }
                            if (untie(%hash)) {                             if (untie(%hash)) {
                              while (my ($symb,$param_hash) = each(%data)) {                               while (my ($symb,$param_hash) = each(%data)) {
Line 1264  sub make_new_child { Line 1262  sub make_new_child {
                              chop($qresult);                               chop($qresult);
                              print $client "$qresult\n";                               print $client "$qresult\n";
                            } else {                             } else {
                              print $client "error:$!\n";                               print $client "error: ".($!+0)
    ." untie(GDBM) Failed\n";
                            }                             }
                        } else {                         } else {
                            print $client "error:$!\n";                             print $client "error: ".($!+0)
          ." tie(GDBM) Failed\n";
                        }                         }
 # ------------------------------------------------------------------------ dump  # ------------------------------------------------------------------------ dump
                    } elsif ($userinput =~ /^dump/) {                     } elsif ($userinput =~ /^dump/) {
Line 1298  sub make_new_child { Line 1298  sub make_new_child {
                                chop($qresult);                                 chop($qresult);
                                print $client "$qresult\n";                                 print $client "$qresult\n";
                            } else {                             } else {
                                print $client "error:$!\n";                                 print $client "error: ".($!+0)
      ." untie(GDBM) Failed\n";
                            }                             }
                        } else {                         } else {
                            print $client "error:$!\n";                             print $client "error: ".($!+0)
          ." tie(GDBM) Failed\n";
                        }                         }
 # ----------------------------------------------------------------------- store  # ----------------------------------------------------------------------- store
                    } elsif ($userinput =~ /^store/) {                     } elsif ($userinput =~ /^store/) {
Line 1338  sub make_new_child { Line 1340  sub make_new_child {
    if (untie(%hash)) {     if (untie(%hash)) {
                               print $client "ok\n";                                print $client "ok\n";
                            } else {                             } else {
                               print $client "error:$!\n";                                print $client "error: ".($!+0)
     ." untie(GDBM) Failed\n";
                            }                             }
                        } else {                         } else {
                            print $client "error:$!\n";                             print $client "error: ".($!+0)
          ." tie(GDBM) Failed\n";
                        }                         }
       } else {        } else {
                           print $client "refused\n";                            print $client "refused\n";
Line 1372  sub make_new_child { Line 1376  sub make_new_child {
               $qresult=~s/\&$//;                $qresult=~s/\&$//;
                               print $client "$qresult\n";                                print $client "$qresult\n";
                            } else {                             } else {
                               print $client "error:$!\n";                                print $client "error: ".($!+0)
     ." untie(GDBM) Failed\n";
                            }                             }
                        } else {                         } else {
                            print $client "error:$!\n";                             print $client "error: ".($!+0)
          ." tie(GDBM) Failed\n";
                        }                         }
 # -------------------------------------------------------------------- chatsend  # -------------------------------------------------------------------- chatsend
                    } elsif ($userinput =~ /^chatsend/) {                     } elsif ($userinput =~ /^chatsend/) {
Line 1414  sub make_new_child { Line 1420  sub make_new_child {
    print $client "ok\n";     print $client "ok\n";
        }         }
        else {         else {
    print $client "error:$!\n";     print $client "error: ".($!+0)
          ." IO::File->new Failed\n";
        }         }
 # ----------------------------------------------------------------------- idput  # ----------------------------------------------------------------------- idput
                    } elsif ($userinput =~ /^idput/) {                     } elsif ($userinput =~ /^idput/) {
Line 1438  sub make_new_child { Line 1445  sub make_new_child {
    if (untie(%hash)) {     if (untie(%hash)) {
                               print $client "ok\n";                                print $client "ok\n";
                            } else {                             } else {
                               print $client "error:$!\n";                                print $client "error: ".($!+0)
     ." untie(GDBM) Failed\n";
                            }                             }
                        } else {                         } else {
                            print $client "error:$!\n";                             print $client "error: ".($!+0)
          ." tie(GDBM) Failed\n";
                        }                         }
 # ----------------------------------------------------------------------- idget  # ----------------------------------------------------------------------- idget
                    } elsif ($userinput =~ /^idget/) {                     } elsif ($userinput =~ /^idget/) {
Line 1459  sub make_new_child { Line 1468  sub make_new_child {
               $qresult=~s/\&$//;                $qresult=~s/\&$//;
                               print $client "$qresult\n";                                print $client "$qresult\n";
                            } else {                             } else {
                               print $client "error:$!\n";                                print $client "error: ".($!+0)
     ." untie(GDBM) Failed\n";
                            }                             }
                        } else {                         } else {
                            print $client "error:$!\n";                             print $client "error: ".($!+0)
          ." tie(GDBM) Failed\n";
                        }                         }
 # ---------------------------------------------------------------------- tmpput  # ---------------------------------------------------------------------- tmpput
                    } elsif ($userinput =~ /^tmpput/) {                     } elsif ($userinput =~ /^tmpput/) {
Line 1479  sub make_new_child { Line 1490  sub make_new_child {
    print $client "$id\n";     print $client "$id\n";
        }         }
        else {         else {
    print $client "error:$!\n";     print $client "error: ".($!+0)
          ."IO::File->new Failed\n";
        }         }
   
 # ---------------------------------------------------------------------- tmpget  # ---------------------------------------------------------------------- tmpget
Line 1495  sub make_new_child { Line 1507  sub make_new_child {
                            close $store;                             close $store;
        }         }
        else {         else {
    print $client "error:$!\n";     print $client "error: ".($!+0)
          ."IO::File->new Failed\n";
        }         }
   
 # -------------------------------------------------------------------------- ls  # -------------------------------------------------------------------------- ls
Line 1546  sub make_new_child { Line 1559  sub make_new_child {
                 &logthis("<font color=blue>WARNING: "                  &logthis("<font color=blue>WARNING: "
                 ."Rejected client $clientip, closing connection</font>");                  ."Rejected client $clientip, closing connection</font>");
             }              }
  }                 }             
   
 # =============================================================================  # =============================================================================
                 
  &logthis("<font color=red>CRITICAL: "   &logthis("<font color=red>CRITICAL: "
  ."Disconnect from $clientip ($hostid{$clientip})</font>");       ."Disconnect from $clientip ($hostid{$clientip})</font>");    
         # tidy up gracefully and finish  
       
         $server->close();  
   
         # this exit is VERY important, otherwise the child will become          # this exit is VERY important, otherwise the child will become
         # a producer of more and more children, forking yourself into          # a producer of more and more children, forking yourself into
         # process death.          # process death.
         exit;          exit;
     }      
 }  }
   
   

Removed from v.1.105  
changed lines
  Added in v.1.109


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