Changeset 16055 for misc/runpugs
- Timestamp:
- 04/21/07 15:42:06 (19 months ago)
- Location:
- misc/runpugs
- Files:
-
- 3 modified
-
lib/Web/Terminal/Server.pm (modified) (12 diffs)
-
lib/Web/Terminal/Settings.pm (modified) (2 diffs)
-
perl/runpugs.pl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
misc/runpugs/lib/Web/Terminal/Server.pm
r15833 r16055 1 1 package Web::Terminal::Server; 2 2 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 19 15 20 16 use vars qw( $VERSION ); … … 49 45 my $v = (1 - $Web::Terminal::Settings::daemon)*(1-$Web::Terminal::Settings::test); 50 46 51 # Datastructures per app, so $session{$app}{...}, $inactive[$app][...] or @{$inactive[$app]}52 my @active_sessions = (); # id => session_number for active sessions47 # Datastructures per app, so $session{$app}{...}, $inactive[$app][...] or @{$inactive[$app]} 48 my @active_sessions = (); # id => session_number for active sessions 53 49 my @sessions = (); # session_number (from stack) => actual session object 54 50 my @session_numbers_stack = (); # stack for session numbers, i.e. those not active or inactive! … … 61 57 my @n_inactive_sessions = (); 62 58 63 # �imit number of session from a single IP.59 # Limit number of session from a single IP. 64 60 # Problem for folks behind a gateway, but otherwise too easy for DoS 65 61 my %n_sessions_ip = (); # ip -> nsessions 66 62 67 # for use by child to know how many new sessions to create63 # For use by child to know how many new sessions to create 68 64 my @n_new_sessions = (); 69 65 … … 82 78 my $host = $Web::Terminal::Settings::host; 83 79 my $port = $Web::Terminal::Settings::port; 84 $SIG{USR1} = \&clean_up_timed_out_sessions; 80 81 $SIG{USR1} = \&clean_up_timed_out_sessions; 85 82 $SIG{USR2} = \&init_create; 86 if ($Web::Terminal::Settings::daemon) { 83 84 if ($Web::Terminal::Settings::daemon) { 87 85 Proc::Daemon::Init; 88 86 } … … 90 88 # fork/exec by the book: 91 89 use Errno qw(EAGAIN); 92 FORK: { 90 91 FORK: { 93 92 if ( $childpid = fork ) { 94 93 … … 120 119 } 121 120 122 # normally the child restarts the parent if it dies121 # The child can restart the parent 123 122 if ($Web::Terminal::Settings::test==1) { 124 123 die "No restarting, test phase\n"; … … 130 129 } 131 130 } elsif ( $! == EAGAIN ) { 132 133 131 # Maybe ulimit might take us here 134 132 sleep 30; 135 133 redo FORK; 136 134 } else { 137 138 135 # Or ulimit could take us here 139 136 print "Couldn't fork" if $v; … … 147 144 # Advanced Perl Programming 148 145 sub login_proc { 149 150 146 # Unconditionally accept. 151 147 \&rcvd_msg_from_client; … … 531 527 532 528 #------------------------------------------------------------------------------- 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 533 535 sub deactivate_session { 534 536 my $app = shift; … … 536 538 my $ip = shift; 537 539 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 } 538 546 my $ncmd = $Web::Terminal::Settings::reset_command; 539 547 my $lines = $term->write($ncmd); … … 649 657 %{ $sessions[$app]}=(); 650 658 659 if (&sane($app)) { 651 660 for my $i ( 1 .. $Web::Terminal::Settings::npreloaded_sessions[$app] ) { 652 my $ret = &create_session($app);661 my $ret = &create_session($app); 653 662 print $ret>0?'OK: $ret':'NOK',': #sesssions: ', scalar( @{ $inactive_sessions[$app] } ), ' for app ', 654 663 $app, "\n" … … 657 666 assert(scalar(@{ $inactive_sessions[$app] })==$Web::Terminal::Settings::npreloaded_sessions[$app]); 658 667 } 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) 672 sub 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() 663 685 # all it does is set the counter @n_new_sessions (count zero!) 664 686 # if counter is 0, it gets reset to max-min 665 # �his avoids potential race hazards687 # this avoids potential race hazards 666 688 sub init_create { 667 689 -
misc/runpugs/lib/Web/Terminal/Settings.pm
r15408 r16055 61 61 62 62 #Pugs 63 my $ulimit='ulimit -m 64000; ulimit -v 64000;'; 64 my $nice='/usr/bin/nice'; 65 my $pugs='/usr/bin/pugs'; 66 my $rel_root='/home/andara/pugs-rel'; 67 my $dev_root='/home/andara/pugs-dev'; 68 63 69 our @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" 67 72 ); 68 73 … … 81 86 our $filter=0; 82 87 our $filter_pattern=''; 83 #my $root='/home/andara/apache';84 my $root='/Users/wim/Builds/pugs/misc/runpugs';88 my $root='/home/andara/apache'; 89 #my $root='/Users/wim/Builds/pugs/misc/runpugs'; 85 90 our $cgi_path="$root/cgi-bin/"; 86 91 our $lib_path="$root/lib/"; -
misc/runpugs/perl/runpugs.pl
r15408 r16055 64 64 && do { 65 65 $cmd=$cmdline; 66 # a ';' on a single-line command confuses pugs 67 if($cmd=~/$prompt/) {$cmd=~s/;\s*$//} 66 68 $cmd=~s/$Web::Terminal::Settings::prompt_pattern//; 67 69 chomp $cmd;
