On Fri, Oct 2, 2009 at 10:21 AM, Eric Shubert <[email protected]> wrote:

> Dazed_75 wrote:
> > RESOLVED !!!
> >
> > Ryan had said:
> >
> > I found this https://bugs.launchpad.net/ubuntu/+source/dhcp3/+bug/392826
> > via a quick google search so the answer to your question about
> > reordering the script doesn't seem like it would work.
> >
> > But I had been looking mostly at the discussion of ordering the elements
> > in /etc/rc?.d/ which I tried several variations for.  When I re-read it
> > and noticed the script attached, it seemed a reasonable work around.
> >
> > Jacob Nevins has said:
> >
> > I'm also running into this.
> >
> > I've bodged around it by putting the attached script in
> > /etc/network/if-up.d/dhcp3-server . I don't claim it's the best
> > solution, or that it should be included in the package, but it works for
> > my situation (where I have a single interface "eth0" explicitly listed
> > in /etc/default/dhcp3-server), so it might be a useful workaround for
> > others.
> >
> > The script was:
> >
> > #! /bin/sh
> > # Kick DHCP server when interface comes up (for Ubuntu, probably Debian
> too)
> >
> > # Workaround for <
> https://bugs.launchpad.net/ubuntu/+source/dhcp3/+bug/392826>
> > # Bugs:
> > #  - Only works when interfaces for dhcpd are explicitly listed.
> >
> >
> > DHCP_IF=/etc/default/dhcp3-server
> > DHCP_INIT=/etc/init.d/dhcp3-server
> >
> > [ -f "$DHCP_IF" -a -f "$DHCP_INIT" ] || exit 0
> >
> > . "$DHCP_IF"
> >
> > if [ "x$INTERFACES" = x ]; then
> >
> >     # Don't know which interfaces it manages, always restart
> >     restart_dhcp=1
> > else
> >     restart_dhcp=0
> >     for iface in "$INTERFACES"; do
> >         if [ "$iface" = "$IFACE" ]; then
> >
> >             restart_dhcp=1
> >         fi
> >     done
> > fi
> >
> > if [ "$restart_dhcp" = "1" ]; then
> >     "$DHCP_INIT" restart
> > fi
> >
> >
> > It seemed reasonable to try and it worked.  Now there is no need to
> > actually log in and run /etc/init.d/dhcp3-server start in order to get
> > the DHCO server running.  Oh, BTW, he was wrong about needing to name
> > the interface to use in /etc/default/dhcp3-server.
> >
> > --
> > Dazed_75 a.k.a. Larry
> >
> > The spirit of resistance to government is so valuable on certain
> > occasions, that I wish it always to be kept alive.
> >  - Thomas Jefferson
> >
> >
> While that script appears to work, I don't believe it will work as
> intended. Long story short, [ "" = "" ] is always true, as = is
> assignment. The tests should be [ "" == "" ] . Substitute appropriately,
> and the rest appears ok.
>
> --
> -Eric 'shubes'
>
> I see what you mean.  It didn't really try to read the code since it has
been a VERY long time since I write any shell code.  Glad I did not since
just trying it worked and might I not have tried it had I caught the
ambiguity ... err, poor code.  I wonder if you could assist me by carefully
reading the following where I have commented the code and changed it, or
not, according to my understanding?  Tell me where I am wrong before I send
him corrections.

#! /bin/sh
# Kick DHCP server when interface comes up (for Ubuntu, probably Debian too)
# Workaround for <https://bugs.launchpad.net/ubuntu/+source/dhcp3/+bug/392826>
# Bugs:
#  - Only works when interfaces for dhcpd are explicitly listed.

# Dazed_75: If either of these two references are not present as
# regular files, exit with a return code of 0

DHCP_IF=/etc/default/dhcp3-server
DHCP_INIT=/etc/init.d/dhcp3-server

[ -f "$DHCP_IF" -a -f "$DHCP_INIT" ] || exit 0

# Dazed_75: Otherwise source the default configuration file to set the
# variable $INTERFACES (which happens to be a null string in my system
# and never changes

. "$DHCP_IF"

# Dazed_75: The following should use "==" to test if $INTERFACES is null
# rather than assigning x to "x$INTERFACES" which I am not even sure what
# that means though I suspect that in my system, it assigns the value x
# to a variable named $x since $INTERFACES is null for my system.
# Due to the assignment, the if condition is always true so the variable
# $restart_dhcp is always set to 1 and the else condition is never used.

if [ "x$INTERFACES" = x ]; then
    # Don't know which interfaces it manages, always restart
    restart_dhcp=1
else

    # Dazed_75: The else condition is meant to be used if
/etc/default/dhcp3-server
    # when sourced above, sets $INTERFACES to a string value
containing one or more
    # interface names such as "eth0 eth2".
    # It first sets $restart_dhcp to 0 (FALSE) and then iterates for
each "word/name"
    # in $INTERFACES and should be using "==" to test if the current
word matches a
    # variable named $IFACE which I can find to reference to anywhere.
 The intent
    # would be to set $restart_dhcp to 1 (TRUE) if ANY of the words in
$INTERFACES
    # matched the value of $IFACE, but the assignment wrongly ensures
the value is
    # always set to TRUE

    restart_dhcp=0
    for iface in "$INTERFACES"; do
        if [ "$iface" = "$IFACE" ]; then
            restart_dhcp=1
        fi
    done
fi

# Dazed_75: Hence the only condition under which the following code is
not reached
# is if one or both of the listed config files is not present or not a
regular file.
# Further, under all conditions, when this code is reached, the
$restart_dhcp has
# been set to 1 (TRUE) due to the assignment operator being used.
#
# Hence, any condition that causes this script to execute will cause
# /etc/init.d/dhcp3-server to be executed with an argument of
"restart".  Further,
# I find nothing in that script which uses a variable named $IFACE or
$iface which
# may just be something I do not see.

if [ "$restart_dhcp" = "1" ]; then
    "$DHCP_INIT" restart
fi

# Dazed_75: In closing, the assignment operators inside the conditionals could
# and should be changed to conditional "==". But, in either case, as long as
# /etc/default/dhcp3-server is not altered to set the contents of $INTERFACES,
# this script will always cause "/etc/init.d/dhcp3-server restart" to
be executed.


-- 
Dazed_75 a.k.a. Larry

The spirit of resistance to government is so valuable on certain occasions,
that I wish it always to be kept alive.
 - Thomas Jefferson
_______________________________________________
PLUG-applications mailing list
[email protected]
http://lists.plug.phoenix.az.us/cgi-bin/mailman/listinfo/plug-applications

Reminder: All replies will go back to this mailing list. If you wish to send a 
reply to a specific person, please use the reply function and change the 
&quot;To:&quot; address to that person before sending.

Reply via email to