On Tue, Mar 25, 2008 at 04:48:40PM +0100, andres wrote:
> Hi all. We are developing and application over uclibc and busybox on a
> mips architecture.
>
> In addition, we are using an Erlang Virtual Machine. The problem is that
> this one fails when we try to access to system. Example:
>
> 4> os:cmd("ls /").
> []
>
> 5> open_port({spawn, "ls"}, []).
> #Port<0.91>
> 6> flush().
> ok
>
> As we see, the above commands doesn't list anything.
>
> We think underlaying Virtual Machine uses "exec" family calls and these
> ones crash. In fact, we have made some tests with little programs.
They are all wrong.
> int main(){
> int result = execv("/bin/ls", NULL);
> exit(0);
> }//main
You must specifiy the arguments, NULL isn't enough, like:
int main() {
char *argv[] = { "/bin/ls", NULL };
int result = execv(argv[0], argv);
exit(0);
}
> int main(){
>
> int result = execv("/bin/ls", "-lisa");
This is so wrong it hurts. :(
You probably want: execl("/bin/ls", "ls", "-lisa", NULL);
(note: execl, not execv)
> int result = execv("/bin/ls", "");
Same case.
> char *cmd[] = { "ls", "-l", (char *)0 };
> int result = execv("/bin/ls", cmd);
This one is correct.
> char *cmd[] = { "ls", "", (char *)0 };
> int result = execv("/bin/ls", cmd);
Also correct (you're trying to "list" a file with no name).
> char *cmd[] = { "ls", NULL, (char *)0 };
> int result = execv("/bin/ls", cmd);
That's plain "ls".
You can't complain the way the application crashes when it passes
invalid arguments to a function. In most cases, it will try to fetch
data from an invalid memory location, and be killed by the kernel.
--
lfr
0/0
pgpTtujHb6a3X.pgp
Description: PGP signature
_______________________________________________ busybox mailing list [email protected] http://busybox.net/cgi-bin/mailman/listinfo/busybox
