From owner-svn-src-all@FreeBSD.ORG Sun Jun 19 22:59:55 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 29DDD1065672; Sun, 19 Jun 2011 22:59:55 +0000 (UTC) (envelope-from dougb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 00CBE8FC0A; Sun, 19 Jun 2011 22:59:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p5JMxsxd013081; Sun, 19 Jun 2011 22:59:54 GMT (envelope-from dougb@svn.freebsd.org) Received: (from dougb@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p5JMxsBS013080; Sun, 19 Jun 2011 22:59:54 GMT (envelope-from dougb@svn.freebsd.org) Message-Id: <201106192259.p5JMxsBS013080@svn.freebsd.org> From: Doug Barton Date: Sun, 19 Jun 2011 22:59:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r223311 - head/etc/rc.d X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Jun 2011 22:59:55 -0000 Author: dougb Date: Sun Jun 19 22:59:54 2011 New Revision: 223311 URL: http://svn.freebsd.org/changeset/base/223311 Log: Blah, forgot to svn add the actual script from r223310 Added: head/etc/rc.d/netwait (contents, props changed) Added: head/etc/rc.d/netwait ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/etc/rc.d/netwait Sun Jun 19 22:59:54 2011 (r223311) @@ -0,0 +1,97 @@ +#!/bin/sh + +# $FreeBSD$ +# +# PROVIDE: netwait +# REQUIRE: NETWORKING +# KEYWORD: nojail +# +# The netwait script is intended to be used by systems which have +# statically-configured IP addresses in rc.conf(5). If your system +# uses DHCP, you should use synchronous_dhclient="YES" in your +# /etc/rc.conf instead of using netwait. + +. /etc/rc.subr + +name="netwait" +rc_var=`set_rcvar` +start_cmd="${name}_start" +stop_cmd=":" + +netwait_start() +{ + local ip rc count output link + + if [ -z "${netwait_ip}" ]; then + err 1 "You must define one or more IP addresses in netwait_ip" + fi + + if [ ${netwait_timeout} -lt 1 ]; then + err 1 "netwait_timeout must be >= 1" + fi + + # Handle SIGINT (Ctrl-C); force abort of while() loop + trap break SIGINT + + if [ -n "${netwait_if}" ]; then + echo -n "Waiting for $netwait_if to have link" + + count=1 + while [ ${count} -le ${netwait_if_timeout} ]; do + if output=`/sbin/ifconfig ${netwait_if} 2>/dev/null`; then + link=`expr "${output}" : '.*[[:blank:]]status: \(no carrier\)'` + if [ -z "${link}" ]; then + echo '.' + break + fi + else + echo '' + err 1 "ifconfig ${netwait_if} failed" + fi + sleep 1 + count=$((count+1)) + done + if [ -n "${link}" ]; then + # Restore default SIGINT handler + trap - SIGINT + + echo '' + warn "Interface still has no link. Continuing with startup, but" + warn "be aware you may not have a fully functional networking" + warn "layer at this point." + return + fi + fi + + # Handle SIGINT (Ctrl-C); force abort of while() loop + trap break SIGINT + + for ip in ${netwait_ip}; do + echo -n "Waiting for ${ip} to respond to ICMP" + + count=1 + while [ ${count} -le ${netwait_timeout} ]; do + /sbin/ping -t 1 -c 1 -o ${ip} >/dev/null 2>&1 + rc=$? + + if [ $rc -eq 0 ]; then + # Restore default SIGINT handler + trap - SIGINT + + echo '.' + return + fi + count=$((count+1)) + done + echo ': No response from host.' + done + + # Restore default SIGINT handler + trap - SIGINT + + warn "Exhausted IP list. Continuing with startup, but be aware you may" + warn "not have a fully functional networking layer at this point." +} + +load_rc_config $name +run_rc_command "$1"