LINUX.ORG.RU

История изменений

Исправление LamerOk, (текущая версия) :

Конкретно в какой версии POSIX нет execve()? Про POSIX.1-1996

Да, там есть execve(), но там же написано и следующее:

3.1.2.2 Description
...
When a C program is executed as a result of this call, it shall be entered as a C language function call as follows:

     int main(int argc, char *argv[]);
where argc is the argument count and argv is an array of character pointers to the arguments themselves. In addition, the following variable:
     extern char **environ;
is initialized as a pointer to an array of character pointers to the environment strings.
...
For those forms not containing an envp pointer [execl(), execv(), execlp(), and execvp()], the environment for the new process image is taken from the external variable environ in the calling process.

То есть передача окружения через третий аргумент execve() - это не единственный и не единственно правильный механизм. Наоборот, система, передающая третий аргумент, обязана для совместимости корректно инициализировать ещё глобальную переменную, т.к. main() имеет только два аргумента.

Исправление LamerOk, :

Конкретно в какой версии POSIX нет execve()? Про POSIX.1-1996

Да, там есть execve(), но там же написано и следующее:

3.1.2.2 Description
...
When a C program is executed as a result of this call, it shall be entered as a C language function call as follows:

     int main(int argc, char *argv[]);
where argc is the argument count and argv is an array of character pointers to the arguments themselves. In addition, the following variable:
     extern char **environ;
is initialized as a pointer to an array of character pointers to the environment strings.
...
For those forms not containing an envp pointer [execl(), execv(), execlp(), and execvp()], the environment for the new process image is taken from the external variable environ in the calling process.

То есть передача окружения через третий аргумент execve() - это не единственный и не единственно правильный механизм. Наоборот, система, передающая третий аргумент, обязана для совместимости корректно инициализировать ещё глобальную переменную. А main() имеет только два аргумента.

Исходная версия LamerOk, :

Конкретно в какой версии POSIX нет execve()? Про POSIX.1-1996

Да, там есть execve(), но там же написано и следующее:

3.1.2.2 Description
...
When a C program is executed as a result of this call, it shall be entered as a C language function call as follows:

     int main(int argc, char *argv[]);
where argc is the argument count and argv is an array of character pointers to the arguments themselves. In addition, the following variable:
     extern char **environ;
is initialized as a pointer to an array of character pointers to the environment strings.
...
For those forms not containing an envp pointer [execl(), execv(), execlp(), and execvp()], the environment for the new process image is taken from the external variable environ in the calling process.

То есть передача окружения через третий аргумент main() - это не единственный и не единственно правильный механизм. Наоборот, система, получающая третий аргумент, обязана для совместимости корректно инициализировать ещё глобальную переменную.