@@ -16,24 +16,15 @@
<https://www.gnu.org/licenses/>. */
#include <errno.h>
-#include <stddef.h>
+#include <fcntl.h>
#include <unistd.h>
-
/* Replace the current process, executing PATH with arguments ARGV and
environment ENVP. ARGV and ENVP are terminated by NULL pointers. */
int
__execve (const char *path, char *const argv[], char *const envp[])
{
- if (path == NULL || argv == NULL || envp == NULL)
- {
- __set_errno (EINVAL);
- return -1;
- }
-
- __set_errno (ENOSYS);
- return -1;
+ return __execveat (AT_FDCWD, path, argv, envp, 0);
}
-stub_warning (execve)
weak_alias (__execve, execve)
@@ -20,6 +20,8 @@
#include <stddef.h>
#include <unistd.h>
+#include <arch-execveat.h>
+
/* Replace the current process, executing PATH relative to difrd with
arguments argv and environment envp.
argv and envp are terminated by NULL pointers. */
@@ -27,15 +29,7 @@ int
__execveat (int dirfd, const char *path, char *const argv[], char *const envp[],
int flags)
{
- if (path == NULL || argv == NULL || envp == NULL)
- {
- __set_errno (EINVAL);
- return -1;
- }
-
- __set_errno (ENOSYS);
- return -1;
+ return __arch_execveat (dirfd, path, argv, envp, flags);
}
-stub_warning (execveat)
weak_alias (__execveat, execveat)
@@ -16,23 +16,20 @@
<https://www.gnu.org/licenses/>. */
#include <errno.h>
-#include <stddef.h>
+#include <fcntl.h>
#include <unistd.h>
-
/* Execute the file FD refers to, overlaying the running program image.
ARGV and ENVP are passed to the new program, as for `execve'. */
int
fexecve (int fd, char *const argv[], char *const envp[])
{
- if (fd < 0 || argv == NULL || envp == NULL)
+ /* Avoid unexpected behavior of execveat with AT_FDCWD. */
+ if (fd < 0)
{
- __set_errno (EINVAL);
+ __set_errno (EBADF);
return -1;
}
- __set_errno (ENOSYS);
- return -1;
+ return __execveat (fd, "", argv, envp, AT_EMPTY_PATH);
}
-
-stub_warning (fexecve)
similarity index 61%
rename from sysdeps/mach/hurd/execve.c
rename to sysdeps/generic/arch-execveat.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 1991-2024 Free Software Foundation, Inc.
+/* Architecture-specific execveat implementation. Stub version.
+ Copyright (C) 2024 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -15,18 +16,10 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <unistd.h>
-#include <hurd.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-/* Replace the current process, executing FILE_NAME with arguments ARGV and
- environment ENVP. ARGV and ENVP are terminated by NULL pointers. */
-int
-__execve (const char *file_name, char *const argv[], char *const envp[])
+static int
+__arch_execveat (int dirfd, const char *path, char *const argv,
+ char *const envp, int flags)
{
- return __execveat (AT_FDCWD, file_name, argv, envp, 0);
+ __set_errno (ENOSYS);
+ return -1;
}
-
-weak_alias (__execve, execve)
similarity index 90%
rename from sysdeps/mach/hurd/execveat.c
rename to sysdeps/mach/hurd/arch-execveat.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 1991-2024 Free Software Foundation, Inc.
+/* Execute program relative to a directory file descriptor. Hurd version.
+ Copyright (C) 1991-2024 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -25,9 +26,9 @@
/* Replace the current process, executing FILE_NAME with arguments ARGV and
environment ENVP. ARGV and ENVP are terminated by NULL pointers. */
-int
-__execveat (int dirfd, const char *file_name, char *const argv[],
- char *const envp[], int flags)
+static int
+__arch_execveat (int dirfd, const char *file_name, char *const argv[],
+ char *const envp[], int flags)
{
error_t err;
char *concat_name = NULL;
@@ -88,5 +89,3 @@ __execveat (int dirfd, const char *file_name, char *const argv[],
return __hurd_fail (err);
}
-
-weak_alias (__execveat, execveat)
deleted file mode 100644
@@ -1,47 +0,0 @@
-/* Copyright (C) 1993-2024 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <unistd.h>
-#include <hurd.h>
-#include <hurd/fd.h>
-#include <errno.h>
-
-/* Execute the file FD refers to, overlaying the running program image. */
-
-int
-fexecve (int fd, char *const argv[], char *const envp[])
-{
- file_t file;
- error_t err;
- enum retry_type doretry;
- char retryname[1024];
-
- err = HURD_DPORT_USE (fd,
- __dir_lookup (port, "", O_EXEC, 0, &doretry, retryname, &file));
-
- if (! err && (doretry != FS_RETRY_NORMAL || retryname[0] != '\0'))
- err = EGRATUITOUS;
- if (err)
- return __hurd_fail(err);
-
- err = _hurd_exec_paths (__mach_task_self (), file, NULL, NULL, argv, envp);
- if (! err)
- err = EGRATUITOUS;
-
- __mach_port_deallocate (__mach_task_self (), file);
- return __hurd_fail (err);
-}
similarity index 73%
rename from sysdeps/unix/sysv/linux/fexecve.c
rename to sysdeps/unix/sysv/linux/arch-execveat.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 1994-2024 Free Software Foundation, Inc.
+/* Execute program relative to a directory file descriptor. Linux version.
+ Copyright (C) 1994-2024 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -15,17 +16,11 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <errno.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <unistd.h>
#include <fcntl.h>
-#include <sys/stat.h>
-
#include <fd_to_filename.h>
-#include <sysdep.h>
-#include <sys/syscall.h>
#include <kernel-features.h>
+#include <sys/syscall.h>
+#include <sysdep.h>
static int
__do_fexecve (int fd, char *const argv[], char *const envp[])
@@ -64,17 +59,20 @@ __do_fexecve (int fd, char *const argv[], char *const envp[])
return -1;
}
-/* Execute the file FD refers to, overlaying the running program image.
- ARGV and ENVP are passed to the new program, as for `execve'. */
-int
-fexecve (int fd, char *const argv[], char *const envp[])
+static int
+__arch_execveat (int dirfd, const char *path, char *const *argv,
+ char *const *envp, int flags)
{
- /* Avoid unexpected behavior of execveat with AT_FDCWD. */
- if (fd < 0)
- {
- __set_errno (EBADF);
- return -1;
- }
+ /* Use execve if possible, to preserve the historic system call
+ profile. */
+ if (dirfd == AT_FDCWD && flags == 0)
+ return INLINE_SYSCALL_CALL (execve, path, argv, envp, flags);
+
+ /* Provide emulation for an fexecve-style execveat call. */
+ if (dirfd >= 0 && flags == AT_EMPTY_PATH && path[0] == '\0')
+ return __do_fexecve (dirfd, argv, envp);
- return __do_fexecve (fd, argv, envp);
+ /* Otherwise perform the system call without emulation. */
+ return INLINE_SYSCALL_CALL (execveat, dirfd, path, &argv[0], &envp[0],
+ flags);
}
deleted file mode 100644
@@ -1,32 +0,0 @@
-/* Execute program relative to a directory file descriptor.
- Copyright (C) 2021-2024 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <fd_to_filename.h>
-#include <sysdep.h>
-#include <unistd.h>
-
-/* Execute the file FD refers to, overlaying the running program image.
- ARGV and ENVP are passed to the new program, as for 'execve'. */
-int
-execveat (int dirfd, const char *path, char *const argv[], char *const envp[],
- int flags)
-{
- /* Avoid implicit array coercion in syscall macros. */
- return INLINE_SYSCALL_CALL (execveat, dirfd, path, &argv[0], &envp[0],
- flags);
-}
@@ -9,7 +9,6 @@ delete_module EXTRA delete_module 3 delete_module
epoll_create1 EXTRA epoll_create1 i:i epoll_create1
epoll_ctl EXTRA epoll_ctl i:iiip epoll_ctl
eventfd EXTRA eventfd2 i:ii eventfd
-execve - execve i:spp __execve execve
flock - flock i:ii __flock flock
fsconfig EXTRA fsconfig i:iUsNi fsconfig
fsmount EXTRA fsmount i:iUU fsmount