Annoying ERROR: 'wlan0' is not a DHCP-enabled interface

Eygene Ryabinkin rea at freebsd.org
Mon Dec 26 09:52:50 UTC 2011


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 
> > ------------------------------------------------------------------------
> >
> > 
> r226879 | rea | 2011-10-27 23:03:38 -0700 (Thu, 27 Oct 2011) | 10 lines
> > 
> > Fix handling of rc_force in /etc/rc.d/dhclient
> > 
> > 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.
> > 
> > Spotted by:	hrs Reviewed by:	hrs, des Approved by:	des MFC after:	2
> > weeks 
> > ------------------------------------------------------------------------
> >
> >  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
> 
>            return [exitstatus]
> 
> 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."
> 
> 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=226345&r2=226464
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/dhclient"
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 one.
Moreover, script names ending in .sh are currently deprecated inside rc.subr.
So, for this case 'return 1' == '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=226464&r2=226879
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)
> 
> 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 ;))
-- 
Eygene Ryabinkin                                        ,,,^..^,,,
[ Life's unfair - but root password helps!           | codelabs.ru ]
[ 82FE 06BC D497 C0DE 49EC  4FF0 16AF 9EAE 8152 ECFB | freebsd.org ]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-rc/attachments/20111226/c9c4291c/attachment.pgp


More information about the freebsd-rc mailing list