* argv null terminated in main()?
@ 2004-09-16 21:26 Aleksandar Milivojevic
2004-09-16 21:01 ` Alan Cox
0 siblings, 1 reply; 3+ messages in thread
From: Aleksandar Milivojevic @ 2004-09-16 21:26 UTC (permalink / raw)
To: Linux Kernel Mailing List
I was looking for info on this question on web and in documentation, but
couldn't find it documented anywhere.
The question is, after call to execve() system call, and after new image
is loaded, is argv (as passed to main() function of new program) NULL
terminated or not in Linux?
So far I found article from Ritchie saying that argv[argc] was -1 up to
Unix Sixth Edition (1975), and than it was changed to NULL starting from
Seventh Edition (in 1979) and than later same behaviour was carried over
to 32V and BSD. Looking at the man page for exec(2) on Solaris, which
is System V derivate, the documentation still states the same
(argv[argc] is guaranteed to be NULL).
But how about Linux kernel? What (if anything) is copied or filled into
argv[argc] by execve()?
Documentation for execve() on Linux doesn't state it explicitly, but one
could find himself lured into beleiving that argv[argc] should be NULL.
It says "The argument vector and environment can be accessed by the
called program's main function, when it is defined as int main(int
argc, char *argv[], char *envp[])". Because original vector as passed
to execve was NULL terminated.
I've looked in the kernel source code (just a glance), and by looking at
copy_strings function in exec.c, it seems as argv[argc] might be
undefined (it seems that loop copies only first argc - 1 elements of
argv). But I might be wrong.
--
Aleksandar Milivojevic <amilivojevic@pbl.ca> Pollard Banknote Limited
Systems Administrator 1499 Buffalo Place
Tel: (204) 474-2323 ext 276 Winnipeg, MB R3T 1L7
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: argv null terminated in main()?
2004-09-16 21:26 argv null terminated in main()? Aleksandar Milivojevic
@ 2004-09-16 21:01 ` Alan Cox
2004-09-17 13:54 ` Aleksandar Milivojevic
0 siblings, 1 reply; 3+ messages in thread
From: Alan Cox @ 2004-09-16 21:01 UTC (permalink / raw)
To: Aleksandar Milivojevic; +Cc: Linux Kernel Mailing List
On Iau, 2004-09-16 at 22:26, Aleksandar Milivojevic wrote:
> I was looking for info on this question on web and in documentation, but
> couldn't find it documented anywhere.
>
> The question is, after call to execve() system call, and after new image
> is loaded, is argv (as passed to main() function of new program) NULL
> terminated or not in Linux?
Yes. execve is documented in SuS v3 which you can find on the web. See
also info glibc which does have a lot more information on other useful
extensions like saved argv0 copies.
Alan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: argv null terminated in main()?
2004-09-16 21:01 ` Alan Cox
@ 2004-09-17 13:54 ` Aleksandar Milivojevic
0 siblings, 0 replies; 3+ messages in thread
From: Aleksandar Milivojevic @ 2004-09-17 13:54 UTC (permalink / raw)
To: Linux Kernel Mailing List
Alan Cox wrote:
> On Iau, 2004-09-16 at 22:26, Aleksandar Milivojevic wrote:
>>The question is, after call to execve() system call, and after new image
>>is loaded, is argv (as passed to main() function of new program) NULL
>>terminated or not in Linux?
>
> Yes. execve is documented in SuS v3 which you can find on the web. See
> also info glibc which does have a lot more information on other useful
> extensions like saved argv0 copies.
Thanks for quick answer. I didn't know to which degree was Linux SuS v3
compliant, so I said better to ask ;-)
--
Aleksandar Milivojevic <amilivojevic@pbl.ca> Pollard Banknote Limited
Systems Administrator 1499 Buffalo Place
Tel: (204) 474-2323 ext 276 Winnipeg, MB R3T 1L7
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-09-17 13:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-16 21:26 argv null terminated in main()? Aleksandar Milivojevic
2004-09-16 21:01 ` Alan Cox
2004-09-17 13:54 ` Aleksandar Milivojevic
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox