From owner-freebsd-rc@FreeBSD.ORG Mon Dec 26 09:52:50 2011 Return-Path: Delivered-To: freebsd-rc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BE8B61065680; Mon, 26 Dec 2011 09:52:50 +0000 (UTC) (envelope-from rea@codelabs.ru) Received: from 0.mx.codelabs.ru (0.mx.codelabs.ru [144.206.177.45]) by mx1.freebsd.org (Postfix) with ESMTP id D220E8FC13; Mon, 26 Dec 2011 09:52:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codelabs.ru; s=two; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=1zj2P/KialEkM6MZMF01nYmewc3C4h3cuiAUEo/QzKU=; b=FLQ3nPApb/jWB2vlmVh1Q/+RyH/J/dTHv+PeUhcDe26+GIv6XdkGcip2dkMqCW0ujck8AXMMpxjvHLvnjPgbzcmNyfOK7Kb5XFyn273NcZjib97vYTnUwaKBVhzVEt7Cf4MxdXZJPBFAAz6rOR62uLRKC3AVy+CVS8C65Q2ExgpFQK9tIIP6/UJGTke57WbNEkrOOJUvQPNiiWOgCH2RUjNzr2n4Dk7xPbesRFKf5gXYroC3+K0p6mcmY/Fx5PM7TyQIM+Vvm2TJ5ZLIwVeqlFdr4pZ4O/rC9dx8BAN8yfKBz33uIR8Pez7Fm68TWraq5NrtO1/FA3JfjmXu+Z+c3Q==; Received: from void.codelabs.ru (void.codelabs.ru [144.206.177.25]) by 0.mx.codelabs.ru with esmtpsa (TLSv1:AES256-SHA:256) id 1Rf7EG-000JwZ-Bw; Mon, 26 Dec 2011 12:52:24 +0300 Date: Mon, 26 Dec 2011 13:52:21 +0400 From: Eygene Ryabinkin To: Doug Barton Message-ID: References: <4EF6401E.3080902@FreeBSD.org> <20111224215649.GA12789@stack.nl> <4EF80CA7.3070303@FreeBSD.org> <4EF82E3B.6040601@FreeBSD.org> <4EF833B7.9040704@FreeBSD.org> <0A59E5CD-3598-41B0-A707-6C5185E80043@gmail.com> <4EF83A59.8080008@FreeBSD.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="+epxrXWOh++2HLjY" Content-Disposition: inline In-Reply-To: <4EF83A59.8080008@FreeBSD.org> Sender: rea@codelabs.ru Cc: Pyun Yong-Hyeon , d@delphij.net, Garrett Cooper , Gleb Smirnoff , freebsd-rc@freebsd.org Subject: Re: Annoying ERROR: 'wlan0' is not a DHCP-enabled interface X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Dec 2011 09:52:50 -0000 --+epxrXWOh++2HLjY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Mon, Dec 26, 2011 at 01:11:53AM -0800, Doug Barton wrote: > On 12/26/2011 01:02, Garrett Cooper wrote: > > $ svn log -r 226879=20 > > ------------------------------------------------------------------------ > > > >=20 > r226879 | rea | 2011-10-27 23:03:38 -0700 (Thu, 27 Oct 2011) | 10 lines > >=20 > > Fix handling of rc_force in /etc/rc.d/dhclient > >=20 > > Variable 'rc_force' is accessible only at the time of > > rc_run_command, so it can't be examined from the script's main code. > >=20 > > Spotted by: hrs Reviewed by: hrs, des Approved by: des MFC after: 2 > > weeks=20 > > ------------------------------------------------------------------------ > > > > It simply didn't exist before this change; before it was just a > > 'return 1', which is illegal outside of functions, amongst other > > things. > > Ok, so I think here is some of the source of the confusion: Unlikely that the confusion will come from my side: I know how return acts (it terminates the current context and returns to the caller) and how exit acts -- it just terminates the current process. Why can I substitute 'return 1' for 'err 1' in this case is explained below. > "The syntax of the return command is >=20 > return [exitstatus] >=20 > It terminates the current executional scope, returning from the previous > nested function, sourced script, or shell instance, in that order. The > return command is implemented as a special built-in command." >=20 > It's actually used often'ish in rc.d where exit cannot be. The whole story is the following one. My original fix, http://svnweb.freebsd.org/base/head/etc/rc.d/dhclient?r1=3D226345&r2=3D226= 464 has 'return 1' from the top-level scope of dhclient script. At this scope it is just equal to 'exit 1', unless someone does ". /etc/rc.d/dhclie= nt" as /etc/rc used to do. But current version of run_rc_script does not source the scripts that aren't ended in .sh, but spawns the subprocess for each on= e. Moreover, script names ending in .sh are currently deprecated inside rc.sub= r. So, for this case 'return 1' =3D=3D 'exit 1': {{{ $ sh -x 1.sh || echo "failed" + trap 'echo Going away' 0 + return 1 + echo Going away Going away failed $ sh -x 2.sh || echo "failed" + trap 'echo Going away' 0 + exit 1 + echo Going away Going away failed }}} But r226464 wasn't good enough, because rc_force is set only when the rc.d command hooks are executed, thus it isn't set on the top-level context of rc.d scripts. So there goes r226879, http://svnweb.freebsd.org/base/head/etc/rc.d/dhclient?r1=3D226464&r2=3D22= 6879 that introduced dhclient_pre_check _and_ the "err" call we're arguing about. Here the historical retrospection ends. > > So I vote to just remove the message (convert the err 1 to a exit 1) >=20 > I haven't dug into it yet, but if it was a return previously it almost > certainly should not be an exit now. Doug, I may be blunt now, but how can one ever say something about the code that he hasn't digged into? I know about the common sense, but it alone can't be applied to the non-trivial problems with any hope for good results. > I'll dig into the original change more tomorrow, now that it's clear > what we're actually dealing with. Very good, thanks a lot! > Thanks to both of you for helping to make it clear. My pleasure ;)) --=20 Eygene Ryabinkin ,,,^..^,,, [ Life's unfair - but root password helps! | codelabs.ru ] [ 82FE 06BC D497 C0DE 49EC 4FF0 16AF 9EAE 8152 ECFB | freebsd.org ] --+epxrXWOh++2HLjY Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (FreeBSD) iF4EAREIAAYFAk74Q9UACgkQFq+eroFS7PvOQAEAjd1oAqK8e6jyz8Ssx5UTWfbm aNX/O1Xat1a53UItDlwA/3htbnQdQ0CZ1LiFWWYOeE2f6j/r4tCFClVLHHRHn3LX =LgQc -----END PGP SIGNATURE----- --+epxrXWOh++2HLjY--