lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # $Id: poff,v 1.1 2002/11/24 23:30:44 etbe Exp $ |
| 4 | # Written by John Hasler <john@dhh.gt.org> and based on work |
| 5 | # by Phil Hands <phil@hands.com>. Distributed under the GNU GPL |
| 6 | |
| 7 | if [ -x /usr/bin/kill ]; then |
| 8 | KILL="/usr/bin/kill" |
| 9 | else |
| 10 | KILL="/bin/kill" |
| 11 | fi |
| 12 | SIG=TERM |
| 13 | DONE="stopped" |
| 14 | MODE="" |
| 15 | |
| 16 | usage () |
| 17 | { |
| 18 | cat <<!EOF! |
| 19 | usage: $0 [option] [provider] |
| 20 | options: |
| 21 | -r Cause pppd to drop the line and redial. |
| 22 | -d Toggle the state of pppd's debug option. |
| 23 | -c Cause pppd to renegotiate compression. |
| 24 | -a Stop all pppd's. 'provider' will be ignored. |
| 25 | -h Print this help summary and exit. |
| 26 | -v Print version and exit. |
| 27 | none Stop pppd. |
| 28 | |
| 29 | Options may not be combined. |
| 30 | |
| 31 | If 'provider' is omitted pppd will be stopped or signalled if and only if |
| 32 | there is exactly one running unless the '-a' option was given. If |
| 33 | 'provider' is supplied the pppd controlling the connection to that |
| 34 | provider will be stopped or signalled. |
| 35 | !EOF! |
| 36 | } |
| 37 | |
| 38 | # Get option. If there are none replace the "?" that getopts puts in |
| 39 | # FLAG on error with "null". |
| 40 | getopts rdcavh FLAG |
| 41 | if [ "$?" -ne 0 ]; then |
| 42 | FLAG="null" |
| 43 | fi |
| 44 | |
| 45 | # Check for additional options. Should be none. |
| 46 | getopts :rdcavh DUMMY |
| 47 | if [ "$?" -eq 0 ]; then |
| 48 | echo "$0: Illegal option -- ${OPTARG}." |
| 49 | exit 1 |
| 50 | fi |
| 51 | |
| 52 | case $FLAG in |
| 53 | "r") SIG=HUP; DONE=signalled; shift ;; |
| 54 | "d") SIG=USR1; DONE=signalled; shift ;; |
| 55 | "c") SIG=USR2; DONE=signalled; shift ;; |
| 56 | "a") MODE="all"; shift ;; |
| 57 | "v") echo "$0$Revision: 1.1 $_TrickToPrint_RCS_Revision"; exit 0 ;; |
| 58 | "h") usage; exit 0 ;; |
| 59 | "?") exit 1; |
| 60 | esac |
| 61 | |
| 62 | # Get the PIDs of all the pppds running. Could also get these from |
| 63 | # /var/run, but pppd doesn't create .pid files until ppp is up. |
| 64 | PIDS=`pidof pppd` |
| 65 | |
| 66 | # poff is pointless if pppd isn't running. |
| 67 | if test -z "$PIDS"; then |
| 68 | echo "$0: No pppd is running. None ${DONE}." |
| 69 | exit 1 |
| 70 | fi |
| 71 | |
| 72 | # Find out how many pppd's are running. |
| 73 | N=`echo "$PIDS" | wc -w` |
| 74 | |
| 75 | # If there are no arguments we can't do anything if there is more than one |
| 76 | # pppd running. |
| 77 | if test "$#" -eq 0 -a "$N" -gt 1 -a $FLAG != "a" ; then |
| 78 | echo "$0: More than one pppd running and no "-a" option and |
| 79 | no arguments supplied. Nothing ${DONE}." |
| 80 | exit 1 |
| 81 | fi |
| 82 | |
| 83 | # If either there are no arguments or '-a' was specified kill all the |
| 84 | # pppd's. |
| 85 | if test "$#" -eq 0 -o "$MODE" = "all" ; then |
| 86 | $KILL -$SIG $PIDS || { |
| 87 | echo "$0: $KILL failed. None ${DONE}." |
| 88 | exit 1 |
| 89 | } |
| 90 | exit 0 |
| 91 | fi |
| 92 | |
| 93 | # There is an argument, so kill the pppd started on that provider. |
xf.li | 8402749 | 2024-04-09 00:17:51 -0700 | [diff] [blame^] | 94 | PID=`ps axw | grep "[ /]pppd call $1" | grep -w "$1" | awk '{print $1}'` |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 95 | if test -n "$PID" ; then |
| 96 | $KILL -$SIG $PID || { |
| 97 | echo "$0: $KILL failed. None ${DONE}." |
| 98 | exit 1 |
| 99 | } |
| 100 | else |
| 101 | echo "$0: I could not find a pppd process for provider '$1'. None ${DONE}." |
| 102 | exit 1 |
| 103 | fi |
| 104 | exit 0 |