xref: /titanic_50/usr/src/lib/libdscp/svc/svc-dscp (revision 25cf1a301a396c38e8adf52c15f537b80d2483f7)
1*25cf1a30Sjl139090#!/bin/sh
2*25cf1a30Sjl139090#
3*25cf1a30Sjl139090# CDDL HEADER START
4*25cf1a30Sjl139090#
5*25cf1a30Sjl139090# The contents of this file are subject to the terms of the
6*25cf1a30Sjl139090# Common Development and Distribution License (the "License").
7*25cf1a30Sjl139090# You may not use this file except in compliance with the License.
8*25cf1a30Sjl139090#
9*25cf1a30Sjl139090# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*25cf1a30Sjl139090# or http://www.opensolaris.org/os/licensing.
11*25cf1a30Sjl139090# See the License for the specific language governing permissions
12*25cf1a30Sjl139090# and limitations under the License.
13*25cf1a30Sjl139090#
14*25cf1a30Sjl139090# When distributing Covered Code, include this CDDL HEADER in each
15*25cf1a30Sjl139090# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*25cf1a30Sjl139090# If applicable, add the following below this CDDL HEADER, with the
17*25cf1a30Sjl139090# fields enclosed by brackets "[]" replaced with your own identifying
18*25cf1a30Sjl139090# information: Portions Copyright [yyyy] [name of copyright owner]
19*25cf1a30Sjl139090#
20*25cf1a30Sjl139090# CDDL HEADER END
21*25cf1a30Sjl139090#
22*25cf1a30Sjl139090#
23*25cf1a30Sjl139090# Copyright 2006 Sun Microsystems, Inc.	 All rights reserved.
24*25cf1a30Sjl139090# Use is subject to license terms.
25*25cf1a30Sjl139090#
26*25cf1a30Sjl139090# ident	"%Z%%M%	%I%	%E% SMI"
27*25cf1a30Sjl139090#
28*25cf1a30Sjl139090
29*25cf1a30Sjl139090#
30*25cf1a30Sjl139090# Start script for the SPARC-Enterprise DSCP service.
31*25cf1a30Sjl139090#
32*25cf1a30Sjl139090
33*25cf1a30Sjl139090. /lib/svc/share/smf_include.sh
34*25cf1a30Sjl139090
35*25cf1a30Sjl139090OPL=SUNW,SPARC-Enterprise
36*25cf1a30Sjl139090FJOPL=FJSV,SPARC-Enterprise
37*25cf1a30Sjl139090TMPOPL=SUNW,OPL-Enterprise
38*25cf1a30Sjl139090OPL_LIB=/usr/platform/${OPL}/lib
39*25cf1a30Sjl139090DM2S_DEVICE=/dev/dm2s0
40*25cf1a30Sjl139090PPP_OPTIONS=${OPL_LIB}/dscp.ppp.options
41*25cf1a30Sjl139090DSCP_IFNAME=/var/run/dscp.ifname
42*25cf1a30Sjl139090PRTDSCP=/usr/platform/${OPL}/sbin/prtdscp
43*25cf1a30Sjl139090PLATFORM=`/sbin/uname -i`
44*25cf1a30Sjl139090SLEEP=/bin/sleep
45*25cf1a30Sjl139090PKILL=/bin/pkill
46*25cf1a30Sjl139090
47*25cf1a30Sjl139090LD_LIBRARY_PATH=/lib:${OPL_LIB}; export LD_LIBRARY_PATH
48*25cf1a30Sjl139090
49*25cf1a30Sjl139090# This service can only run on OPL.
50*25cf1a30Sjl139090if  [ "${PLATFORM}" != "${OPL}" -a \
51*25cf1a30Sjl139090      "${PLATFORM}" != "${FJOPL}" -a \
52*25cf1a30Sjl139090      "${PLATFORM}" != "${TMPOPL}" ]; then
53*25cf1a30Sjl139090
54*25cf1a30Sjl139090	exit $SMF_EXIT_ERR_CONFIG
55*25cf1a30Sjl139090fi
56*25cf1a30Sjl139090
57*25cf1a30Sjl139090case "$1" in
58*25cf1a30Sjl139090'start')
59*25cf1a30Sjl139090
60*25cf1a30Sjl139090	if [ ! -x /usr/bin/pppd ]; then
61*25cf1a30Sjl139090		exit $SMF_EXIT_ERR_CONFIG
62*25cf1a30Sjl139090	fi
63*25cf1a30Sjl139090
64*25cf1a30Sjl139090	if [ ! -c $DM2S_DEVICE ]; then
65*25cf1a30Sjl139090		exit $SMF_EXIT_ERR_CONFIG
66*25cf1a30Sjl139090	fi
67*25cf1a30Sjl139090
68*25cf1a30Sjl139090	if [ ! -f $PPP_OPTIONS ]; then
69*25cf1a30Sjl139090		exit $SMF_EXIT_ERR_CONFIG
70*25cf1a30Sjl139090	fi
71*25cf1a30Sjl139090
72*25cf1a30Sjl139090	SUCCESS=0
73*25cf1a30Sjl139090	for UNIT in 0 1 2 3 4 5 6 7 8 9; do
74*25cf1a30Sjl139090		/usr/bin/pppd $DM2S_DEVICE unit $UNIT file $PPP_OPTIONS
75*25cf1a30Sjl139090		if [ ! "$?" = "1" ]; then
76*25cf1a30Sjl139090			echo "sppp$UNIT" > $DSCP_IFNAME
77*25cf1a30Sjl139090			SUCCESS=1
78*25cf1a30Sjl139090			break
79*25cf1a30Sjl139090		fi
80*25cf1a30Sjl139090	done
81*25cf1a30Sjl139090
82*25cf1a30Sjl139090	if [ $SUCCESS -ne 1 ]; then
83*25cf1a30Sjl139090		exit $SMF_EXIT_ERR_FATAL
84*25cf1a30Sjl139090	fi
85*25cf1a30Sjl139090
86*25cf1a30Sjl139090	# Wait for the DSCP link to come up, but only for 30 seconds
87*25cf1a30Sjl139090	for RETRY in 0 1 2 3 4 5; do
88*25cf1a30Sjl139090		${PRTDSCP} >/dev/null 2>&1
89*25cf1a30Sjl139090		if [ $? -eq 0 ]; then
90*25cf1a30Sjl139090			exit $SMF_EXIT_OK
91*25cf1a30Sjl139090		fi
92*25cf1a30Sjl139090		${SLEEP} 5
93*25cf1a30Sjl139090	done
94*25cf1a30Sjl139090
95*25cf1a30Sjl139090	# Stop pppd before we return failure
96*25cf1a30Sjl139090	${PKILL} -TERM -f "pppd ${DM2S_DEVICE}"
97*25cf1a30Sjl139090	${SLEEP} 1
98*25cf1a30Sjl139090	${PKILL} -KILL -f "pppd ${DM2S_DEVICE}"
99*25cf1a30Sjl139090	rm -f $DSCP_IFNAME
100*25cf1a30Sjl139090	exit $SMF_EXIT_ERR_FATAL
101*25cf1a30Sjl139090	;;
102*25cf1a30Sjl139090
103*25cf1a30Sjl139090'stop')
104*25cf1a30Sjl139090	# First try SIGTERM and then SIGKILL
105*25cf1a30Sjl139090	${PKILL} -TERM -f "pppd ${DM2S_DEVICE}"
106*25cf1a30Sjl139090	${SLEEP} 1
107*25cf1a30Sjl139090	${PKILL} -KILL -f "pppd ${DM2S_DEVICE}"
108*25cf1a30Sjl139090	rm -f $DSCP_IFNAME
109*25cf1a30Sjl139090	exit $SMF_EXIT_OK
110*25cf1a30Sjl139090	;;
111*25cf1a30Sjl139090esac
112