[PATCH 8/8] wall: new applet
Denys Vlasenko
vda.linux at googlemail.com
Tue Oct 27 15:09:37 UTC 2009
On Tue, Oct 27, 2009 at 10:47 AM, Peter Korsgaard <jacmet at uclibc.org> wrote:
>>>>>> "walter" == walter harms <wharms at bfs.de> writes:
>
> Hi,
>
> >> + int fd = argv[1] ? xopen(argv[1], O_RDONLY) : STDIN_FILENO;
> >> +
>
>
> walter> i did not try; but what will happen if argc==1 ?
> walter> argv[1] should be undefined.
>
> No, argv is afaik guaranteed to be null terminated - E.G. access to
> argv[argc] is OK - But you can ofcourse cheat with execve and get argc
> == 0, so the below is indeed better.
>
> walter> perhaps this is more save
> walter> (argc > 1) ? xopen(argv[1], O_RDONLY) : STDIN_FILENO;
Yes, you can do
int main()
{
static char *argv[1] = { 0 };
execvp("busybox", argv);
return 0;
}
but this way busybox wouldn't even call wall_main, it will segfault earlier.
--
vda
More information about the busybox
mailing list