`fexecve`函数的参数解释

huangapple go评论52阅读模式
英文:

Some clarity on the arguments of `fexecve`

问题

The Linux man pages say that the third argument to fexecve is envp[] which my research has led me to believe is the environment to execute the file descriptor e.g. “/use/python3” for a Python file.

  1. 这个说法正确吗?如果我错了,请纠正我。

  2. 如果我在使用ELF二进制文件,那么该参数应该是什么?

注意:我尝试过将第二和第三个参数留空,即*char[](如果这是类型的话),但我收到了以下错误信息:

fexecve: 无效的参数

提前感谢您的帮助。我是在手机上做这个操作的,所以请原谅任何奇怪的文本。另外,文件描述符是一个memfd,如果这有任何意义的话。

英文:

The Linux man pages say that the third argument to fexecve is envp[] which my research has led me to believe is the environment to execute the file descriptor e.g. “/use/python3” for a Python file.

  1. Is this true? Please correct me if I’m wrong

  2. What if I’m using an ELF binary? What would the argument be then?

Note: I’ve tried this with the second and third arguments empty *char[] (if that’s what the types were) and I got:

> fexecve: invalid argument

Thanks in advance. I’m doing this on my phone so excuse any weird text. Also, the file descriptor is a memfd, if that means anything.

答案1

得分: 1

envp 参数与 execve()execle() 的参数相似。它是一个字符串数组,其中每个元素都是一个以 variable=value 格式表示的环境变量,将用作新进程中初始的环境变量集。数组的末尾由一个 NULL 值表示。

fexecve()execve() 相同,只是它从一个打开的文件描述符中获取要运行的程序,而不是从一个路径名中获取;这可以避免在存在检查后替换可执行文件或其路径名中的目录而导致的某些竞态条件。

envp 参数的详细信息可以在 execve() 手册页中找到。如果你不需要提供自定义环境,你可以使用全局变量 environ,让新进程继承当前进程的环境(这就是 execl()execv() 的工作方式,因为它们不接受显式的 envp 参数)。

英文:

The envp argument is just like the same argument to execve() or execle(). It's an array of strings, where each element is an environment variable in the format variable=value, which will be used as the initial set of environment variables in the new process. The end of the array is indicated by a NULL value.

fexecve() is the same as execve(), except that it gets the program to run from an open file descriptor rather than a pathname; this can be useful to avoid some race conditions resulting from the executable or a directory in its pathname being replaced after an existence check.

The details of the envp parameter can be found in the execve() man page. If you don't need to provide a custom environment, you can use the global variable environ to have the new process inherit the current process's environment (this is how execl() and execv() work, since they don't take an explicit envp argument).

huangapple
  • 本文由 发表于 2023年4月20日 06:35:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76059280.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定