For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > October 2006 > execve() argument types









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author execve() argument types
phil-news-nospam@ipal.net

2006-10-30, 7:15 pm

The following is the definition for execve():

int execve(const char *path, char *const argv[], char *const envp[]);

I'm curious why the partial const attribute for the argument vectors but
not for the argument characters themselves. Why not:

int execve(const char *path, const char *const argv[], const char *const envp[]);

Is execve() expected to modify the argument and/or environment strings
in the unreplaced VM if it fails and returns an error? It would be
easier to call execve() with either const or non-const strings if it
had a definition like that.

--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
| first name lower case at ipal.net / spamtrap-2006-10-29-2022@ipal.net |
|------------------------------------/-------------------------------------|
Robert Harris

2006-10-30, 7:15 pm

phil-news-nospam@ipal.net wrote:
> The following is the definition for execve():
>
> int execve(const char *path, char *const argv[], char *const envp[]);
>
> I'm curious why the partial const attribute for the argument vectors but
> not for the argument characters themselves. Why not:
>
> int execve(const char *path, const char *const argv[], const char *const envp[]);
>
> Is execve() expected to modify the argument and/or environment strings
> in the unreplaced VM if it fails and returns an error? It would be
> easier to call execve() with either const or non-const strings if it
> had a definition like that.
>


No, but the program invoked by exec is allowed to change its arguments
and environment strings if it really wants to.

Robert
Barry Margolin

2006-10-30, 7:15 pm

In article <3Kl1h.43940$r61.12638@text.news.blueyonder.co.uk>,
Robert Harris <robert.f.harris@blueyonder.co.uk> wrote:

> phil-news-nospam@ipal.net wrote:
>
> No, but the program invoked by exec is allowed to change its arguments
> and environment strings if it really wants to.


Doesn't the program get a copy of those strings, not the original
strings?

In most cases this is a meaningless question, because the original
memory image is replaced by exec. But if any of the argument or
environment strings are in shared memory, it's relevant -- will the new
program still reference that shared memory?

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Robert Harris

2006-10-30, 7:15 pm

Barry Margolin wrote:
> In article <3Kl1h.43940$r61.12638@text.news.blueyonder.co.uk>,
> Robert Harris <robert.f.harris@blueyonder.co.uk> wrote:
>
>
> Doesn't the program get a copy of those strings, not the original
> strings?


Yes, of course :-).

>
> In most cases this is a meaningless question, because the original
> memory image is replaced by exec. But if any of the argument or
> environment strings are in shared memory, it's relevant -- will the new
> program still reference that shared memory?


According to my (Linux) man shmget, all attached memory segments are
detached after an exec().

So the strings can probably be const without problems. In fact, checking
with the Posix man page examples of the use of exec with strings are
given, so it must be OK.

Robert


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com