meson: add option for fexecve use
There are downsides to using fexecve: when fexecve is used (for normal executables), /proc/pid/status shows Name: 3, which means that ps -C foobar doesn't work. pidof works, because it checks /proc/self/cmdline. /proc/self/exe also shows the correct link, but requires privileges to read. /proc/self/comm also shows "3". I think this can be considered a kernel deficiency: when O_CLOEXEC is used, this "3" is completely meaningless. It could be any number. The kernel should use argv[0] instead, which at least has *some* meaning. I think the approach with fexecve/execveat is instersting, so let's provide it as opt-in.
This commit is contained in:
@@ -447,6 +447,7 @@ ExecCommandFlags exec_command_flags_from_string(const char *s) {
|
||||
}
|
||||
|
||||
int fexecve_or_execve(int executable_fd, const char *executable, char *const argv[], char *const envp[]) {
|
||||
#if ENABLE_FEXECVE
|
||||
execveat(executable_fd, "", argv, envp, AT_EMPTY_PATH);
|
||||
|
||||
if (IN_SET(errno, ENOSYS, ENOENT) || ERRNO_IS_PRIVILEGE(errno))
|
||||
@@ -463,6 +464,7 @@ int fexecve_or_execve(int executable_fd, const char *executable, char *const arg
|
||||
* least in case of bash) the script name, $0, will be shown as /dev/fd/nnn, which breaks
|
||||
* scripts which make use of $0. Thus, let's fall back to execve() in this case.
|
||||
*/
|
||||
#endif
|
||||
execve(executable, argv, envp);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user