Re: execl!

H. Peter Anvin (hpa@transmeta.com)
24 Mar 1999 04:38:40 GMT


Followup to: <Pine.3.87.9903240924.A28286-0100000@teil.soft.net>
By author: G Jalaja Devi <jalaja@teil.soft.net>
In newsgroup: linux.dev.kernel
>
> Have a look at this piece of code.
> The instructions prior to the execl() function is not getting executed.
> When I give a getchar() after the printf statement then the "Tr -module"
> is getting printed.
> From the manpage, what I had understood is that the execl function
> replaces the current process image with the new process image.
> But, Does it replaces the prior instructions also? or what is happening??
>

The problem is that you're doing write to stdio, which doesn't get
flushed before you exec(). Put an fflush(NULL); before execl() and
you're fine.

> int pid;
> pid = fork();
> if (pid == 0)
> {
> printf("Tr -module");
> getchar();
> execl("/sbin/insmod", "insmod", "trc", NULL);
> }
> else if (pid < 0)
> perror("Error in fork - load2.c");
> else
> {
> printf("I am in the parent process");
>
> }

-hpa

-- 
"The user's computer downloads the ActiveX code and simulates a 'Blue
Screen' crash, a generally benign event most users are familiar with
and that would not necessarily arouse suspicions."
-- Security exploit description on http://www.zks.net/p3/how.aspb

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/