head 1.16; access; symbols; locks; strict; comment @# @; 1.16 date 97.01.02.17.51.32; author alexis; state Exp; branches; next 1.15; 1.15 date 96.11.05.10.43.46; author alexis; state Exp; branches; next 1.14; 1.14 date 96.10.31.21.01.46; author alexis; state Exp; branches; next 1.13; 1.13 date 96.10.26.18.58.09; author alexis; state Exp; branches; next 1.12; 1.12 date 96.10.26.09.32.23; author alexis; state Exp; branches; next 1.11; 1.11 date 96.10.04.10.06.47; author alexis; state Exp; branches; next 1.10; 1.10 date 96.10.04.09.27.01; author alexis; state Exp; branches; next 1.9; 1.9 date 96.10.03.15.47.52; author alexis; state Exp; branches; next 1.8; 1.8 date 96.10.03.14.59.59; author alexis; state Exp; branches; next 1.7; 1.7 date 96.10.02.16.39.58; author alexis; state Exp; branches; next 1.6; 1.6 date 96.10.02.13.53.22; author alexis; state Exp; branches; next 1.5; 1.5 date 96.09.30.22.50.01; author alexis; state Exp; branches; next 1.4; 1.4 date 96.09.30.19.42.36; author alexis; state Exp; branches; next 1.3; 1.3 date 96.09.30.17.02.15; author root; state Exp; branches; next 1.2; 1.2 date 96.09.30.08.35.29; author root; state Exp; branches; next 1.1; 1.1 date 96.09.29.22.54.37; author alexis; state Exp; branches; next ; desc @working version @ 1.16 log @Mainly relating to fork request handling - which avoids the necessity to load config files redundantly. @ text @#!/usr/bin/perl5.003 ############################################################################### # # CONFIGURABLE THINGS # ############################################################################### system("echo $0: 1 >> /tmp/progname"); # The value of this variable is a colon-separated list of directories # where Perl5 will look for required files. The files this program uses # are msgs.pl and tfr.pl. So find those files and put their directories # between the quotes - separating them by colons if they are in more than # one location. $main::localpl_dir = "/usr/local/lib/perl5"; # What's the location of the master configuration file. There is no way # to specify an alternative file. You must put it in here. (Of course # your free to change the contents of this file to point to other files, # if you want to change your configuration on a regular basis. See the manual # page for more details.) $main::master_config_file = "/usr/local/lib/ppp/master.cfg"; ############################################################################### # # DON'T CHANGE ANYTHING BELOW HERE # ############################################################################### use strict; use FileHandle; use Sys::Hostname; ($main::progname = $0) =~ s/^.*\/([^\/]+)/$1/; $main::modvers{'thisprogram'} = "MARKER"; ($main::modvers{'thisprogram'} =~ /^M.*R$/) && ($main::modvers{'thisprogram'} = '$Id: ppp-on,v 1.15 1996/11/05 10:43:46 alexis Exp alexis $') =~ s/^.*,v (\S+) .*$/$1/; $ENV{'LOCALPLDIR'} && ($main::localpl_dir = $ENV{'LOCALPLDIR'}); unshift(@@INC,split(/:/, $main::localpl_dir)); # Functions used by this file require "msgs.pl"; ($main::modvers{'msgs.pl'} ne "1.12") && (!$ENV{'IGNORELOCALPLVERS'}) && &msgs::error("configuration error: wrong version of msgs.pl"); require "tfr.pl"; ($main::modvers{'tfr.pl'} ne "1.2") && (!$ENV{'IGNORELOCALPLVERS'}) && &msgs::error("configuration error: wrong version of tfr.pl"); # Lock file $main::lock_file = "/var/lock/ppp_on"; # Message level $msgs::verboselevel = 100; # Facility to which all messages are logged $msgs::facility = 'local0'; # Run in bg or fg? $main::background = 1; sub load_config { my($config_file, $level) = @@_; my $fh; defined($config_file) || ($config_file = $main::master_config_file); defined($level) ? $level++ : ($level = 0); &msgs::debug(5, "load_config: config file is $config_file, level is $level"); ($fh = new FileHandle $config_file) || &msgs::error("can't open $config_file: $!"); while (<$fh>) { chop; if (/^\s*$/ || /^\s*#.*$/) { next; } elsif (/^newsrunning: (.+)$/) { $main::newsrunning_cmd = $1; } elsif (/^newsrun: (.+)$/) { $main::newsrun_cmd = $1; } elsif (/^sendmail: (.+)$/) { $main::sendmail_cmd = $1; } elsif (/^xmitnews: (.+)$/) { $main::xmitnews_cmd = $1; } elsif (/^slurp: (.+)$/) { $main::slurp_cmd = $1; } elsif (/^chat: (.+)$/) { $main::chat_cmd = $1; } elsif (/^nnmaster: (.+)$/) { $main::nnmaster_cmd = $1; } elsif (/^include: (.+)$/) { &msgs::debug(5, "load_config: about to include $_\n"); &load_config($1, $level); # &msgs::debug(5, "load_config: done including $_\n"); } elsif (/^pppd: (.+)$/) { $main::pppd_cmd = $1; } elsif (/^chatline: (.+)$/) { push @@main::chat_lines, $1; } elsif (/^chatscript: (.+)$/) { open(CHAT_HANDLE, $1) || &msgs::error("can't open $1: $!"); while () { chop; if (/^\s*$/ || /^\s*#.*$/) { next; } else { push @@main::chat_lines, $_; } } close CHAT_HANDLE; } elsif (/^password: (.+)$/) { $main::password = $1; } elsif (/^login: (.+)$/) { $main::login = $1; } elsif (/^telno: (.+)$/) { $main::telno = $1; } elsif (/^netmask: (.+)$/) { $main::netmask = $1; } elsif (/^up: (.+)$/) { $main::up_cmd = $1; if (!defined($main::announce_flg)) { $main::announce_flg = 1; } } elsif (/^down: (.+)$/) { $main::down_cmd = $1; if (!defined($main::announce_flg)) { $main::announce_flg = 1; } } elsif (/^port: (.+)$/) { if (!defined($main::port_file)) { $main::port_file = $1; } } elsif (/^speed: (.+)$/) { if (!defined($main::port_speed)) { $main::port_speed = $1; } } elsif (/^idle: (.+)$/) { if (!defined($main::max_idle_interval)) { $main::max_idle_interval = $1; } } elsif (/^getnews: (.+)$/) { if (!defined($main::getnews_flg)) { $main::getnews_flg = $1; } } elsif (/^quality: (.+)$/) { if (!defined($main::qualt_flg)) { $main::qualt_flg = $1; } } elsif (/^nntpserver: (.+)$/) { if (!defined($main::nntp_server)) { $main::nntp_server = $1; } } else { &msgs::error("invalid configuration file entry: $_"); } } $fh->close; $level && return; defined($main::newsrunning_cmd) || &msgs::error("newsrunning command not defined in any config file"); defined($main::newsrun_cmd) || &msgs::error("newsrun command not defined in any config file"); defined($main::sendmail_cmd) || &msgs::error("sendmail command not defined in any config file"); defined($main::chat_cmd) || &msgs::error("chat command not defined in any config file"); defined($main::xmitnews_cmd) || &msgs::error("xmitnews command not defined in any config file"); defined($main::slurp_cmd) || &msgs::error("slurp command not defined in any config file"); defined($main::nnmaster_cmd) || &msgs::error("nnmaster command not defined in any config file"); defined($main::pppd_cmd) || &msgs::error("pppd command not defined in any config file"); defined($main::port_file) || &msgs::error("port not defined in any config file"); defined($main::port_speed) || &msgs::error("speed not defined in any config file"); defined($main::max_idle_interval) || &msgs::error("idle not defined in any config file"); defined($main::getnews_flg) || &msgs::error("getnews not defined in any config file"); defined(@@main::chat_lines) || &msgs::error("no chat lines defined in any config file"); defined($main::netmask) || &msgs::error("netmask not defined in any config file"); defined($main::nntp_server) || &msgs::error("nntpserver not defined in any config file"); defined($main::qualt_flg) || &msgs::error("quality not defined in any config file"); foreach (@@main::chat_lines) { if (/%T/ && !defined($main::telno)) { &msgs::error("telno not defined in any config file but %T is used"); } elsif (/%L/ && !defined($main::login)) { &msgs::error("login not defined in any config file but %L is used"); } elsif (/%P/ && !defined($main::password)) { &msgs::error("password not defined in any config file but %P is used"); } elsif (/%I/ && !defined($main::max_idle_interval)) { &msgs::error("idle time not defined in any config file but %I is used"); } } &msgs::debug(5, "load_config: newsrunning command is $main::newsrunning_cmd"); &msgs::debug(5, "load_config: newsrun command is $main::newsrun_cmd"); &msgs::debug(5, "load_config: sendmail command is $main::sendmail_cmd"); &msgs::debug(5, "load_config: chat command is $main::chat_cmd"); &msgs::debug(5, "load_config: xmitnews command is $main::xmitnews_cmd"); &msgs::debug(5, "load_config: slurp command is $main::slurp_cmd"); &msgs::debug(5, "load_config: nnmaster command is $main::nnmaster_cmd"); &msgs::debug(5, "load_config: pppd command is $main::pppd_cmd"); &msgs::debug(5, "load_config: up command is $main::up_cmd"); &msgs::debug(5, "load_config: down command is $main::down_cmd"); &msgs::debug(5, "load_config: port is $main::port_file"); &msgs::debug(5, "load_config: speed is $main::port_speed"); &msgs::debug(5, "load_config: idle is $main::max_idle_interval"); &msgs::debug(5, "load_config: news flag is $main::getnews_flg"); # This lines contains all sorts of funny characters and it screws 'logger'! # &msgs::debug(5, "load_config: chat script is " . join("\n", @@main::chat_lines)); &msgs::debug(5, "load_config: netmask is $main::netmask"); &msgs::debug(5, "load_config: nntp server is $main::nntp_server"); &msgs::debug(5, "load_config: min quality is $main::qualt_flg"); &msgs::debug(5, "load_config: password is $main::password"); &msgs::debug(5, "load_config: login is $main::login"); &msgs::debug(5, "load_config: telno is $main::telno"); &msgs::debug(5, "load_config: announce flag is $main::announce_flg"); } sub chgstate { my($newpid, $newstate) = @@_; my($tmplock_file) = "$main::lock_file.$$"; my($oldpid, $oldstate, $holding_pid, $line, $forkreqpid); # Check if there is a fork request if ($main::progname eq "ppp-on") { &msgs::debug(10, "chgstate: checking for fork requests"); if (-f "/tmp/pleasefork") { &msgs::debug(10, "chgstate: found a fork request"); open(FORKREQ_HANDLE, "/tmp/pleasefork") || &msgs::error("can't open forkrequest file: $!"); chop($line = ); close FORKREQ_HANDLE; if ($forkreqpid = fork) { &msgs::debug(10, "chgstate: parent returning"); } elsif (defined $forkreqpid) { &msgs::debug(10, "chgstate: child continuing"); if ($line =~ /ip-up/) { &msgs::debug(10, "chgstate: child calling ip_up"); $0 = 'ip-up-f'; $main::progname = $0; &ip_up; } elsif ($line =~ /ip-down/) { &msgs::debug(10, "chgstate: child calling ip_down"); $0 = 'ip-down-f'; $main::progname = $0; &ip_down; } elsif ($line =~ /news-xfer/) { &msgs::debug(10, "chgstate: child calling news_xfer"); $0 = 'news-xfer-f'; $main::progname = $0; &news_xfer; } elsif ($line =~ /news-flush/) { &msgs::debug(10, "chgstate: child calling news_flush"); $0 = 'news-flush-f'; $main::progname = $0; &news_flush; } else { &msgs::error("being asked to fork $line"); } exit 0; } else { &msgs::error("fork failed: $!"); } unlink "/tmp/pleasefork"; } else { &msgs::debug(10, "chgstate: no fork requests"); } } # newpid > 0 means lock with newpid and newstate if ($newpid > 0) { open(TMPLOCK_HANDLE, ">$tmplock_file") || &msgs::error("can't open temporary lock: $!"); print TMPLOCK_HANDLE join(' ', $newpid, $newstate), "\n"; close TMPLOCK_HANDLE; if (link($tmplock_file, $main::lock_file)) { &msgs::debug(100, "chgstate: lock mode, locked"); unlink $tmplock_file; return(0); } open(LOCK_HANDLE, $main::lock_file) || &msgs::error("can't read lock file: $!"); ($holding_pid) = ( =~ /^([0-9]+) .*$/); close LOCK_HANDLE; if ($holding_pid && -d "/proc/$holding_pid") { &msgs::debug(100, "chgstate: lock mode, busy"); unlink $tmplock_file; return($holding_pid); } unlink $main::lock_file; if (link($tmplock_file, $main::lock_file)) { &msgs::debug(100, "chgstate: lock mode, locked after stale"); unlink $tmplock_file; return(0); } return(-1); } elsif (! -f $main::lock_file) { return(0, "NO-PROC"); } elsif ($newpid < 0) { &msgs::debug(100, "chgstate: mode: unlock mode"); unlink $main::lock_file; return(0); # no pid or 0 } elsif ($newstate ne "0") { open(LOCK_HANDLE, $main::lock_file) || &msgs::error("can't read lock file: $!"); chop($line = ); ($oldpid, $oldstate) = split(/ /, $line); close LOCK_HANDLE; open(LOCK_HANDLE, ">$main::lock_file") || &msgs::error("can't write lock file: $!"); print LOCK_HANDLE join(' ', $oldpid, $newstate), "\n"; close LOCK_HANDLE; &msgs::debug(100, "chgstate: write state mode: $oldstate to $newstate"); return(0); } else { &msgs::debug(100, "chgstate: mode: reading state ..."); open(LOCK_HANDLE, $main::lock_file) || &msgs::error("can't read lock file: $!"); chop($line = ); ($oldpid, $oldstate) = split(/ /, $line); close LOCK_HANDLE; if (-d "/proc/$oldpid") { &msgs::debug(100, "chgstate: mode: read state mode: $oldstate"); return($oldpid, $oldstate); } else { &msgs::debug(100, "chgstate: mode: read state mode: stale lock"); return(0, "NO-PROC"); } } } sub bg_pppd { my($pppd_cmd, $port_file, $port_speed, $chat_cmd, $netmask, $hostname, $ipparam, @@chat_lines) = @@_; my($pid, $cmd_str); $main::tmp_chat_script_file = "/tmp/$main::progname.$$.chat"; &msgs::debug(10, "bg_pppd: sof"); open(TMP_CHAT_HANDLE, ">$main::tmp_chat_script_file") || &msgs::error("can't open $main::tmp_chat_script_file: $!"); foreach (@@chat_lines) { # &msgs::debug(10, "bg_pppd: current line is $_"); s/\%I/$main::max_idle_interval/g; s/\%P/$main::password/g; s/\%L/$main::login/g; s/\%T/$main::telno/g; print TMP_CHAT_HANDLE "$_\n"; } close TMP_CHAT_HANDLE; &msgs::debug(10, "bg_pppd: after rewriting"); $cmd_str = "$pppd_cmd $port_file $port_speed connect \"$chat_cmd -v -f $main::tmp_chat_script_file\" crtscts defaultroute lock netmask $netmask $hostname: asyncmap 0x00000000 mru 576 mtu 576 lcp-echo-interval 180 -detach ipparam $ipparam"; if ($pid = fork) { return($pid); } elsif (defined $pid) { &msgs::debug(8, "bg_pppd: about to exec: $cmd_str"); exec($cmd_str) || &msgs::error("exec failed: $!"); } else { &msgs::error("fork failed: $!"); } } sub sub1 { $SIG{'CHLD'} = 'sub1'; &msgs::debug(6, "sub1: caught SIGCHLD"); (-f $main::tmp_chat_script_file) && unlink $main::tmp_chat_script_file; wait; } sub sub4 { $SIG{'ALRM'} = 'sub4'; &msgs::debug(6, "sub4: caught SIGALRM"); } sub sub3 { $SIG{'USR1'} = 'sub3'; &msgs::debug(6, "sub3: caught SIGUSR1"); } sub sub2 { my($pid, $state); $SIG{'INT'} = 'IGNORE'; $SIG{'TERM'} = 'IGNORE'; &msgs::debug(6, "sub2: caught SIGINT or SIGTERM"); ($pid, $state) = &chgstate(0, 0); if (defined $main::pppd_pid && $main::pppd_pid > 0) { &chgstate(0, "PD-USERREQ"); kill 'INT', $main::pppd_pid; wait; } } sub announce { my($cmd) = @@_; if (! -x $cmd) { &msgs::warning("missing announce command: $cmd"); } else { &msgs::debug(10, "announce: announcing with command $cmd"); system($cmd); &msgs::debug(10, "announce: announcing done"); } } sub xfercnt { my($xfercnt) = 0; open(PROC_HANDLE, "/proc/net/dev") || &msgs::error("can't open /proc/net/dev: $!"); while () { if (/^\s+ppp0:\s+(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+(\d+)\s+.*\n$/) { $xfercnt += $1 + $2; } } close PROC_HANDLE; # $xfercnt = int(rand(6) + 1); &msgs::debug(12, "xfercnt: total use $xfercnt"); return($xfercnt); } sub ppp_on { my($state, $idle_start_time, $last_use_count, $this_use_count); my($rc, $idle_check_interval, $pid, $hostname); $hostname = hostname; &msgs::debug(10, "hostname is $hostname"); &load_config(); if ($main::background) { # Check that the child background process will (probably) be able to # lock successfully in a moment. $msgs::msgs_mode = $msgs::MSGS_STD; ($pid, $state) = &chgstate(0, 0); if ($state ne "NO-PROC") { &msgs::error("process $rc has control!"); } $msgs::msgs_mode = $msgs::MSGS_SYS; fork && exit 0; } &msgs::info("version $main::modvers{'thisprogram'} started"); close STDIN; if (($rc = &chgstate($$, "C")) > 0) { &msgs::error("process $rc has control!"); } elsif ($rc < 0) { &msgs::error("no process has control but can't lock"); } # Very necessary line! # $SIG{'CHLD'} = 'IGNORE'; $SIG{'USR1'} = 'sub3'; $SIG{'ALRM'} = 'sub4'; $SIG{'INT'} = 'sub2'; $SIG{'TERM'} = 'sub2'; if ($main::getnews_flg) { &msgs::debug(8, "ppp_on: calling newsrunning"); system("su - news -c \"$main::newsrunning_cmd on\""); &msgs::debug(8, "ppp_on: newsrunning done"); &msgs::debug(8, "ppp_on: calling newsrun"); system("su - news -c $main::newsrun_cmd"); &msgs::debug(8, "ppp_on: newsrun done"); } else { &msgs::debug(10, "ppp_on: no news processing"); } $last_use_count = 0; $idle_start_time = time; # Check the idle status every quarter of the total idle timeout period $idle_check_interval = int($main::max_idle_interval / 4); &msgs::debug(10, "ppp_on: timeout is $main::max_idle_interval, check every $idle_check_interval"); $main::pppd_pid = &bg_pppd($main::pppd_cmd, $main::port_file, $main::port_speed, $main::chat_cmd, $main::netmask, $hostname, "$main::getnews_flg:$msgs::verboselevel:$main::announce_flg:$main::qualt_flg", @@main::chat_lines); $SIG{'CHLD'} = 'sub1'; for (;;) { ($pid, $state) = &chgstate(0, 0); &msgs::debug(100, "ppp_on: state is $state"); if ($state eq "A" || $state eq "D") { last; } elsif ($state eq "C") { if (-d "/proc/$main::pppd_pid") { &msgs::debug(10, "ppp_on: pppd[$main::pppd_pid] is running"); } else { &msgs::info("restarting pppd"); $main::pppd_pid = &bg_pppd($main::pppd_cmd, $main::port_file, $main::port_speed, $main::chat_cmd, $main::netmask, $hostname, "$main::getnews_flg:$msgs::verboselevel:$main::announce_flg:$main::qualt_flg", @@main::chat_lines); &msgs::debug(10, "ppp_on: pppd[$main::pppd_pid] started"); } } elsif ($state eq "S1") { if (-d "/proc/$main::pppd_pid") { &msgs::debug(10, "ppp_on: waiting for ip_up to give permission to kill pppd"); } else { &msgs::debug(10, "ppp_on: pppd did not get to run ip-up"); &chgstate(0, "A"); next; } } elsif ($state eq "UC") { ; } elsif ($state eq "OC") { if ($main::max_idle_interval != 0) { if ($last_use_count != ($this_use_count = &xfercnt("ppp0"))) { $idle_start_time = time; &msgs::debug(12, "ppp_on: interface in use"); $last_use_count = $this_use_count; } elsif (time - $idle_start_time > $main::max_idle_interval) { &msgs::info("idle timeout elapsed"); &chgstate(0, "PD-IDLE"); kill 15, $main::pppd_pid; } else { &msgs::debug(12, "ppp_on: idle time rising"); } alarm($idle_check_interval); } } elsif ($state eq "PA-WAS-UC" || $state eq "PD-USERREQ" || $state eq "PR-USERREQ" || $state eq "PD-IDLE" || $state eq "PD-BADQ") { kill 15, $main::pppd_pid; } else { &msgs::internal(1, $main::modvers{'thisprogram'}, "S $state"); } # This should not be necessary but perhaps it will help: $SIG{'CHLD'} = 'sub1'; &msgs::debug(8, "ppp_on: going to sleep"); sleep 3600; &msgs::debug(8, "ppp_on: woken up, going to top of loop"); } &chgstate(-1, 0); return(0); } sub ip_down { my($pid, $state); #&load_config(); ($pid, $state) = &chgstate(0, 0); &msgs::debug(100, "ip_down: state is $state"); if ($state eq "PD-IDLE") { &msgs::info("connection down"); &msgs::syslog("disconnected (idle timeout)"); $main::announce_flg && $main::down_cmd && &announce($main::down_cmd); &chgstate(0, "D"); } elsif ($state eq "PD-USERREQ") { &msgs::info("connection down"); &msgs::syslog("disconnected (by request)"); $main::announce_flg && $main::down_cmd && &announce($main::down_cmd); &chgstate(0, "D"); } elsif ($state eq "PR-USERREQ") { &msgs::info("connection down"); &msgs::syslog("disconnected (redialling by request)"); $main::announce_flg && $main::down_cmd && &announce($main::down_cmd); &chgstate(0, "C"); } elsif ($state eq "PA-WAS-UC") { &chgstate(0, "A"); } elsif ($state eq "PR-BADQ") { &chgstate(0, "C"); } elsif ($state eq "OC") { &msgs::info("remote end hung up"); &msgs::syslog("disconnected (remote hung up)"); $main::announce_flg && $main::down_cmd && &announce($main::down_cmd); &chgstate(0, "D"); } else { &msgs::internal(2, $main::modvers{'thisprogram'}, "S $state"); } &wake_ppp_on; return(0); } sub wake_ppp_on { my ($pid, $state); &msgs::debug(8, "wake_ppp_on: waking ppp_on"); # the chgstate call just gets the pid of the ppp_on process, the # state shouldn't get written ($pid, $state) = &chgstate(0, 0); kill 'USR1', $pid; } sub ppp_off { my($pid, $state); &msgs::debug(10, "ppp_off: start"); ($pid, $state) = &chgstate(0, 0); &msgs::debug(100, "ppp_off: state is $state"); if ($state eq "OC") { &chgstate(0, "PD-USERREQ"); } elsif ($state eq "C") { &chgstate(0, "S1"); } elsif ($state eq "UC") { &chgstate(0, "PA-WAS-UC"); } elsif ($state eq "S1" || $state eq "PD-USERREQ" || $state eq "PA-WAS-UC") { &msgs::error("an abandon request is pending"); } elsif ($state eq "NO-PROC") { &msgs::error("no process running!"); } else { &msgs::internal(3, $main::modvers{'thisprogram'}, "S $state"); } &wake_ppp_on; return(0); } sub ppp_info { my($state, $pid); ($pid, $state) = &chgstate(0, 0); if ($state eq "NO-PROC") { print "ppp-on not running\n"; return(0); } print "process number is $pid\n"; if ($state eq "C") { print "Connecting\n"; } elsif ($state eq "UC") { print "Connecting, quality tests pending\n"; } elsif ($state eq "PR-BADQ") { print "Connecting, quality reconnection request pending\n"; } elsif ($state eq "OC") { print "Connected\n"; } elsif ($state eq "PD-USERREQ") { print "Connected, user disconnection request pending\n"; } elsif ($state eq "PR-USERREQ") { print "Connected, user reconnection request pending\n"; } elsif ($state eq "PD-IDLE") { print "Connected, idle timeout disconnection request pending\n"; } elsif ($state eq "D") { print "Disconnected\n"; } elsif ($state eq "S1") { print "Abandonning connection attempt\n"; } elsif ($state eq "PA-WAS-UC") { print "Abandonning connection attempt\n"; } elsif ($state eq "A") { print "Abandonned\n"; } else { &msgs::internal(4, $main::modvers{'thisprogram'}, "S $state"); } } sub ppp_redial { my($pid, $state); ($pid, $state) = &chgstate(0, 0); &msgs::debug(100, "ppp_redial: state is $state"); if ($state eq "OC") { &chgstate(0, "PR-USERREQ"); &wake_ppp_on; } elsif ($state eq "NO-PROC") { &msgs::error("no process running!"); } else { &msgs::internal(5, $main::modvers{'thisprogram'}, "S $state"); } return(0); } sub getlinequality { &msgs::debug(10, "getlinequality: checking line"); sleep(10); return(100); } sub news_xfer { my($backoff, $gotnews, $state, $linequality, $pid, $starttime); ($pid, $state) = &chgstate(0, 0); if ($state ne "OC") { &msgs::error("not connected"); } #&load_config(); &news_xfer_real(); } sub news_xfer_real { my($backoff, $gotnews, $state, $linequality, $pid, $starttime); &msgs::debug(8, "news_xfer_real: calling newsrunning"); system("su - news -c \"$main::newsrunning_cmd off\""); &msgs::debug(8, "news_xfer_real: newsrunning done"); &msgs::debug(8, "news_xfer_real: calling xmitnews"); system("su - news -c \"$main::xmitnews_cmd -d -h $main::nntp_server -f /var/spool/news/out.going/$main::nntp_server/togo\""); &msgs::debug(8, "news_xfer_real: xmitnews done"); # fix kacky file &msgs::debug(10, "news_xfer_real: fixing kacky file"); truncate("/usr/local/lib/nntp/slurp.news.demon.co.uk", 14); &msgs::debug(10, "news_xfer_real: kacky file fixed"); &msgs::debug(10, "news_xfer_real: backoff give up period is $main::getnews_flg"); for ($starttime=time,$backoff=1,$gotnews=0; !$gotnews && time<($starttime+$main::getnews_flg); $backoff *= 2) { &msgs::debug(8, "news_xfer_real: retrieving new news articles: $backoff"); if (system("su - news -c \"$main::slurp_cmd -d $main::nntp_server\"") / 256 == 0) { &msgs::debug(8, "news_xfer_real: new news articles retrieved"); $gotnews = 1; } else { &msgs::info("news retrieval failed, retrying in $backoff seconds"); sleep $backoff; } } if ($gotnews) { &msgs::debug(8, "news_xfer_real: calling newsrunning"); system("su - news -c \"$main::newsrunning_cmd on\""); &msgs::debug(8, "news_xfer_real: newsrunning done"); &msgs::debug(8, "news_xfer_real: calling newsrun"); system("su - news -c $main::newsrun_cmd"); &msgs::debug(8, "news_xfer_real: newsrun done"); &msgs::debug(8, "news_xfer_real: calling nnmaster"); system("su - news -c $main::nnmaster_cmd"); &msgs::debug(8, "news_xfer_real: nnmaster done"); } else { &msgs::debug(10, "news_xfer_real: transfer failed or pppd orphaned me"); } } sub ip_up { my($backoff, $gotnews, $state, $linequality, $pid, $starttime); #&load_config(); ($pid, $state) = &chgstate(0, 0); &msgs::debug(100, "ip_up: state: $state, news: $main::getnews_flg"); if ($state eq "S1") { &chgstate(0, "PA-WAS-UC"); &wake_ppp_on; return(0); } elsif ($state eq "C") { ; } else { &msgs::internal(6, $main::modvers{'thisprogram'}, "S $state"); } &chgstate(0, "UC"); &wake_ppp_on; &msgs::debug(10, "ip_up: now unofficially connected"); &msgs::info("unoffically connected"); if ($main::qualt_flg) { &msgs::debug(10, "ip_up: quality check"); &msgs::info("checking line quality"); $linequality = &getlinequality; ($pid, $state) = &chgstate(0, 0); if ($state eq "PA-WAS-UC") { &msgs::debug(10, "ip_up: spotted that we have been asked to abandon"); return(0); } elsif ($state eq "UC") { if ($linequality < $main::qualt_flg) { &msgs::info("bad quality connection, redial requested"); &chgstate(0, "PR-BADQ"); &wake_ppp_on; return(0); } } else { &msgs::internal(7, $main::modvers{'thisprogram'}, "S $state"); } } else { &msgs::debug(10, "ip_up: acceptable quality is $main::qualt_flg, therefore no check"); } &chgstate(0, "OC"); $main::announce_flg && $main::up_cmd && &announce($main::up_cmd); &msgs::debug(10, "ip_up: done announcing"); &msgs::syslog("connected"); &msgs::debug(10, "ip_up: done syslogging"); &wake_ppp_on; &msgs::debug(10, "ip_up: woken ppp_on"); &msgs::info("officially connected, post connection processing follows"); &msgs::debug(8, "ip_up: running sendmail"); system("$main::sendmail_cmd -q &"); &msgs::debug(8, "ip_up: sendmail in background"); if (defined($main::getnews_flg) && $main::getnews_flg) { &news_xfer_real(); } else { &msgs::debug(10, "ip_up: no news processing"); } &msgs::info("post-connection processing complete"); return(0); } sub news_flush { #&load_config(); &msgs::info("newsrunning on ..."); system("su - news -c \"$main::newsrunning_cmd on\""); &msgs::info("newsrun ..."); system("su - news -c $main::newsrun_cmd"); &msgs::info("nnmaster ..."); system("su - news -c $main::nnmaster_cmd"); &msgs::info("done"); return(0); } sub usage_ppp_on { print STDERR "Usage: $main::progname [ -v | -d ] [ -fg | -bg ] [ -p ] [ -b ] [ -s ] [ -ni | -i ] [ -na | -a ] [ -nq | -q ] [ -nn | -n ]\n"; print STDERR " $main::progname -V\n"; exit 1; } sub usage_ip_up_down { print STDERR "Usage: $main::progname [ ]\n"; exit 1; } sub usage_no_args { print STDERR "Usage: $main::progname\n"; exit 1; } sub show_version { print "$main::progname version ", $main::modvers{'thisprogram'}, "\n"; exit 0; } sub forkreq { my($prog) = @@_; &msgs::debug(10, "forkreq: called with parameter $prog"); open(FORKREQ_HANDLE, ">/tmp/pleasefork") || &msgs::error("can't open /tmp/pleasefork: $!"); print FORKREQ_HANDLE "$prog\n"; close FORKREQ_HANDLE; &msgs::debug(10, "forkreq: request submitted, now waking ppp_on"); &wake_ppp_on; &msgs::debug(10, "forkreq: woken ppp_on, all done"); return 0; } sub main { my(@@ARGV) = @@_; my($rc) = 0; $0 = $main::progname . ' '. join(' ', @@ARGV); $msgs::msgs_mode = $msgs::MSGS_SYS; &msgs::debug(10, "main: top, progname is $main::progname"); if ($main::progname ne "ppp-on" && $main::progname ne "ppp-off" && $main::progname ne "ip-up" && $main::progname ne "ip-down" && $main::progname ne "ppp-redial" && $main::progname eq "news-flush" && $main::progname ne "ppp-info" && $main::progname eq "news-xfer") { &msgs::error("program incorrectly named"); } # if ($main::progname eq "ip-up" || $main::progname eq "ip-down") { # $msgs::msgs_mode = $msgs::MSGS_SYS; # } ($> != 0) && &msgs::warning("you are not root!"); # Process the options or split the ipparam parameter - depending on the # name of this program if ($main::progname eq "ip-up" || $main::progname eq "ip-down") { # &msgs::debug(100, "6th cmd line arg is $ARGV[5]"); # if (defined $ARGV[5] && $ARGV[5] && !defined $ARGV[6]) { # ($main::getnews_flg, $msgs::verboselevel, $main::announce_flg, $main::qualt_flg) = split(/:/, $ARGV[5]); # &msgs::debug(10, "getnews: $main::getnews_flg, msgs::verboselevel: $msgs::verboselevel, wall: $main::announce_flg, qualt: $main::qualt_flg"); # } else { # &usage_ip_up_down; # } ; } elsif ($main::progname eq "ppp-on" || $main::progname eq "news-xfer") { while (defined($ARGV[0]) && $ARGV[0] =~ /^-./) { $_ = shift @@ARGV; # -V is print the version number if (/^-V$/) { &show_version; # -d is turn on debug at the specified level } elsif (/^-d(.*)/) { $msgs::verboselevel = ($1 ? $1 : shift @@ARGV); # -v is be verbose } elsif (/^-v$/) { $msgs::verboselevel = 3; # -fg is run in foreground (useful for shells) } elsif (/^-fg$/) { $main::background = 0; # -bg is run in background } elsif (/^-bg$/) { $main::background = 1; # -p is set port } elsif (/^-p(.*)/) { $main::port_file = ($1 ? $1 : shift @@ARGV); # -b is set port speed } elsif (/^-b(.*)/) { $main::port_speed = ($1 ? $1 : shift @@ARGV); # -s is for an alternative NNTP server } elsif (/^-s(.*)/) { $main::nntp_server = ($1 ? $1 : shift @@ARGV); # -i is set idle timeout in seconds } elsif (/^-i(.*)/) { $main::max_idle_interval = ($1 ? $1 : shift @@ARGV); # -ni is set idle timeout in seconds } elsif (/^-ni$/) { $main::max_idle_interval = 0; # -a is announce } elsif (/^-a$/) { $main::announce_flg = 1; # -na is don't announce } elsif (/^-na$/) { $main::announce_flg = 0; # -q is check quality } elsif (/^-q(.*)$/) { $main::qualt_flg = ($1 ? $1 : shift @@ARGV); # -nq is don't check quality } elsif (/^-nq$/) { $main::qualt_flg = 0; # -nn is don't get news } elsif (/^-nn$/) { $main::getnews_flg = 0; # Check this last! It interferes with previous options! # -n is get news } elsif (/^-n(.*)$/) { $main::getnews_flg = ($1 ? $1 : shift @@ARGV); # otherwise the user has typed something daft } else { &usage_ppp_on; } } defined($ARGV[0]) && &usage_ppp_on; } elsif ($main::progname eq "ppp-down" || $main::progname eq "ppp-redial" || $main::progname eq "ppp-info" || $main::progname eq "news-flush" || $main::progname eq "ppp-off") { defined($ARGV[0]) && &usage_no_args; } # if ($main::progname eq "ppp-on") { # $msgs::msgs_mode = $msgs::MSGS_SYS; # } # tmp file registration services #$SIG{'INT'} = 'sighandler'; #$SIG{'TERM'} = 'sighandler'; if ($main::progname eq "ppp-on") { return(&ppp_on); } elsif ($main::progname eq "ppp-off") { return(&ppp_off); } elsif ($main::progname eq "ip-up") { system("echo $0: calling forkreq now >> /tmp/progname"); return(&forkreq($main::progname)); } elsif ($main::progname eq "ip-down") { return(&forkreq($main::progname)); } elsif($main::progname eq "ppp-redial") { return(&ppp_redial); } elsif($main::progname eq "news-flush") { return(&forkreq($main::progname)); } elsif($main::progname eq "news-xfer") { return(&forkreq($main::progname)); } elsif($main::progname eq "ppp-info") { return(&ppp_info); } } umask 077; exit(&main(@@ARGV)); @ 1.15 log @Added news-xfer command. Everything works now, but the next release will be an attempt to speed up program startup by getting ppp_on to fork other commands by requesters not directly running other internal programs. @ text @d9 2 d38 1 a38 1 ($main::modvers{'thisprogram'} =~ /^M.*R$/) && ($main::modvers{'thisprogram'} = '$Id: ppp-on,v 1.14 1996/10/31 21:01:46 alexis Exp alexis $') =~ s/^.*,v (\S+) .*$/$1/; d53 1 a53 1 $msgs::verboselevel = 2; d219 47 a265 1 my($oldpid, $oldstate, $holding_pid, $line); d315 1 d539 1 a539 1 &load_config(); d691 1 a691 1 &load_config(); d713 1 a713 1 for ($starttime=time,$backoff=1,$gotnews=0; !$gotnews && time<($starttime+$main::getnews_flg) && getppid != 1; $backoff *= 2) { d745 1 a745 1 &load_config(); d813 1 a813 1 &load_config(); d853 15 d875 1 d895 8 a902 7 &msgs::debug(100, "6th cmd line arg is $ARGV[5]"); if (defined $ARGV[5] && $ARGV[5] && !defined $ARGV[6]) { ($main::getnews_flg, $msgs::verboselevel, $main::announce_flg, $main::qualt_flg) = split(/:/, $ARGV[5]); &msgs::debug(10, "getnews: $main::getnews_flg, msgs::verboselevel: $msgs::verboselevel, wall: $main::announce_flg, qualt: $main::qualt_flg"); } else { &usage_ip_up_down; } d982 1 a982 1 $main::progname eq "ppp-info" || $main::progname eq "newsflush" || d1000 2 a1001 1 return(&ip_up); d1003 1 a1003 1 return(&ip_down); d1007 1 a1007 1 return(&news_flush); d1009 1 a1009 1 return(&news_xfer); @ 1.14 log @Took all the configuration out! That's a lot of changes! @ text @d36 1 a36 1 ($main::modvers{'thisprogram'} =~ /^M.*R$/) && ($main::modvers{'thisprogram'} = '$Id: ppp-on,v 1.13 1996/10/26 18:58:09 alexis Exp alexis $') =~ s/^.*,v (\S+) .*$/$1/; d68 1 a68 1 ($fh = new FileHandle $config_file) || &msgs::error("xcan't open $config_file: $!"); d285 1 a285 1 open(TMP_CHAT_HANDLE, ">$main::tmp_chat_script_file") || &msgs::error("ycan't open $main::tmp_chat_script_file: $!"); a297 1 &msgs::debug(10, "command string is $cmd_str"); d634 58 d752 1 a752 40 &msgs::debug(8, "ip_up: calling newsrunning"); system("su - news -c \"$main::newsrunning_cmd off\""); &msgs::debug(8, "ip_up: newsrunning done"); &msgs::debug(8, "ip_up: calling xmitnews"); system("su - news -c \"$main::xmitnews_cmd -d -h $main::nntp_server -f /var/spool/news/out.going/$main::nntp_server/togo\""); &msgs::debug(8, "ip_up: xmitnews done"); # fix kacky file &msgs::debug(10, "ip_up: fixing kacky file"); truncate("/usr/local/lib/nntp/slurp.news.demon.co.uk", 14); &msgs::debug(10, "ip_up: kacky file fixed"); &msgs::debug(10, "ip_up: backoff give up period is $main::getnews_flg"); for ($starttime=time,$backoff=1,$gotnews=0; !$gotnews && time<($starttime+$main::getnews_flg) && getppid != 1; $backoff *= 2) { &msgs::debug(8, "ip_up: retrieving new news articles: $backoff"); if (system("su - news -c \"$main::slurp_cmd -d $main::nntp_server\"") / 256 == 0) { &msgs::debug(8, "ip_up: new news articles retrieved"); $gotnews = 1; } else { &msgs::info("news retrieval failed, retrying in $backoff seconds"); sleep $backoff; } } if ($gotnews) { &msgs::debug(8, "ip_up: calling newsrunning"); system("su - news -c \"$main::newsrunning_cmd on\""); &msgs::debug(8, "ip_up: newsrunning done"); &msgs::debug(8, "ip_up: calling newsrun"); system("su - news -c $main::newsrun_cmd"); &msgs::debug(8, "ip_up: newsrun done"); &msgs::debug(8, "ip_up: calling nnmaster"); system("su - news -c $main::nnmaster_cmd"); &msgs::debug(8, "ip_up: nnmaster done"); } else { &msgs::debug(10, "ip_ip: transfer failed or pppd orphaned me"); } d762 1 a762 1 sub newsflush d814 2 a815 2 $main::progname ne "ppp-redial" && $main::progname eq "newsflush" && $main::progname ne "ppp-info") { d838 1 a838 1 } elsif ($main::progname eq "ppp-on") { d939 4 a942 2 } elsif($main::progname eq "newsflush") { return(&newsflush); @ 1.13 log @Bumped msgs.pl version number check when reading status from lock files it now checks that the process is running before report the status therein &syslog calls changed to &msgs::syslog @ text @d2 27 d30 7 d38 2 a39 1 # Local host config goes here ############################################### d41 7 a47 1 $main::localpl_dir = "/usr/local/lib/perl5:/home/alexis/dev/ppp-on"; d49 2 a50 11 $main::port_file = "/dev/cua0"; $main::port_speed = 38400; $main::hostname_cmd = "/bin/hostname -f"; $main::newsrunning_cmd = "/usr/lib/newsbin/input/newsrunning"; $main::newsrun_cmd = "/usr/lib/newsbin/input/newsrun"; $main::sendmail_cmd = "/usr/lib/sendmail"; $main::xmitnews_cmd = "/usr/local/lib/nntp/xmitnews"; $main::slurp_cmd = "/usr/local/lib/nntp/slurp"; $main::chat_cmd = "/usr/sbin/chat"; $main::nnmaster_cmd = "/usr/lib/nn/nnmaster"; $main::pppd_cmd = "/usr/sbin/pppd"; d52 2 a53 6 $main::max_idle_interval = 300; $main::getnews_flg = 1; $main::wall_flg = 1; $main::qualt_flg = 0; $main::background = 1; $main::news_backoff_limit = 180; d56 2 a57 1 # Remote host config goes here ############################################## d59 4 a62 3 $main::chat_file = "/usr/local/lib/ppp/demon.chat"; $main::netmask = "255.255.0.0"; $main::nntp_server = "news.demon.co.uk"; d64 2 a65 1 # Don't change ############################################################## d67 61 a127 1 ($main::progname = $0) =~ s/^.*\/([^\/]+)/$1/; d129 29 a157 2 $main::modvers{'thisprogram'} = "MARKER"; ($main::modvers{'thisprogram'} =~ /^M.*R$/) && ($main::modvers{'thisprogram'} = '$Id: ppp-on,v 1.12 1996/10/26 09:32:23 alexis Exp alexis $') =~ s/^.*,v (\S+) .*$/$1/; d159 1 a159 2 $ENV{'FADLIBDIR'} && ($main::localpl_dir = $ENV{'FADLIBDIR'}); push(@@INC,split(/:/, $main::localpl_dir)); d161 51 a211 7 # Functions used by this file require "msgs.pl"; ($main::modvers{'msgs.pl'} ne "1.12") && (!$ENV{'FADIGNMODVERS'}) && &msgs::error("configuration error: wrong version of msgs.pl"); require "tmpreg.pl"; ($main::modvers{'tmpreg.pl'} ne "1.1") && (!$ENV{'FADIGNMODVERS'}) && &msgs::error("configuration error: wrong version of tmpreg.pl"); chop($msgs::hostname = `$main::hostname_cmd`); d279 1 d281 1 d283 16 a298 1 $cmd_str = "$main::pppd_cmd $main::port_file $main::port_speed connect \"$main::chat_cmd -v -f $main::chat_file\" crtscts defaultroute lock netmask $main::netmask $msgs::hostname: asyncmap 0x00000000 mru 576 mtu 576 lcp-echo-interval 180 -detach ipparam $main::getnews_flg:$msgs::verboselevel:$main::wall_flg:$main::qualt_flg"; d304 1 a304 2 exec($cmd_str); &msgs::error("exec failed: $!"); d314 1 d347 1 a347 2 my($mode) = @@_; &msgs::debug(10, "announce: mode: $mode"); d349 2 a350 2 if (! -x "/usr/local/lib/ppp/$mode.sh") { &msgs::warning("missing action file: /usr/local/lib/ppp/$mode.sh"); d352 2 a353 2 &msgs::debug(10, "announce: announcing"); system("/usr/local/lib/ppp/$mode.sh"); d361 1 a361 1 open(PROC_HANDLE, "/proc/net/dev") || die; d378 1 a378 1 my($rc, $idle_check_interval, $pid); d380 15 a394 1 $main::background && fork && exit; d397 1 a403 1 $msgs::msgs_mode = $msgs::MSGS_SYS; d426 2 a427 1 $main::pppd_pid = &bg_pppd; d431 2 d444 1 a444 1 $main::pppd_pid = &bg_pppd; a483 1 &msgs::info("exiting"); d491 1 a491 1 $msgs::msgs_mode = $msgs::MSGS_SYS; d499 1 a499 1 $main::wall_flg && &announce("down"); d504 1 a504 1 $main::wall_flg && &announce("down"); d509 1 a509 1 $main::wall_flg && &announce("down"); d518 1 a518 1 $main::wall_flg && &announce("down"); a541 1 $msgs::msgs_mode = $msgs::MSGS_STD; a567 2 $msgs::msgs_mode = $msgs::MSGS_STD; a612 1 $msgs::msgs_mode = $msgs::MSGS_STD; d637 1 a637 1 my($backoff, $gotnews, $state, $linequality, $pid); d639 1 a639 1 $msgs::msgs_mode = $msgs::MSGS_SYS; d647 1 a647 1 exit(0); d666 1 a666 1 exit(0); d668 1 a668 1 if ($linequality < 90) { d672 1 a672 1 exit(0); d677 2 d682 1 a682 1 $main::wall_flg && &announce("up"); d694 1 a694 1 if (defined $main::getnews_flg && $main::getnews_flg) { d708 2 a709 1 for ($backoff=1,$gotnews=0; !$gotnews && $backoff<$main::news_backoff_limit && getppid != 1; $backoff *= 2) { d733 1 a733 1 &msgs::debug(10, "ip_ip: transfer failed or pppd exited"); d740 1 a740 1 exit(0); d746 1 a746 1 $msgs::msgs_mode = $msgs::MSGS_STD; d761 14 a774 1 sub usage d776 1 a776 2 print STDERR "Usage: $main::progname -V\n"; print STDERR " $main::progname [ -d level | -v ]\n"; d792 13 d807 2 a808 55 # Process the options while (defined($ARGV[0]) && $ARGV[0] =~ /^-./) { $_ = shift @@ARGV; # -V is print the version number if (/^-V$/) { &show_version; # -d is turn on debug at the specified level } elsif (/^-d(.*)/) { $msgs::verboselevel = ($1 ? $1 : shift @@ARGV); # -v is be verbose } elsif (/^-v$/) { $msgs::verboselevel = 3; # -n is get news } elsif (/^-n$/) { $main::getnews_flg = 1; # -nn is don't get news } elsif (/^-nn$/) { $main::getnews_flg = 0; # -w is wall } elsif (/^-w$/) { $main::wall_flg = 1; # -nw is don't wall } elsif (/^-nw$/) { $main::wall_flg = 0; # -q is check quality } elsif (/^-q$/) { $main::qualt_flg = 1; # -nq is don't check quality } elsif (/^-nq$/) { $main::qualt_flg = 0; # -i is set idle timeout in seconds } elsif (/^-i(.*)/) { $main::max_idle_interval = ($1 ? $1 : shift @@ARGV); # -ni is set idle timeout in seconds } elsif (/^-ni$/) { $main::max_idle_interval = 0; # -fg is run in foreground (useful for shells) } elsif (/^-fg$/) { $main::background = 0; # -bg is run in background } elsif (/^-bg$/) { $main::background = 1; d810 6 a815 1 # otherwise the user has typed something daft d817 1 a817 1 &usage; d819 87 a905 1 } d915 4 a918 13 } elsif($main::progname eq "ip-up" || $main::progname eq "ip-down") { &msgs::debug(10, "6th cmd line arg is $ARGV[5]"); if (defined $ARGV[5] && $ARGV[5]) { ($main::getnews_flg, $msgs::verboselevel, $main::wall_flg, $main::qualt_flg) = split(/:/, $ARGV[5]); &msgs::debug(10, "getnews: $main::getnews_flg, msgs::verboselevel: $msgs::verboselevel, wall: $main::wall_flg, qualt: $main::qualt_flg"); } else { &msgs::internal(8, $main::modvers{'thisprogram'}, "A $ARGV[5]"); } if ($main::progname eq "ip-up") { return(&ip_up); } else { return(&ip_down); } a924 2 } else { &msgs::error("program incorrectly named"); a925 1 return(0); @ 1.12 log @Changed from perl4 to perl5 Separated localhost config and remote host config a little &chgstate did return just the new state, but now returns (pid, newstate) No longer walls, but just calls external script, up to you what it does Turned off quality check by default Changed &ppp_info to give slightly friendlier messages Fixed $0 to get rid of 'perl' @ text @d39 1 a39 1 ($main::modvers{'thisprogram'} =~ /^M.*R$/) && ($main::modvers{'thisprogram'} = '$Id: ppp-on,v 1.11 1996/10/04 10:06:47 alexis Exp alexis $') =~ s/^.*,v (\S+) .*$/$1/; d46 1 a46 1 ($main::modvers{'msgs.pl'} ne "1.10") && (!$ENV{'FADIGNMODVERS'}) && &msgs::error("configuration error: wrong version of msgs.pl"); d84 1 a84 1 return("NO-PROC"); d106 7 a112 2 &msgs::debug(100, "chgstate: mode: read state mode: $oldstate"); return($oldpid, $oldstate); d175 1 a175 1 &msgs::debug(10, "announcing"); d177 1 a177 1 &msgs::debug(10, "announcing done"); d305 1 a305 1 syslog("disconnected (idle timeout)"); d310 1 a310 1 syslog("disconnected (by request)"); d315 1 a315 1 syslog("disconnected (redialling by request)"); d324 1 a324 1 syslog("disconnected (remote hung up)"); a377 1 print "$main::progname version: $main::modvers{'thisprogram'}\n"; d379 6 a384 1 print "process $pid\n"; d492 3 a494 1 syslog("connected"); d496 1 a585 1 $rc = 0; @ 1.11 log @if slurp fails then subsequent news processing is abandonned. @ text @d1 2 a2 1 #!/usr/bin/perl4.036 d4 1 a4 1 # Config goes here ########################################################## d6 27 a32 26 $localpl_dir = "/usr/local/lib/perl4"; $lock_file = "/var/lock/ppp_on"; $port_file = "/dev/cua0"; $port_speed = 38400; $chat_file = "/usr/local/lib/ppp/demon.chat"; $netmask = "255.255.0.0"; $nntp_server = "news.demon.co.uk"; $hostname_cmd = "/bin/hostname -f"; $newsrunning_cmd = "/usr/lib/newsbin/input/newsrunning"; $newsrun_cmd = "/usr/lib/newsbin/input/newsrun"; $sendmail_cmd = "/usr/lib/sendmail"; $xmitnews_cmd = "/usr/local/lib/nntp/xmitnews"; $slurp_cmd = "/usr/local/lib/nntp/slurp"; $chat_cmd = "/usr/sbin/chat"; $nnmaster_cmd = "/usr/lib/nn/nnmaster"; $pppd_cmd = "/usr/sbin/pppd"; $verboselevel = 2; $max_idle_interval = 300; $getnews_flg = 1; $wall_flg = 1; $qualt_flg = 1; $background = 1; $news_backoff_limit = 180; d36 1 a36 1 ($progname = $0) =~ s/^.*\/([^\/]+)/$1/; d38 2 a39 2 $modvers{'thisprogram'} = "MARKER"; ($modvers{'thisprogram'} =~ /^M.*R$/) && ($modvers{'thisprogram'} = '$Id: ppp-on,v 1.10 1996/10/04 09:27:01 alexis Exp alexis $') =~ s/^.*,v (\S+) .*$/$1/; d41 2 a42 2 $ENV{'FADLIBDIR'} && ($localpl_dir = $ENV{'FADLIBDIR'}); push(@@INC,split(/:/, $localpl_dir)); d46 1 a46 1 ($modvers{'msgs.pl'} ne "1.7") && (!$ENV{'FADIGNMODVERS'}) && &error("configuration error: wrong version of msgs.pl"); d48 1 a48 1 ($modvers{'tmpreg.pl'} ne "1.1") && (!$ENV{'FADIGNMODVERS'}) && &error("configuration error: wrong version of tmpreg.pl"); d50 1 a50 1 chop($hostname = `$hostname_cmd`); d54 3 a56 3 local($newpid, $newstate) = @@_; local($tmplock_file) = "$lock_file.$$"; local($oldpid, $oldstate); d60 1 a60 1 open(TMPLOCK_HANDLE, ">$tmplock_file") || &error("can't open temporary lock: $!"); d63 2 a64 2 if (link($tmplock_file, $lock_file)) { &debug(100, "chgstate: lock mode, locked"); d68 1 a68 1 open(LOCK_HANDLE, $lock_file) || &error("can't read lock file: $!"); d72 1 a72 1 &debug(100, "chgstate: lock mode, busy"); d76 3 a78 3 unlink $lock_file; if (link($tmplock_file, $lock_file)) { &debug(100, "chgstate: lock mode, locked after stale"); d83 1 a83 1 } elsif (! -f $lock_file) { d86 2 a87 2 &debug(100, "chgstate: mode: unlock mode"); unlink $lock_file; d91 1 a91 1 open(LOCK_HANDLE, $lock_file) || &error("can't read lock file: $!"); d95 1 a95 1 open(LOCK_HANDLE, ">$lock_file") || &error("can't write lock file: $!"); d98 1 a98 1 &debug(100, "chgstate: write state mode: $oldstate to $newstate"); d101 2 a102 2 &debug(100, "chgstate: mode: reading state ..."); open(LOCK_HANDLE, $lock_file) || &error("can't read lock file: $!"); d106 2 a107 2 &debug(100, "chgstate: mode: read state mode: $oldstate"); return($oldstate); d113 1 a113 1 local($pid); d115 1 a115 1 $cmd_str = "$pppd_cmd $port_file $port_speed connect \"$chat_cmd -v -f $chat_file\" crtscts defaultroute lock netmask $netmask $hostname: asyncmap 0x00000000 mru 576 mtu 576 lcp-echo-interval 180 -detach ipparam $getnews_flg:$verboselevel:$wall_flg:$qualt_flg"; d120 1 a120 1 &debug(8, "bg_pppd: about to exec: $cmd_str"); d122 1 a122 1 &error("exec failed: $!"); d124 1 a124 1 &error("fork failed: $!"); d131 1 a131 1 &debug(6, "sub1: caught SIGCHLD"); d138 1 a138 1 &debug(6, "sub4: caught SIGALRM"); d144 1 a144 1 &debug(6, "sub3: caught SIGUSR1"); d149 2 d153 3 a155 3 &debug(6, "sub2: caught SIGINT or SIGTERM"); ($state) = &chgstate(0,0,0); if (defined $pppd_pid && $pppd_pid > 0) { d157 1 a157 1 kill 'INT', $pppd_pid; d164 2 a165 2 local($mode) = @@_; &debug(10, "announce: mode: $mode"); d167 2 a168 2 if (! -f "/usr/local/lib/ppp/$mode.msg") { &warning("missing message file: /usr/local/lib/ppp/$mode.msg"); d170 3 a172 3 &debug(10, "announce: walling"); system("wall < /usr/local/lib/ppp/$mode.msg"); &debug(10, "announce: walling done"); d178 1 a178 1 local($xfercnt) = 0; d189 1 a189 1 &debug(12, "xfercnt: total use $xfercnt"); d195 2 a196 1 local($pppd_pid); d198 1 a198 1 $background && fork && exit; d200 1 a200 2 $msgs_mode = $MSGS_SYS; &info("version $modvers{'thisprogram'} started"); d203 1 a203 1 &error("process $rc has control!"); d205 1 a205 1 &error("no process has control but can't lock"); d207 1 d216 8 a223 8 if ($getnews_flg) { &debug(8, "ppp_on: calling newsrunning"); system("su - news -c \"$newsrunning_cmd on\""); &debug(8, "ppp_on: newsrunning done"); &debug(8, "ppp_on: calling newsrun"); system("su - news -c $newsrun_cmd"); &debug(8, "ppp_on: newsrun done"); d225 1 a225 1 &debug(10, "ppp_on: no news processing"); d230 3 a232 3 $pppd_pid = &bg_pppd; $idle_check_interval = int($max_idle_interval / 4); &debug(10, "ppp_on: timeout is $max_idle_interval, check every $idle_check_interval"); d236 2 a237 2 ($state) = &chgstate(0, 0, 0); &debug(100, "ppp_on: state is $state"); d241 2 a242 2 if (-d "/proc/$pppd_pid") { &debug(10, "ppp_on: pppd[$pppd_pid] is running"); d244 3 a246 3 &info("restarting pppd"); $pppd_pid = &bg_pppd; &debug(10, "ppp_on: pppd[$pppd_pid] started"); d249 2 a250 2 if (-d "/proc/$pppd_pid") { &debug(10, "ppp_on: waiting for ip_up to give permission to kill pppd"); d252 2 a253 2 &debug(10, "ppp_on: pppd did not get to run ip-up"); &chgstate(0, "A", 0); d256 4 a259 2 } elsif ($state eq "OC" || $state eq "UC") { if ($max_idle_interval != 0) { d262 1 a262 1 &debug(12, "ppp_on: interface in use"); d264 4 a267 4 } elsif (time - $idle_start_time > $max_idle_interval) { &info("idle timeout elapsed"); &chgstate(0, "PD-IDLE", 0); kill 15, $pppd_pid; d269 1 a269 1 &debug(12, "ppp_on: idle time rising"); d274 1 a274 1 kill 15, $pppd_pid; d276 1 a276 1 &internal(1, $modvers{'thisprogram'}, "S $state"); d280 1 a280 1 &debug(8, "ppp_on: going to sleep"); d282 1 a282 1 &debug(8, "ppp_on: woken up, going to top of loop"); d284 2 a285 2 &chgstate(-1,0,0); &info("exiting"); d291 4 a294 2 $msgs_mode = $MSGS_SYS; local($state) = &chgstate(0, 0, 0); d296 1 a296 1 &debug(100, "ip_down: state is $state"); d299 4 a302 3 &info("connection down"); $wall_flg && &announce("down"); &chgstate(0, "D", 0); d304 4 a307 3 &info("connection down"); $wall_flg && &announce("down"); &chgstate(0, "D", 0); d309 4 a312 3 &info("connection down"); $wall_flg && &announce("down"); &chgstate(0, "C", 0); d314 1 a314 1 &chgstate(0, "A", 0); d316 1 a316 1 &chgstate(0, "C", 0); d318 4 a321 3 &info("remote end hung up"); $wall_flg && &announce("down"); &chgstate(0, "D", 0); d323 1 a323 1 &internal(2, $modvers{'thisprogram'}, "S $state"); d331 3 a333 1 &debug(8, "wake_ppp_on: waking ppp_on"); d336 2 a337 1 kill 'USR1', &chgstate(99999, "BADSTATE", 99999); d342 5 a346 3 $msgs_mode = $MSGS_STD; &debug(10, "ppp_off: start"); local($state) = &chgstate(0, 0, 0); d348 1 a348 1 &debug(100, "ppp_off: state is $state"); d351 1 a351 1 &chgstate(0, "PD-USERREQ", 0); d353 1 a353 1 &chgstate(0, "S1", 0); d355 3 a357 3 &chgstate(0, "PA-WAS-UC", 0); } elsif ($state eq "S1") { &error("an abandon request is pending"); d359 3 a361 3 &error("no process running!"); } elsif ($state ne "C") { &internal(3, $modvers{'thisprogram'}, "S $state"); d369 3 a371 1 $msgs_mode = $MSGS_STD; d373 35 a407 3 print "$progname version: $modvers{'thisprogram'}\n"; printf "state is %s\n", &chgstate(0, 0, 0); return(0); d412 4 a415 2 $msgs_mode = $MSGS_STD; local($state) = &chgstate(0, 0, 0); d417 1 a417 1 &debug(100, "ppp_redial: state is $state"); d420 1 a420 1 &chgstate(0, "PR-USERREQ", 0); d423 1 a423 1 &error("no process running!"); d425 1 a425 1 &internal(4, $modvers{'thisprogram'}, "S $state"); d432 1 a432 1 &debug(10, "getlinequality: checking line"); d439 4 a442 2 $msgs_mode = $MSGS_SYS; local($state) = &chgstate(0, 0, 0); d444 1 a444 1 &debug(100, "ip_up: state: $state, news: $getnews_flg"); d447 1 a447 1 &chgstate(0, "PA-WAS-UC", 0); d453 1 a453 1 &internal(5, $modvers{'thisprogram'}, "S $state"); d456 1 a456 1 &chgstate(0, "UC", 0); d458 2 a459 2 &debug(10, "ip_up: now unofficially connected"); &info("unoffically connected"); d461 3 a463 3 if ($qualt_flg) { &debug(10, "ip_up: quality check"); &info("checking line quality"); d465 1 a465 1 ($state) = &chgstate(0, 0, 0); d467 1 a467 1 &debug(10, "ip_up: spotted that we have been asked to abandon"); d471 2 a472 2 &info("bad quality connection, redial requested"); &chgstate(0, "PR-BADQ", 0); d477 1 a477 1 &internal(6, $modvers{'thisprogram'}, "S $state"); d481 3 a483 2 &chgstate(0, "OC", 0); $wall_flg && &announce("up"); d485 1 a485 1 &info("officially connected, post connection processing follows"); d487 12 a498 12 &debug(8, "ip_up: running sendmail"); system("$sendmail_cmd -q &"); &debug(8, "ip_up: sendmail in background"); if (defined $getnews_flg && $getnews_flg) { &debug(8, "ip_up: calling newsrunning"); system("su - news -c \"$newsrunning_cmd off\""); &debug(8, "ip_up: newsrunning done"); &debug(8, "ip_up: calling xmitnews"); system("su - news -c \"$xmitnews_cmd -d -h $nntp_server -f /var/spool/news/out.going/$nntp_server/togo\""); &debug(8, "ip_up: xmitnews done"); d501 1 a501 1 &debug(10, "ip_up: fixing kacky file"); d503 1 a503 1 &debug(10, "ip_up: kacky file fixed"); d505 4 a508 4 for ($backoff=1,$gotnews=0; !$gotnews && $backoff<$news_backoff_limit && getppid != 1; $backoff *= 2) { &debug(8, "ip_up: retrieving new news articles: $backoff"); if (system("su - news -c \"$slurp_cmd -d $nntp_server\"") / 256 == 0) { &debug(8, "ip_up: new news articles retrieved"); d511 1 a511 1 &info("news retrieval failed, retrying in $backoff seconds"); d517 7 a523 7 &debug(8, "ip_up: calling newsrunning"); system("su - news -c \"$newsrunning_cmd on\""); &debug(8, "ip_up: newsrunning done"); &debug(8, "ip_up: calling newsrun"); system("su - news -c $newsrun_cmd"); &debug(8, "ip_up: newsrun done"); d525 3 a527 3 &debug(8, "ip_up: calling nnmaster"); system("su - news -c $nnmaster_cmd"); &debug(8, "ip_up: nnmaster done"); d529 1 a529 1 &debug(10, "ip_ip: transfer failed or pppd exited"); d532 1 a532 1 &debug(10, "ip_up: no news processing"); d535 1 a535 1 &info("post-connection processing complete"); d542 1 a542 1 $msgs_mode = $MSGS_STD; d544 2 a545 2 &info("newsrunning on ..."); system("su - news -c \"$newsrunning_cmd on\""); d547 2 a548 2 &info("newsrun ..."); system("su - news -c $newsrun_cmd"); d550 2 a551 2 &info("nnmaster ..."); system("su - news -c $nnmaster_cmd"); d553 1 a553 1 &info("done"); d559 2 a560 2 print STDERR "Usage: $progname -V\n"; print STDERR " $progname [ -d level | -v ]\n"; d566 1 a566 1 print "$progname version ", $modvers{'thisprogram'}, "\n"; d572 2 a573 2 local(@@ARGV) = @@_; local($rc) = 0; d576 3 d580 1 a580 1 while ($ARGV[0] =~ /^-./) { d589 1 a589 1 $verboselevel = ($1 ? $1 : shift @@ARGV); d593 1 a593 1 $verboselevel = 3; d597 1 a597 1 $getnews_flg = 1; d601 1 a601 1 $getnews_flg = 0; d605 1 a605 1 $wall_flg = 1; d609 1 a609 1 $wall_flg = 0; d613 1 a613 1 $qualt_flg = 1; d617 1 a617 1 $qualt_flg = 0; d621 1 a621 1 $max_idle_interval = ($1 ? $1 : shift @@ARGV); d625 1 a625 1 $max_idle_interval = 0; d629 1 a629 1 $background = 0; d633 1 a633 1 $background = 1; d645 1 a645 1 if ($progname eq "ppp-on") { d647 1 a647 1 } elsif ($progname eq "ppp-off") { d649 2 a650 2 } elsif($progname eq "ip-up" || $progname eq "ip-down") { &debug(10, "6th cmd line arg is $ARGV[5]"); d652 2 a653 2 ($getnews_flg, $verboselevel, $wall_flg, $qualt_flg) = split(/:/, $ARGV[5]); &debug(10, "getnews: $getnews_flg, verboselevel: $verboselevel, wall: $wall_flg, qualt: $qualt_flg"); d655 1 a655 1 &internal(7, $modvers{'thisprogram'}, "A $ARGV[5]"); d657 1 a657 1 if ($progname eq "ip-up") { d662 1 a662 1 } elsif($progname eq "ppp-redial") { d664 1 a664 1 } elsif($progname eq "newsflush") { d666 1 a666 1 } elsif($progname eq "ppp-info") { d669 1 a669 1 &error("program incorrectly named"); d675 1 a675 3 $rc = &main(@@ARGV); &debug(14, "_main: exiting with return code $rc"); exit $rc; @ 1.10 log @added an extra call to $SIG{'CHLD'} = 'sub1' this shouldn't be necessary, but it seems to not wait - or rather not clear a zombie - when it should. @ text @d30 1 d37 1 a37 1 ($modvers{'thisprogram'} =~ /^M.*R$/) && ($modvers{'thisprogram'} = '$Id: ppp-on,v 1.9 1996/10/03 15:47:52 alexis Exp alexis $') =~ s/^.*,v (\S+) .*$/$1/; d448 1 a448 1 for ($backoff=1; $backoff<180 && getppid != 1; $backoff *= 2) { d452 1 a452 1 last; d459 8 a466 7 &debug(8, "ip_up: calling newsrunning"); system("su - news -c \"$newsrunning_cmd on\""); &debug(8, "ip_up: newsrunning done"); &debug(8, "ip_up: calling newsrun"); system("su - news -c $newsrun_cmd"); &debug(8, "ip_up: newsrun done"); d468 6 a473 3 &debug(8, "ip_up: calling nnmaster"); system("su - news -c $nnmaster_cmd"); &debug(8, "ip_up: nnmaster done"); @ 1.9 log @more fixes @ text @d36 1 a36 1 ($modvers{'thisprogram'} =~ /^M.*R$/) && ($modvers{'thisprogram'} = '$Id: ppp-on,v 1.8 1996/10/03 14:59:59 alexis Exp alexis $') =~ s/^.*,v (\S+) .*$/$1/; d270 2 @ 1.8 log @Fixed a few bugs, added debug messages, rearranged a few things .... This works ... at least no bugs found yet. @ text @d14 1 a14 1 $hostname_cmd = "/bin/hostname"; d36 1 a36 1 ($modvers{'thisprogram'} =~ /^M.*R$/) && ($modvers{'thisprogram'} = '$Id: ppp-on,v 1.7 1996/10/02 16:39:58 alexis Exp alexis $') =~ s/^.*,v (\S+) .*$/$1/; d47 1 a47 1 $hostname = `$hostname_cmd -f`; d296 1 d445 2 a446 2 for ($backoff=1; $backoff<180 && getppid != 0; $backoff *= 2) { &debug(8, "ip_up: retrieving new news articles (backoff $backoff / 180)"); d451 2 a452 1 &debug(8, "ip_up: new news retrieval failed"); @ 1.7 log @updated version number in tests of msgs.pl version changed location of pl files @ text @d6 1 a7 1 $pppd_cmd = "/usr/sbin/pppd"; a9 1 $chat_cmd = "/usr/sbin/chat"; d12 3 a14 1 $hostname = "danae.demon.co.uk"; d20 1 a20 1 $nntp_server = "news.demon.co.uk"; d22 2 a25 1 $state_poll_interval = 3600; d36 1 a36 1 ($modvers{'thisprogram'} =~ /^M.*R$/) && ($modvers{'thisprogram'} = '$Id: ppp-on,v 1.6 1996/10/02 13:53:22 alexis Exp alexis $') =~ s/^.*,v (\S+) .*$/$1/; d47 2 d61 1 a61 1 &debug(10, "chgstate: lock mode, locked"); d68 2 a69 2 if (-d "/proc/$holding_pid") { &debug(10, "chgstate: lock mode, busy"); d75 1 a75 1 &debug(10, "chgstate: lock mode, locked after stale"); d83 1 a83 1 &debug(10, "chgstate: mode: unlock mode"); d95 1 a95 1 &debug(10, "chgstate: write state mode: $oldstate to $newstate"); d98 1 d103 1 a103 1 &debug(10, "chgstate: mode: read state mode: $oldstate"); d117 1 a117 1 &debug(10, "bg_pppd: about to exec: $cmd_str"); d128 1 a128 1 &debug(10, "sub1: caught SIGCHLD"); d135 1 a135 1 &debug(10, "sub4: caught SIGALRM"); d141 1 a141 1 &debug(10, "sub3: caught SIGUSR1"); d148 1 a148 1 &debug(10, "sub2: caught SIGINT or SIGTERM"); d160 1 d165 1 d167 1 d184 1 a184 1 &debug(10, "xfercnt: total use $xfercnt"); d204 1 a204 1 $SIG{'CHLD'} = 'sub1'; d211 1 a211 1 &debug(10, "ppp_on: calling newsrunning"); d213 1 a213 1 &debug(10, "ppp_on: newsrunning done"); d215 1 a215 1 &debug(10, "ppp_on: calling newsrun"); d217 1 a217 1 &debug(10, "ppp_on: newsrun done"); d228 1 a228 1 ($state) = &chgstate(0, 0, 0); d230 2 a231 1 &debug(10, "ppp_on: state is $state"); d244 1 a244 1 &debug(5, "ppp_on: waiting for ip_up to give permission to kill pppd"); d246 1 a246 1 &debug(5, "ppp_on: pppd didn't get to run ip-up"); d254 1 a254 1 &debug(10, "ppp_on: interface in use"); d261 1 a261 1 &debug(10, "ppp_on: idle time rising"); d270 3 a272 4 &debug(10, "ppp_on: going to sleep"); sleep $state_poll_interval; &debug(10, "ppp_on: woken up, checking state"); ($state) = &chgstate(0, 0, 0); d274 1 a275 1 &chgstate(-1,0,0); d284 1 a284 1 &debug(10, "ip_down: state is $state"); d302 1 a302 1 &debug(5, "suspect remote end hung up"); d309 1 d314 1 a314 1 &debug(10, "wake_ppp_on: waking ppp_on"); d326 1 a326 1 &debug(10, "ppp_off: state is $state"); d335 1 a335 1 &error("an abandon reqest is pending"); d342 1 a348 8 # open(PPPD_PIPE, "$pppd_cmd -V 2>&1 |") || &error("can't execute pppd: $!"); # while () { # if (/pppd version (2.2 patch level 0)$/) { # print "pppd version: $1\n"; # } # } # close PPPD_PIPE; d350 2 a351 5 local($state) = &chgstate(0, 0, 0); print "state is $state\n"; exit(0); d359 1 a359 1 &debug(10, "ppp_redial: state is $state"); d369 1 d384 1 a384 1 &debug(10, "ip_up: state: $state, news: $getnews_flg"); d411 1 a411 1 &debug(10, "ip_up: bad quality"); d424 1 a424 1 &debug(10, "ip_up: now officially connected"); d426 1 a426 2 &info("post-connection processing starting"); &debug(10, "ip_up: running sendmail"); d428 1 a428 1 &debug(10, "ip_up: sendmail in background"); d431 1 a431 1 &debug(10, "ip_up: calling newsrunning"); d433 1 a433 1 &debug(10, "ip_up: newsrunning done"); d435 1 a435 1 &debug(10, "ip_up: calling xmitnews"); d437 1 a437 1 &debug(10, "ip_up: xmitnews done"); d444 9 a452 5 do { &debug(10, "ip_up: retrieving new news articles"); $rc = system("su - news -c \"$slurp_cmd -d $nntp_server\"") / 256; &debug(10, "ip_up: new news articles retrieved"); } until ($rc == 0); d454 1 a454 1 &debug(10, "ip_up: calling newsrunning"); d456 1 a456 1 &debug(10, "ip_up: newsrunning done"); d458 1 a458 1 &debug(10, "ip_up: calling newsrun"); d460 1 a460 1 &debug(10, "ip_up: newsrun done"); d462 1 a462 1 &debug(10, "ip_up: calling nnmaster"); d464 1 a464 1 &debug(10, "ip_up: nnmaster done"); d473 18 d581 1 a581 1 &debug(5, "6th arg to me is $ARGV[5]"); d584 1 d595 2 d600 1 a600 1 &error("program incorrectly named\n"); d607 1 a607 1 &debug(10, "_main: exiting with return code $rc"); @ 1.6 log @more changes now works ... subject to sorting out which msgs.pl it should use. @ text @d5 1 a5 1 $localpl_dir = "/usr/local/lib/ppp"; d34 1 a34 1 ($modvers{'thisprogram'} =~ /^M.*R$/) && ($modvers{'thisprogram'} = '$Id: ppp-on,v 1.5 1996/09/30 22:50:01 alexis Exp alexis $') =~ s/^.*,v (\S+) .*$/$1/; d41 1 a41 1 ($modvers{'msgs.pl'} ne "1.1") && (!$ENV{'FADIGNMODVERS'}) && &error("configuration error: wrong version of msgs.pl"); @ 1.5 log @works @ text @a22 1 $idle_check_interval = 30; d25 3 d34 1 a34 1 ($modvers{'thisprogram'} =~ /^M.*R$/) && ($modvers{'thisprogram'} = '$Id: ppp-on,v 1.4 1996/09/30 19:42:36 alexis Exp alexis $') =~ s/^.*,v (\S+) .*$/$1/; d47 1 a47 1 local($newpid, $newstate, $getn_flg, $verb_flg) = @@_; d54 1 a54 1 print TMPLOCK_HANDLE join(' ', $newpid, $newstate, $getn_flg, $verb_flg), "\n"; d86 1 a86 1 ($oldpid, $oldstate, $getn_flg, $verb_flg) = split(/ /, $line); d89 1 a89 1 print LOCK_HANDLE join(' ', $oldpid, $newstate, $getn_flg, $verb_flg), "\n"; d96 1 a96 1 ($oldpid, $oldstate, $getn_flg, $verb_flg) = split(/ /, $line); d99 1 a99 1 return($oldstate, $getn_flg, $verb_flg); d107 1 a107 1 $cmd_str = "$pppd_cmd $port_file $port_speed connect \"$chat_cmd -v -f $chat_file\" crtscts defaultroute lock netmask $netmask $hostname: asyncmap 0x00000000 mru 576 mtu 576 lcp-echo-interval 180 -detach"; d152 11 d165 1 d184 1 a184 1 fork && exit; d189 1 a189 1 if (($rc = &chgstate($$, "C", $getnews_flg, $verboselevel)) > 0) { d217 2 d274 1 a274 2 local($state, $getn_flg, $verb_flg) = &chgstate(0, 0, 0); $verboselevel = $verb_flg; d280 1 d284 1 d295 1 d339 7 a345 7 open(PPPD_PIPE, "$pppd_cmd -V 2>&1 |") || &error("can't execute pppd: $!"); while () { if (/pppd version (2.2 patch level 0)$/) { print "pppd version: $1\n"; } } close PPPD_PIPE; d382 1 a382 3 local($state, $getn_flg, $verb_flg) = &chgstate(0, 0, 0); $getnews_flg = $getn_flg; $verboselevel = $verb_flg; d401 1 a401 3 $qualtest_flg = 1; if ($qualtest_flg) { d422 1 a424 1 &info("offically connected"); d426 1 d466 1 d513 16 d533 2 a534 2 # -i is set idle timeout in seconds } elsif (/^-i$/) { d537 8 d559 12 a570 4 } elsif($progname eq "ip-up") { return(&ip_up); } elsif($progname eq "ip-down") { return(&ip_down); @ 1.4 log @works but .... ppp-on progresses to C and calls pppd ppp-off state goes to PS-WAS-C pppd is still going ppp-on runs kill_pppd which doesn't die 'cos it's uninterruptable? ppp-on also moves onto state A @ text @d24 1 d32 1 a32 1 ($modvers{'thisprogram'} =~ /^M.*R$/) && ($modvers{'thisprogram'} = '$Id: ppp-on,v 1.3 1996/09/30 17:02:15 root Exp $') =~ s/^.*,v (\S+) .*$/$1/; d45 1 a45 1 local($newpid, $newstate, $getnews_flg) = @@_; d52 1 a52 1 print TMPLOCK_HANDLE join(' ', $newpid, $newstate, $getnews_flg), "\n"; d84 1 a84 1 ($oldpid, $oldstate, $getnews_flg) = split(/ /, $line); d87 1 a87 1 print LOCK_HANDLE join(' ', $oldpid, $newstate, $getnews_flg), "\n"; d89 1 a89 1 &debug(10, "chgstate: write state mode: $oldstate --> $newstate"); d94 1 a94 1 ($oldpid, $oldstate, $getnews_flg) = split(/ /, $line); d97 1 a97 1 return($oldstate, $getnews_flg); d150 1 a150 1 sub getusecnt d152 9 a160 2 # local($iface) = @@_; local($totalusecnt) = 0; d162 2 a163 11 # open(PROCNETDEV_HANDLE, "/proc/net/route") || &error("can't open /proc/net/route: $!"); # while () { # if (/^(ppp0.*)\n$/) { # &debug(10, "getusecnt: use count is $1"); # $totalusecnt += $1; # } # } # close PROCNETDEV_HANDLE; $totalusecnt = int(rand(6) + 1); &debug(10, "getusecnt: total use $totalusecnt"); return($totalusecnt); d175 1 a175 1 if (($rc = &chgstate($$, "C", $getnews_flg)) > 0) { d217 8 d227 1 a227 1 if ($last_use_count != ($this_use_count = &getusecnt("ppp0"))) { a231 3 &debug(10, "ppp_on: timeout: idle_start_time $idle_start_time"); &debug(10, "ppp_on: timeout: time " . time); &debug(10, "ppp_on: timeout: max interval $max_idle_interval"); a239 4 } elsif ($state eq "PA-WAS-C") { kill 15, $pppd_pid; &debug(10, "ppp_on: state is $state, moving to state A"); &chgstate(0, "A", 0); d243 1 a243 1 &internal(1, "S $state"); d246 1 a246 2 #sleep 3600; sleep 1; d258 2 a259 1 local($state) = &chgstate(0, 0, 0); d276 3 d280 1 a280 1 &internal(2, "S $state"); d304 1 a304 1 &chgstate(0, "PA-WAS-C", 0); d307 2 d312 1 a312 1 &internal(3, "S $state"); d350 1 a350 1 &internal(4, "S $state"); d364 3 a366 1 local($state, $getnews_flg) = &chgstate(0, 0, 0); d370 3 a372 1 if ($state eq "PA-WAS-C") { d377 1 a377 1 &internal(5, "S $state"); d403 1 a403 1 &internal(6, "S $state"); @ 1.3 log @new version / @ text @d5 2 a6 2 $localpl_dir = "/home/alexis/dev/newincp"; $lock_file = "/tmp/lockfile"; d22 2 a23 2 $max_idle_interval = 90; $idle_check_interval = 10; d31 1 a31 1 ($modvers{'thisprogram'} =~ /^M.*R$/) && ($modvers{'thisprogram'} = '$Id: ppp-on,v 1.2 1996/09/30 08:35:29 root Exp root $') =~ s/^.*,v (\S+) .*$/$1/; d38 1 a38 1 ($modvers{'msgs.pl'} ne "1.6") && (!$ENV{'FADIGNMODVERS'}) && &error("configuration error: wrong version of msgs.pl"); d186 1 a186 1 $SIG{'INT'} = 'sub2'; d204 3 a206 1 while ((($state) = &chgstate(0, 0, 0)) ne "A" && $state ne "D") { d208 2 a209 2 if ($state eq "C" && -d "/proc/$pppd_pid") { &debug(10, "ppp_on: pppd[$pppd_pid] is running"); d211 7 a217 3 &info("restarting pppd"); $pppd_pid = &bg_pppd; &debug(10, "ppp_on: pppd[$pppd_pid] started"); d240 2 d243 1 a243 1 kill 15, $pppd_pid; d245 5 a249 2 sleep 3600; &debug(10, "ppp_on: probably woke up for something"); d277 1 a277 1 &internal(1, "S $state"); d307 1 a307 1 &internal(2, "S $state"); d345 1 a345 1 &internal(5, "S $state"); d365 4 a368 2 } elsif ($state ne "C") { &internal(3, "S $state"); d386 9 a394 8 } elsif ($state ne "UC") { &debug(10, "ip_up: strange state"); &internal(4, "S $state"); } elsif ($linequality < 90) { &debug(10, "ip_up: bad quality"); &chgstate(0, "PR-BADQ", 0); &wake_ppp_on; exit(0); @ 1.2 log @new revision - this works, but may have an incomplete edit in it. @ text @d1 1 a1 1 #!/usr/bin/perl4.036 -w d21 2 a22 2 $verboselevel = 5; $max_idle_interval = 180; d31 1 a31 1 ($modvers{'thisprogram'} =~ /^M.*R$/) && ($modvers{'thisprogram'} = '$Id: ppp-on,v 1.1 1996/09/29 22:54:37 alexis Exp $') =~ s/^.*,v (\S+) .*$/$1/; d44 1 a44 1 local($newpid, $newstate) = @@_; d51 1 a51 1 print TMPLOCK_HANDLE "$$ $newstate\n"; d54 1 a54 1 &debug(5, "chgstate: locked"); a59 1 &debug(5, "lock file says pid $holding_pid has it"); d62 1 a62 1 &debug(5, "already locked by $holding_pid"); d68 1 a68 1 &debug(5, "chgstate: stale lock removed, now locked"); d73 2 d76 1 a76 1 &debug(5, "chgstate: unlocking"); d79 11 d92 2 a93 1 ($oldpid, $oldstate) = ( =~ /^([0-9]+) (.*)$/); d95 2 a96 10 if (defined $newstate) { open(LOCK_HANDLE, ">$lock_file") || &error("can't write lock file: $!"); print LOCK_HANDLE "$oldpid $newstate\n"; &debug(5, "chgstate: wrote state $newstate"); close LOCK_HANDLE; return(0); } else { &debug(5, "chgstate: read state $oldstate"); return($oldstate); } d109 1 a109 1 &debug(5, "bg_pppd: about to exec: $cmd_str"); d120 1 d127 1 d133 1 a133 1 &debug(5, "ppp_on: woken"); d138 4 a141 2 # &info("got INT\n"); $SIG{'INT'} = 'sub2'; d143 1 a144 1 # &info("waiting for pppd to die\n"); d151 2 a152 2 local($iface) = @@_; local($usecnt,$totalusecnt) = (0,0); d154 10 a163 8 open(PROCNETDEV_HANDLE, "/proc/net/route") || &error("can't open /proc/net/route: $!"); while () { ($usecnt) = /^ppp0\s+\w+\s+\d+\s+\d+\s+\d+\s+(\d+)\s+\d+\s+\w+\s+\d+\s+\d+\s+\d+\s*$/; $totalusecnt += $usecnt; # &debug(5, "getusecnt: read use $usecnt"); } close PROCNETDEV_HANDLE; &debug(5, "getusecnt: total use $totalusecnt"); d171 6 a176 1 if (($rc = &chgstate($$, "C")) > 0) { d186 2 a187 1 # $SIG{'INT'} = 'sub2'; d189 11 a199 7 &debug(5, "calling newsrunning"); system("su - news -c \"$newsrunning_cmd on\""); &debug(5, "newsrunning done"); &debug(5, "calling newsrun"); system("su - news -c $newsrun_cmd"); &debug(5, "newsrun done"); d204 2 a205 2 while (($state = &chgstate(0)) ne "A" && $state ne "D") { &debug(5, "ppp_on: state is $state"); d207 1 a207 1 &debug(5, "ppp_on: pppd[$pppd_pid] is running"); d209 1 a209 1 &debug(5, "ppp_on: pppd[$pppd_pid] is not running, restarting"); d211 1 a211 1 &debug(5, "ppp_on: pppd[$pppd_pid] started"); d213 16 a228 12 if ($last_use_count != ($this_use_count = &getusecnt("ppp0"))) { $idle_start_time = time; &debug(5, "ppp_on: interface in use"); $last_use_count = $this_use_count; } elsif (time - $idle_start_time > $max_idle_interval) { &debug(5, "timeout: idle_start_time $idle_start_time"); &debug(5, "timeout: time " . time); &debug(5, "timeout: max interval $max_idle_interval"); &chgstate(0, "PD-IDLE"); kill 15, $pppd_pid; } else { &debug(5, "idle time rising"); a229 1 alarm($idle_check_interval); d232 2 a233 2 &debug(5, "ppp_on: state is $state, moving to state A"); &chgstate(0, "A"); d238 1 a238 1 &debug(5, "ppp_on: probably woke up for something"); d240 2 a241 1 &debug(5, "ppp_on: state is $state, exiting"); d247 2 a248 1 local($state) = &chgstate(0); d250 1 a250 1 &debug(5, "ip_down: state is $state"); d254 1 a254 1 &chgstate(0, "D"); d257 1 a257 1 &chgstate(0, "D"); d260 1 a260 1 &chgstate(0, "C"); d262 1 a262 1 &chgstate(0, "A"); d264 1 a264 1 &chgstate(0, "C"); d266 1 a266 1 &internal("ip_down: strange state: $state"); d273 1 a273 1 &debug(5, "wake_ppp_on: waking ppp_on"); d276 1 a276 1 kill 'USR1', &chgstate(99999, "BADSTATE"); d281 3 a283 1 local($state) = &chgstate(0); d285 1 a285 1 &debug(5, "ppp_off: state is $state"); d288 1 a288 1 &chgstate(0, "PD-USERREQ"); d290 1 a290 1 &chgstate(0, "PA-WAS-C"); d292 5 a296 3 &chgstate(0, "PA-WAS-UC"); } elsif ($state eq "C") { &internal("ppp_off: strange state: $state"); d301 1 a301 1 sub redial d303 1 a303 1 local($state) = &chgstate(0); d305 22 a326 1 &debug(5, "redial: state is $state"); d329 1 a329 1 &chgstate(0, "PR-USERREQ"); d331 2 d334 1 a334 1 &error("no point in redialling, we're not connected yet"); d340 1 a340 1 &debug(5, "getlinequality: checking line"); d347 2 a348 1 local($state) = &chgstate(0); d350 1 a350 1 &debug(5, "ip_up: state is $state"); d355 1 a355 1 &internal("ip_up: strange state: $state"); d358 1 a358 1 &chgstate(0, "UC"); d360 1 a360 1 &debug(5, "now unofficially connected"); d366 1 a366 1 &debug(5, "quality check"); d369 1 a369 1 $state = &chgstate(0); d371 1 a371 1 &debug(5, "spotted that we have been asked to abandon"); d374 2 a375 2 &debug(5, "ip_up: strange state"); &internal("ip_up: strange state: $state"); d377 2 a378 2 &debug(5, "ip_up: bad quality"); &chgstate(0, "PR-BADQ"); d384 1 a384 1 &chgstate(0, "OC"); d386 1 a386 1 &debug(5, "now officially connected"); d389 1 a389 1 &debug(5, "running sendmail"); d391 1 a391 1 &debug(5, "sendmail in background"); d393 27 a419 26 &debug(5, "calling newsrunning"); system("su - news -c \"$newsrunning_cmd off\""); &debug(5, "newsrunning done"); &debug(5, "calling xmitnews"); system("su - news -c \"$xmitnews_cmd -d -h $nntp_server -f /var/spool/news/out.going/$nntp_server/togo\""); &debug(5, "xmitnews done"); # fix kacky file &debug(5, "fixing kacky file"); truncate("/usr/local/lib/nntp/slurp.news.demon.co.uk", 14); &debug(5, "kacky file fixed"); do { &debug(5, "retrieving new news articles"); $rc = system("su - news -c \"$slurp_cmd -d $nntp_server\"") / 256; &debug(5, "new news articles retrieved"); } until ($rc == 0); &debug(5, "calling newsrunning"); system("su - news -c \"$newsrunning_cmd on\""); &debug(5, "newsrunning done"); &debug(5, "calling newsrun"); system("su - news -c $newsrun_cmd"); &debug(5, "newsrun done"); d421 6 a426 3 &debug(5, "calling nnmaster"); system("su - news -c $nnmaster_cmd"); &debug(5, "nnmaster done"); a450 1 &debug(5, "main: processing options"); d474 8 d489 2 a490 2 $SIG{'INT'} = 'sighandler'; $SIG{'TERM'} = 'sighandler'; d500 4 d512 1 a512 1 &debug(5, "exiting with return code $rc"); @ 1.1 log @Initial revision @ text @d22 3 a24 1 $max_idle_interval = 60; d31 1 a31 1 ($modvers{'thisprogram'} =~ /^M.*R$/) && ($modvers{'thisprogram'} = '$Id$') =~ s/^.*,v (\S+) .*$/$1/; a47 6 if (defined $newstate) { &debug(5, "chgstate: passed: Pid: $newpid, State: $newstate"); } else { &debug(5, "chgstate: passed: Pid: $newpid, State: none"); } d60 1 a81 1 &debug(5, "chgstate: in file Pid: $oldpid, State: $oldstate"); d85 1 d87 1 d89 1 d118 11 d143 1 d145 5 a149 3 open(PROCNETDEV_HANDLE, "/proc/net/dev"); while (!( =~ /^\s*$iface:\s+(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s*/)) { ; d152 2 a153 2 &debug(5, "getusecnt: Rx: $1, Tx: $2"); return($1 + $2); d168 2 a191 1 &debug(5, "ppp_on: pppd[$pppd_pid] is in state $state, no action necessary"); d194 1 a194 1 &debug(5, "use count has gone up, time is $idle_start_time"); d197 3 a199 1 &debug(5, "$max idle ($max_idle_interval) exceeded"); d205 1 d213 2 a214 1 sleep(5); d242 9 d268 1 d279 1 d287 2 d305 1 d312 1 d317 1 d320 1 d323 1 d325 1 d331 1 d408 8 @