17c478bd9Sstevel@tonic-gate#!/sbin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*6927f468Sdp# Common Development and Distribution License (the "License").
7*6927f468Sdp# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
237c478bd9Sstevel@tonic-gate# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
247c478bd9Sstevel@tonic-gate# All rights reserved.
257c478bd9Sstevel@tonic-gate#
267c478bd9Sstevel@tonic-gate#
27*6927f468Sdp# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
287c478bd9Sstevel@tonic-gate# Use is subject to license terms.
297c478bd9Sstevel@tonic-gate#
307c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate. /lib/svc/share/smf_include.sh
337c478bd9Sstevel@tonic-gate. /lib/svc/share/net_include.sh
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate# Make sure that the libraries essential to this stage of booting can be found.
367c478bd9Sstevel@tonic-gateLD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate#
397c478bd9Sstevel@tonic-gate# If DHCP was used on a primary interface then set the hostname
407c478bd9Sstevel@tonic-gate# that was returned. If no hostname was returned, set the name
417c478bd9Sstevel@tonic-gate# to be "unknown". The hostname must be set to something, because
427c478bd9Sstevel@tonic-gate# tooltalk will hang unless the name can be locally resolved.
437c478bd9Sstevel@tonic-gate# Sendmail also requires the name to be resolvable locally.
447c478bd9Sstevel@tonic-gate# Later, in inetsvc, we create a name "unknown" and create a entry
457c478bd9Sstevel@tonic-gate# in the local /etc/inet/hosts file pairing "unknown" with the IP
467c478bd9Sstevel@tonic-gate# address assigned by DHCP.  The use of bootparams as a fallback
477c478bd9Sstevel@tonic-gate# for all non-DHCP cases provides compatibility with the
487c478bd9Sstevel@tonic-gate# behavior of the system before netstrategy was introduced.
497c478bd9Sstevel@tonic-gate#
507c478bd9Sstevel@tonic-gate# For non-global zones, fall back to the `uname -n` value provided by the
517c478bd9Sstevel@tonic-gate# kernel if /etc/nodename does not exist, as is expected on an initial boot.
527c478bd9Sstevel@tonic-gate#
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gatesmf_netstrategy
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gatecase "$_INIT_NET_STRATEGY" in
577c478bd9Sstevel@tonic-gate	"dhcp") hostname=`/sbin/dhcpinfo Hostname` ;;
587c478bd9Sstevel@tonic-gate	"rarp") hostname=`/sbin/hostconfig -h -p bootparams`
597c478bd9Sstevel@tonic-gate		trap 'intr=1' 2 3
607c478bd9Sstevel@tonic-gate		while [ -z "$hostname" -a ! -f /etc/.UNCONFIGURED -a \
617c478bd9Sstevel@tonic-gate		    -z "$intr" ]; do
627c478bd9Sstevel@tonic-gate			echo "re-trying host configuration..."
637c478bd9Sstevel@tonic-gate			# Restrict this to IPv4 interfaces.
647c478bd9Sstevel@tonic-gate			/sbin/ifconfig -adD4 auto-revarp up
657c478bd9Sstevel@tonic-gate			hostname=`/sbin/hostconfig -h -p bootparams`
667c478bd9Sstevel@tonic-gate		done
677c478bd9Sstevel@tonic-gate		trap 2 3 ;;
687c478bd9Sstevel@tonic-gate	"none") hostname="`shcat /etc/nodename 2>/dev/null`"
697c478bd9Sstevel@tonic-gate       		if [ -z "$hostname" ]; then
70*6927f468Sdp			if smf_is_globalzone; then
717c478bd9Sstevel@tonic-gate				hostname=`/sbin/hostconfig -h -p bootparams`
727c478bd9Sstevel@tonic-gate			else
737c478bd9Sstevel@tonic-gate				hostname=`/sbin/uname -n`
747c478bd9Sstevel@tonic-gate			fi
757c478bd9Sstevel@tonic-gate		fi ;;
767c478bd9Sstevel@tonic-gateesac
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate#
797c478bd9Sstevel@tonic-gate# If the netstrategy was unsuccessful and we haven't got a locally configured
807c478bd9Sstevel@tonic-gate# name, default to "unknown"
817c478bd9Sstevel@tonic-gate#
827c478bd9Sstevel@tonic-gateif [ -z "$hostname" ]; then
837c478bd9Sstevel@tonic-gate	hostname="`shcat /etc/nodename 2>/dev/null`"
847c478bd9Sstevel@tonic-gate	if [ -z "$hostname" ]; then
857c478bd9Sstevel@tonic-gate		hostname="unknown"
867c478bd9Sstevel@tonic-gate	fi
877c478bd9Sstevel@tonic-gatefi
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate/sbin/uname -S $hostname
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gateecho "Hostname: `/sbin/uname -n`" > /dev/msglog
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate# Reset the library path now that we are past the critical stage
947c478bd9Sstevel@tonic-gateunset LD_LIBRARY_PATH
95*6927f468Sdp
96*6927f468Sdpexit $SMF_EXIT_OK
97