Problem with absolute binary name

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hi All,

I have a board running embedded Linux in it.
I need to have a script that has to run forever i.e even if it exit's
for any reason,it should be stated again.
So I added a entry in the /etc/inittab file and made this script as
'respawn' entry.


::respawn:/flash2/scripts/hello_world.sh

In the script, I call a binary 'hello_world' with it's absolute path
and the binary is in '/flash2/bin' whose path is exported to the PATH
variable.So it should get executed.

My /etc/inittab looks like below

# System initialization.
::sysinit:/etc/init.d/rcS

#Run gettys
ttyS1::respawn:-/bin/sh


#Test respawn
::off:/flash2/hello_world.sh

# Trap CTRL-ALT-DELETE
::ctrlaltdel:/bin/umount -a -r

So the system initialization script /etc/init.d/rcS execute's first
and it is in this script the '/flash2/bin' path is added to export
variable.

But once the board boots, the script 'hello_world.sh' is executed, but
the binary 'hello_world' is not executed.It keeps throwing the
following message

/flash2/hello_world.sh: 5: hello_world: not found
/flash2/hello_world.sh: 5: hello_world: not found
/flash2/hello_world.sh: 5: hello_world: not found
/flash2/hello_world.sh: 5: hello_world: not found
/flash2/hello_world.sh: 5: hello_world: not found
/flash2/hello_world.sh: 5: hello_world: not found

The '/flash2' is the NOR flash partition.

Why is it not able to find 'hello_world' binary whose path is exported
to PATH.

If any clarification needed,please let me know if the explanation is
not clear.

Re: Problem with absolute binary name

Quoted text here. Click to load it

with a quite "standard" setup it would be

/mnt/flash2/hello_world.sh

-Michael

Re: Problem with absolute binary name

Quoted text here. Click to load it

What method are you using to execute the binary from the script?
Did it work properly if you launched the script manually from the
shell prompt?

-

Re: Problem with absolute binary name
Quoted text here. Click to load it

The 'hello_world.sh' script that i am configuring as respawn entry is
shown below

#!/bin/sh
echo "Starting Yellow LED blinking"
while [ 1 ]; do
   hello_world
done


'hello_world' is a simple executable that print's hello world. It's in
'/flash2/bin' whose path is exported to $PATH environment variable.

I am able to execute the same binary from shell manually. In the '/etc/
init.d/rcS' file,i cross checked the value of PATH by echoing it to
stdout and found that '/flash2/bin' is present.

Also, in the '/etc/init.d/rcS' script, in the end i called the same
binary 'hello_world' and it got executed properly. But it is not
executed by '/etc/inittab' as a respawn entry from the
'hello_world.sh' script.

As i told , the '/flash2' is a NOR flash MTD partition.

It's "/etc/init.d/rcS" that will be executed by busybox init first and
then only the respawn entries will be executed. So the same binary
which get's executed when invoked from rcS script doesn't get executed
by '/etc/inittab' as respawn entry.

I hope you understand the issue more clearly now.


Re: Problem with absolute binary name

Quoted text here. Click to load it

Shouldn't this be
S1::respawn:-/bin/sh

Quoted text here. Click to load it

Instead of "off" did you try with "respawn" and '/flash2/bin' ?


Quoted text here. Click to load it

Re: Problem with absolute binary name
Quoted text here. Click to load it

Sorry that was a mistake while pasting my /etc/inittab contents here.
It is actually 'respawn' and not 'off' there. Yes i have tried it with
only 'respawn' but it didn't work.

Re: Problem with absolute binary name
Quoted text here. Click to load it

Another information is that in the 'hello_world.sh' script, before
invoking the 'hello_world' executable,I had added echo $PATH and echo
$LD_LIBRARY_PATH
and found that $PATH is correct and there was no output  for
LD_LIBRARY_PATH. I think this could be the reason for 'hello_world'
being not found.

But it's not sure why LD_LIBRARY_PATH is not having any value.

Re: Problem with absolute binary name
Quoted text here. Click to load it

If the LD_LIBRARY_PATH was the problem the error message would be
different (something about not be able to find a shared library, if your
hello world needs one), not "hello_world: not found"

Re: Problem with absolute binary name
Quoted text here. Click to load it

The reason for this problem is that the busybox 'init' process defines
it's
own PATH environment variable.So any process invoked by it become
their child
process and so they inherit the parent's environment variable.

In the busybox init process source code, the PATH environment variable
is
defined by the macro_PATH_STDPATH.

In the file busybox-xx/init/init.c, this macro is defined as below

#ifndef _PATH_STDPATH
#define _PATH_STDPATH    "/usr/bin:/bin:/usr/sbin:/sbin"
#endif


But by default,the value of this macro is taken from another header
file
'paths.h' which is included in init.c.

So by defining the macro in init.c itself and by adding the '/flash2/
bin' to
it's value,this issue is solved.

#define _PATH_STDPATH    "/usr/bin:/bin:/usr/sbin:/sbin:/flash2/bin"

Thank you all guys for your timely help and suggestions.....

Re: Problem with absolute binary name
Quoted text here. Click to load it

is there any reason for starting the binary from the script and not
directly?

Site Timeline