Changeset 16055 for misc/runpugs

Show
Ignore:
Timestamp:
04/21/07 15:42:06 (19 months ago)
Author:
andara
Message:

[runpugs] use local copy of devel version to avoid versions with broken PUGS_SAFEMODE

Location:
misc/runpugs
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • misc/runpugs/lib/Web/Terminal/Server.pm

    r15833 r16055  
    11package Web::Terminal::Server; 
    22 
    3 =pod 
    4 The inactive sessions queue starts with n_inactive_max sessions. 
    5 Ideally, once it drops to n_inactive_min, it should gradually create  
    6 n_inactive_max-n_inactive_min sessions 
    7 To do this reallu asynchronously, we need to let the child handle this 
    8 The problem is that the child can't access the counters of the parent. 
    9 So I'd just have the child create n_inactive_max-n_inactive_min sessions, gradually e.g. one every 5 minutes 
    10 But that might interfere with the cleanup: 
    11 The child sleeps for some time, then cleans up 
    12 So if we use the same time constant (makes sense), 
    13 the we need a counter which is set by the signal, that's all 
    14  
    15  
    16 So child gets a SIGUSR 
    17 => it sets n_new_sessions to max-min if n_new_sessions was 0 
    18 =cut 
     3#The inactive sessions queue starts with n_inactive_max sessions. 
     4#Ideally, once it drops to n_inactive_min, it should gradually create  
     5#n_inactive_max-n_inactive_min sessions 
     6#To do this reallu asynchronously, we need to let the child handle this 
     7#The problem is that the child can't access the counters of the parent. 
     8#So I'd just have the child create n_inactive_max-n_inactive_min sessions, gradually e.g. one every 5 minutes 
     9#But that might interfere with the cleanup: 
     10#The child sleeps for some time, then cleans up 
     11#So if we use the same time constant (makes sense), 
     12#the we need a counter which is set by the signal, that's all 
     13#So child gets a SIGUSR 
     14#=> it sets n_new_sessions to max-min if n_new_sessions was 0 
    1915 
    2016use vars qw( $VERSION ); 
     
    4945my $v                 = (1 - $Web::Terminal::Settings::daemon)*(1-$Web::Terminal::Settings::test); 
    5046 
    51 #Datastructures per app, so $session{$app}{...}, $inactive[$app][...] or @{$inactive[$app]} 
    52 my @active_sessions             = (); # id => session_number for active sessions 
     47# Datastructures per app, so $session{$app}{...}, $inactive[$app][...] or @{$inactive[$app]} 
     48my @active_sessions       = (); # id => session_number for active sessions 
    5349my @sessions              = (); # session_number (from stack) =>  actual session object 
    5450my @session_numbers_stack = ();  # stack for session numbers, i.e. those not active or inactive! 
     
    6157my @n_inactive_sessions = (); 
    6258 
    63 #imit number of session from a single IP. 
     59# Limit number of session from a single IP. 
    6460# Problem for folks behind a gateway, but otherwise too easy for DoS  
    6561my %n_sessions_ip = ();    # ip -> nsessions  
    6662 
    67 # for use by child to know how many new sessions to create 
     63# For use by child to know how many new sessions to create 
    6864my @n_new_sessions = (); 
    6965 
     
    8278        my $host = $Web::Terminal::Settings::host; 
    8379        my $port = $Web::Terminal::Settings::port; 
    84         $SIG{USR1} = \&clean_up_timed_out_sessions; 
     80 
     81    $SIG{USR1} = \&clean_up_timed_out_sessions; 
    8582        $SIG{USR2} = \&init_create; 
    86         if ($Web::Terminal::Settings::daemon) { 
     83         
     84    if ($Web::Terminal::Settings::daemon) { 
    8785                Proc::Daemon::Init; 
    8886        } 
     
    9088        # fork/exec by the book: 
    9189        use Errno qw(EAGAIN); 
    92   FORK: { 
     90 
     91    FORK: { 
    9392                if ( $childpid = fork ) { 
    9493 
     
    120119                        } 
    121120 
    122                         # normally the child restarts the parent if it dies 
     121                        # The child can restart the parent 
    123122                        if ($Web::Terminal::Settings::test==1) { 
    124123                        die "No restarting, test phase\n"; 
     
    130129                        } 
    131130                } elsif ( $! == EAGAIN ) { 
    132  
    133131                        # Maybe ulimit might take us here 
    134132                        sleep 30; 
    135133                        redo FORK; 
    136134                } else { 
    137  
    138135                        # Or ulimit could take us here 
    139136                        print "Couldn't fork" if $v; 
     
    147144# Advanced Perl Programming 
    148145sub login_proc { 
    149  
    150146        # Unconditionally accept. 
    151147        \&rcvd_msg_from_client; 
     
    531527 
    532528#------------------------------------------------------------------------------- 
     529# deactivate_session() was meant to take a running session and recycle it 
     530# using a reset_command. 
     531# Unfortunately, if the user leaves the session on an unfinished multi-line, 
     532# the reset_command doesn't get through.  
     533# So we should check that based on the value of prompt. 
     534# If it's multi-line we need kill & create 
    533535sub deactivate_session { 
    534536        my $app   = shift; 
     
    536538        my $ip    = shift; 
    537539        my $term  = $sessions[$app]{ $active_sessions[$app]{$id} }; 
     540    my $unfinished_multi_line=0; 
     541    my $tprompt=$term->{prompt}; 
     542    if ($tprompt=~/$Web::Terminal::Settings::prompt_pattern/ and $tprompt ne 
     543    $Web::Terminal::Settings::prompt) { 
     544    my $unfinished_multi_line=1; 
     545    } 
    538546        my $ncmd  = $Web::Terminal::Settings::reset_command; 
    539547        my $lines = $term->write($ncmd); 
     
    649657                  %{ $sessions[$app]}=(); 
    650658                   
     659if (&sane($app)) { 
    651660                for my $i ( 1 .. $Web::Terminal::Settings::npreloaded_sessions[$app] ) { 
    652                         my $ret = &create_session($app); 
     661            my $ret = &create_session($app); 
    653662                        print $ret>0?'OK: $ret':'NOK',': #sesssions: ', scalar( @{ $inactive_sessions[$app] } ), ' for app ', 
    654663                          $app, "\n" 
     
    657666        assert(scalar(@{ $inactive_sessions[$app] })==$Web::Terminal::Settings::npreloaded_sessions[$app]); 
    658667        } 
    659 }    # END of init_session() 
    660  
    661 #------------------------------------------------------------------------------- 
    662 # init_create gets called by SIGUSR2 
     668    } 
     669}    # END of init_sessions() 
     670#------------------------------------------------------------------------------ 
     671# check if command is sane (FSDO sane) 
     672sub sane { 
     673    my $app=shift; 
     674    my $cmd=$Web::Terminal::Settings::commands[$app]; 
     675    $cmd=~s/^.*nice\s+//; # de-nice 
     676    my $reply=`PUGS_SAFEMODE=1 $cmd -e \"print 42\" 2>/dev/null`; 
     677    if ($reply==42) { 
     678        return 1; 
     679    } else { 
     680        return 0; 
     681    } 
     682} 
     683#------------------------------------------------------------------------------- 
     684# init_create gets called by SIGUSR2, as raised by async_init_create() 
    663685# all it does is set the counter @n_new_sessions (count zero!) 
    664686# if counter is 0, it gets reset to max-min 
    665 #his avoids potential race hazards  
     687# this avoids potential race hazards  
    666688sub init_create { 
    667689 
  • misc/runpugs/lib/Web/Terminal/Settings.pm

    r15408 r16055  
    6161 
    6262#Pugs 
     63my $ulimit='ulimit -m 64000; ulimit -v 64000;'; 
     64my $nice='/usr/bin/nice'; 
     65my $pugs='/usr/bin/pugs'; 
     66my $rel_root='/home/andara/pugs-rel'; 
     67my $dev_root='/home/andara/pugs-dev'; 
     68 
    6369our @commands=( 
    64 #'/usr/bin/nice /home/andara/pugs-rel/pugs -I/home/andara/pugs-rel/blib6/lib', 
    65 '/usr/bin/pugs', 
    66 '/usr/bin/nice /usr/bin/pugs' 
     70"$ulimit $nice $rel_root/pugs -I$rel_root/blib6/lib", 
     71"$ulimit $nice $dev_root/pugs -I$dev_root/blib6/lib" 
    6772); 
    6873 
     
    8186our $filter=0; 
    8287our $filter_pattern=''; 
    83 #my $root='/home/andara/apache'; 
    84 my $root='/Users/wim/Builds/pugs/misc/runpugs'; 
     88my $root='/home/andara/apache'; 
     89#my $root='/Users/wim/Builds/pugs/misc/runpugs'; 
    8590our $cgi_path="$root/cgi-bin/"; 
    8691our $lib_path="$root/lib/"; 
  • misc/runpugs/perl/runpugs.pl

    r15408 r16055  
    6464            && do { 
    6565                $cmd=$cmdline; 
     66                # a ';' on a single-line command confuses pugs 
     67                if($cmd=~/$prompt/) {$cmd=~s/;\s*$//} 
    6668                $cmd=~s/$Web::Terminal::Settings::prompt_pattern//; 
    6769                chomp $cmd;