[uClinux-dev] execve function of linux-2.4.x of
uClinux-dist-20070130 misbehavior
=?gb2312?B?y84gaHo=?=
chinadldz2002 at hotmail.com
Fri Feb 23 06:45:56 EST 2007
Hi everybody.
cpu: S3C4510
toolchain: arm-elf-tools-20030314
use uClibc
I run this version of uclinux in skyeye, and find that if parameters are
passed from commandline the invoked command often output an error,
especially busybox, it can't work at all.
And at last, I find the pointer passed to main function is offseted
backward by 2.
I write two programs to test execve function:
#################
invoke.c:
#################
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
pid_t cpid;
int status;
char *cargv[5];
char *cenvp[1];
printf("version 2\n");
cpid = vfork();
if(cpid == -1) { printf("fork failed!\n"); perror("fork");
exit(EXIT_FAILURE); }
if(cpid == 0) { // child
cargv[0] = "dispargv";
cargv[1] = "argv1";
cargv[2] = "argv2";
cargv[3] = "argv3";
cargv[4] = NULL;
cenvp[0] = NULL;
printf("Child PID is %ld\n", (long)getpid());
execve("/bin/dispargv", cargv, cenvp);
}
wait(&status);
return 0;
}
######################
dispargv.c
######################
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[], char *envp[])
{
int tmp = 0;
printf("argv is: \n");
for(tmp = 0; tmp < argc; tmp++)
{
printf("%d: %s\n", tmp, argv[tmp]);
}
return 0;
}
###################
Makefile
###################
EXEC1 = invoke
OBJS1 = invoke.o
EXEC2 = dispargv
OBJS2 = dispargv.o
all: $(EXEC1) $(EXEC2)
$(EXEC1): $(OBJS1)
$(CC) $(LDFLAGS) -o $@ $(OBJS1)
$(EXEC2): $(OBJS2)
$(CC) $(LDFLAGS) -o $@ $(OBJS2)
romfs:
$(ROMFSINST) /bin/invoke
$(ROMFSINST) /bin/dispargv
.PHONY:
clean:
-rm -f $(EXEC1) $(EXEC2) *.elf *.gdb *.o
############################################################
After adding them to user/testexecve and making the romfs image, when
running:
/bin> invoke
version 2
Child PID is 10
argv is:
0: <
1:
2: dispargv
3: argv1
/> dispargv haha xixi wuwu
argv is:
0: ?
1: ?
2: dispargv
3: haha
It is obviously that the argv pointer is offseted backward by 2.
Is it a bug, or something I did wrong?
_________________________________________________________________
ÏíÓÃÊÀ½çÉÏ×î´óµÄµç×ÓÓʼþϵͳ¡ª MSN Hotmail¡£ http://www.hotmail.com
More information about the uClinux-dev
mailing list