[Novalug] Infinite loop in init script on embedded linux -- hopeless?

Jon LaBadie novalugml@jgcomp.com
Tue Apr 24 12:36:49 EDT 2012


On Tue, Apr 24, 2012 at 10:40:32AM -0400, Nick Danger wrote:
> On 04/24/2012 09:08 AM, Jeremy Trimble wrote:
> > My company is developing some software for an embedded (timesys) Linux 
> > target.  One of our developers (name omitted to protect the innocent) 
> > wrote an script that would attempt to wait until the Ethernet 
> > interface comes up, then try to set the system time using ntpdate.  It 
> > does this by continually running 'ifconfig eth0' until that command 
> > returns 0 (indicating that 'eth0' is now a valid interface on the 
> > machine).
> >
> > Unfortunately, it seems that the interface won't come up until after 
> > all the init scripts have run, so this script sits in an infinte loop, 
> > waiting for the appearance of an interface which won't come up until 
> > this script exits.  Since the ethernet interface is effectively our 
> > only connectivity to the processor where this code is running, this 
> > basically locks us out of the unit.  The init script itself is stored 
> > on some integrated flash chip somewhere in the system, not on 
> > removable media.
> 
> I find a logical fallacy here. You are saying the interface wont come up 
> until the script exits, and the script won't exit until the interface 
> comes up. So why bother to run that script.. right there? Maybe it needs 
> to be in rc.local or somewhere else?
> 
> Otherwise, as others have said, put in a loop counter, or a timeout. Or 
> just take the script out as it seems to be kinda redundant. You can do 
> an ntpdate elsewhere in startup (after you know ifconfig is up)

I was thinking along the same lines.

Do embedded systems still use network scripts such as those found in
/etc/sysconfig/network-scripts?  If so, there may be a set of "post"
scripts or "local" scripts that run after network configuration.  You
could move execution of ntpdate to these locations.  Also my "ifup-post"
script contains these intriguing lines:

    # Notify programs that have requested notification
    do_netreport

Perhaps your script could start a child that asks for notification and
sleeps while the parent exits to complete its "init" function.

jl
-- 
Jon H. LaBadie                  novalugml@jgcomp.com
 11226 South Shore Rd		(703) 787-0688 (H)
 Reston, VA  20190		(609) 477-8330 (C)



More information about the Novalug mailing list