xref: /illumos-gate/usr/src/lib/libdscp/svc/svc-dscp (revision 0b05a701b49058a6d47b581827961c6c39b1071a)
125cf1a30Sjl139090#!/bin/sh
225cf1a30Sjl139090#
325cf1a30Sjl139090# CDDL HEADER START
425cf1a30Sjl139090#
525cf1a30Sjl139090# The contents of this file are subject to the terms of the
625cf1a30Sjl139090# Common Development and Distribution License (the "License").
725cf1a30Sjl139090# You may not use this file except in compliance with the License.
825cf1a30Sjl139090#
925cf1a30Sjl139090# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1025cf1a30Sjl139090# or http://www.opensolaris.org/os/licensing.
1125cf1a30Sjl139090# See the License for the specific language governing permissions
1225cf1a30Sjl139090# and limitations under the License.
1325cf1a30Sjl139090#
1425cf1a30Sjl139090# When distributing Covered Code, include this CDDL HEADER in each
1525cf1a30Sjl139090# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1625cf1a30Sjl139090# If applicable, add the following below this CDDL HEADER, with the
1725cf1a30Sjl139090# fields enclosed by brackets "[]" replaced with your own identifying
1825cf1a30Sjl139090# information: Portions Copyright [yyyy] [name of copyright owner]
1925cf1a30Sjl139090#
2025cf1a30Sjl139090# CDDL HEADER END
2125cf1a30Sjl139090#
2225cf1a30Sjl139090#
2325cf1a30Sjl139090# Copyright 2006 Sun Microsystems, Inc.	 All rights reserved.
2425cf1a30Sjl139090# Use is subject to license terms.
2525cf1a30Sjl139090#
2625cf1a30Sjl139090# ident	"%Z%%M%	%I%	%E% SMI"
2725cf1a30Sjl139090#
2825cf1a30Sjl139090
2925cf1a30Sjl139090#
3025cf1a30Sjl139090# Start script for the SPARC-Enterprise DSCP service.
3125cf1a30Sjl139090#
3225cf1a30Sjl139090
3325cf1a30Sjl139090. /lib/svc/share/smf_include.sh
3425cf1a30Sjl139090
3525cf1a30Sjl139090OPL=SUNW,SPARC-Enterprise
3625cf1a30Sjl139090OPL_LIB=/usr/platform/${OPL}/lib
3725cf1a30Sjl139090DM2S_DEVICE=/dev/dm2s0
3825cf1a30Sjl139090PPP_OPTIONS=${OPL_LIB}/dscp.ppp.options
3925cf1a30Sjl139090DSCP_IFNAME=/var/run/dscp.ifname
4025cf1a30Sjl139090PRTDSCP=/usr/platform/${OPL}/sbin/prtdscp
4125cf1a30Sjl139090PLATFORM=`/sbin/uname -i`
4225cf1a30Sjl139090SLEEP=/bin/sleep
4325cf1a30Sjl139090PKILL=/bin/pkill
4425cf1a30Sjl139090
4525cf1a30Sjl139090LD_LIBRARY_PATH=/lib:${OPL_LIB}; export LD_LIBRARY_PATH
4625cf1a30Sjl139090
4725cf1a30Sjl139090# This service can only run on OPL.
48*0b05a701Smcwalterif  [ "${PLATFORM}" != "${OPL}" ]; then
4925cf1a30Sjl139090	exit $SMF_EXIT_ERR_CONFIG
5025cf1a30Sjl139090fi
5125cf1a30Sjl139090
5225cf1a30Sjl139090case "$1" in
5325cf1a30Sjl139090'start')
5425cf1a30Sjl139090
5525cf1a30Sjl139090	if [ ! -x /usr/bin/pppd ]; then
5625cf1a30Sjl139090		exit $SMF_EXIT_ERR_CONFIG
5725cf1a30Sjl139090	fi
5825cf1a30Sjl139090
5925cf1a30Sjl139090	if [ ! -c $DM2S_DEVICE ]; then
6025cf1a30Sjl139090		exit $SMF_EXIT_ERR_CONFIG
6125cf1a30Sjl139090	fi
6225cf1a30Sjl139090
6325cf1a30Sjl139090	if [ ! -f $PPP_OPTIONS ]; then
6425cf1a30Sjl139090		exit $SMF_EXIT_ERR_CONFIG
6525cf1a30Sjl139090	fi
6625cf1a30Sjl139090
6725cf1a30Sjl139090	SUCCESS=0
6825cf1a30Sjl139090	for UNIT in 0 1 2 3 4 5 6 7 8 9; do
6925cf1a30Sjl139090		/usr/bin/pppd $DM2S_DEVICE unit $UNIT file $PPP_OPTIONS
7025cf1a30Sjl139090		if [ ! "$?" = "1" ]; then
7125cf1a30Sjl139090			echo "sppp$UNIT" > $DSCP_IFNAME
7225cf1a30Sjl139090			SUCCESS=1
7325cf1a30Sjl139090			break
7425cf1a30Sjl139090		fi
7525cf1a30Sjl139090	done
7625cf1a30Sjl139090
7725cf1a30Sjl139090	if [ $SUCCESS -ne 1 ]; then
7825cf1a30Sjl139090		exit $SMF_EXIT_ERR_FATAL
7925cf1a30Sjl139090	fi
8025cf1a30Sjl139090
8125cf1a30Sjl139090	# Wait for the DSCP link to come up, but only for 30 seconds
8225cf1a30Sjl139090	for RETRY in 0 1 2 3 4 5; do
8325cf1a30Sjl139090		${PRTDSCP} >/dev/null 2>&1
8425cf1a30Sjl139090		if [ $? -eq 0 ]; then
8525cf1a30Sjl139090			exit $SMF_EXIT_OK
8625cf1a30Sjl139090		fi
8725cf1a30Sjl139090		${SLEEP} 5
8825cf1a30Sjl139090	done
8925cf1a30Sjl139090
9025cf1a30Sjl139090	# Stop pppd before we return failure
9125cf1a30Sjl139090	${PKILL} -TERM -f "pppd ${DM2S_DEVICE}"
9225cf1a30Sjl139090	${SLEEP} 1
9325cf1a30Sjl139090	${PKILL} -KILL -f "pppd ${DM2S_DEVICE}"
9425cf1a30Sjl139090	rm -f $DSCP_IFNAME
9525cf1a30Sjl139090	exit $SMF_EXIT_ERR_FATAL
9625cf1a30Sjl139090	;;
9725cf1a30Sjl139090
9825cf1a30Sjl139090'stop')
9925cf1a30Sjl139090	# First try SIGTERM and then SIGKILL
10025cf1a30Sjl139090	${PKILL} -TERM -f "pppd ${DM2S_DEVICE}"
10125cf1a30Sjl139090	${SLEEP} 1
10225cf1a30Sjl139090	${PKILL} -KILL -f "pppd ${DM2S_DEVICE}"
10325cf1a30Sjl139090	rm -f $DSCP_IFNAME
10425cf1a30Sjl139090	exit $SMF_EXIT_OK
10525cf1a30Sjl139090	;;
10625cf1a30Sjl139090esac
107