Subject: Re: pppd & tail show PID after ppp-down
To: None <netbsd-help@netbsd.org>
From: James K. Lowden <jklowden@schemamania.org>
List: netbsd-help
Date: 10/15/2001 23:29:15
On Mon, Oct 15, 2001 at 07:02:50AM -0400, Gan Uesli Starling wrote:
> I use /etc/ppp/ppp-up and /etc/ppp/ppp-down from The NetBSD Guide by F. Lupi. 
> And all the while I was iterating the process, after calling ppp-down, the 
> link would fall (as expected) but on the next calling of ppp-up the on-screen 
> messages from command "tail" in the ppp-up script would multiply.
> 
> When I explored this I noted that command "ps" would show PID's for ppp-up 
> and tail both even after running ppp-down.
> 
> Now the PPP link had gone down. I see the lights go off on the dial-in box 
> right beside it. But "tail" was obviously still running. 

Gan, 

You mean these scripts:

(http://www.mclink.it/personal/MG2508/nbsdeng/chap-net.html#AEN2153)

Example 9-7. ppp-up

  #!/bin/sh
  MODEM=tty01
  POP=bignet
  if [ -f /var/spool/lock/LCK..$MODEM ]; then
    echo ppp is already running...
  else
    pppd call $POP
    tail -f /var/log/messages
  fi
        
Example 9-8. ppp-down

  #!/bin/sh
  MODEM=tty01
  if [ -f /var/spool/lock/LCK..$MODEM ]; then
    echo -f killing pppd...
    kill -HUP `cat /var/spool/lock/LCK..$MODEM
    echo done
  else
    echo ppp is not active
  fi

+++

Oh dear, that doesn't look good, does it?  You're sending a SIGHUP to
the pppd pid, but never say boo to that "tail -f".  

To fix that, add the following line to ppp-down after the "kill -HUP":

ps -T |perl -ne'print `kill -HUP $1` if m!^(\d+) .+tail -f /var/log/messages!'

[never learned awk, you see]

That asks perl to look at each line of your ps output for
your tail command, locate the pid, and send a SIGHUP to it. 
The m!<stuff>! is a regular expression search; everything between the
!! pair is the regexp.  You may have to adjust it slightly if you
didn't copy & paste the script from the handbook.  

Or, you just remove the "tail -f", of course.  You can always look at
the message log yourself if something goes wrong. 

Comment: Does anyone else think `cat /var/spool/lock/LCK..$MODEM` is a
little over-complex compared to `cat /var/run/ppp0.pid`?  

Question: I think Gan's right to expect ppp-up to come to a
conclusion *somehow*.  But I'm a little new at this game.  How do I
recommend a change to the handbook?  Send-pr?

--jkl