diff mbox series

[v2,06/13] posix: Introduce the __arch_spawni function

Message ID 465f313f9ae9e74fd610ca63f4afc02992ce68c0.1722193092.git.fweimer@redhat.com
State New
Headers show
Series getenv/environ thread safety | expand

Commit Message

Florian Weimer July 28, 2024, 7:02 p.m. UTC
And move the definition of SPAWN_ERROR to spawn_int.h.

The separate __arch_spawni function allows centralized
implementation of preparatory code in posix/spawni.c, which is no
longer a stub after this commit.
---
 posix/spawn_int.h                             |  7 +++++
 posix/spawni.c                                | 15 ++---------
 sysdeps/generic/arch-spawni.h                 | 27 +++++++++++++++++++
 sysdeps/mach/hurd/{spawni.c => arch-spawni.h} | 12 ++++-----
 .../sysv/linux/{spawni.c => arch-spawni.h}    | 18 ++++---------
 5 files changed, 47 insertions(+), 32 deletions(-)
 create mode 100644 sysdeps/generic/arch-spawni.h
 rename sysdeps/mach/hurd/{spawni.c => arch-spawni.h} (99%)
 rename sysdeps/unix/sysv/linux/{spawni.c => arch-spawni.h} (96%)

Comments

Adhemerval Zanella Netto Oct. 29, 2024, 8:29 p.m. UTC | #1
On 28/07/24 16:02, Florian Weimer wrote:
> And move the definition of SPAWN_ERROR to spawn_int.h.
> 
> The separate __arch_spawni function allows centralized
> implementation of preparatory code in posix/spawni.c, which is no
> longer a stub after this commit.

LGTM, thanks.

> ---
>  posix/spawn_int.h                             |  7 +++++
>  posix/spawni.c                                | 15 ++---------
>  sysdeps/generic/arch-spawni.h                 | 27 +++++++++++++++++++
>  sysdeps/mach/hurd/{spawni.c => arch-spawni.h} | 12 ++++-----
>  .../sysv/linux/{spawni.c => arch-spawni.h}    | 18 ++++---------
>  5 files changed, 47 insertions(+), 32 deletions(-)
>  create mode 100644 sysdeps/generic/arch-spawni.h
>  rename sysdeps/mach/hurd/{spawni.c => arch-spawni.h} (99%)
>  rename sysdeps/unix/sysv/linux/{spawni.c => arch-spawni.h} (96%)
> 
> diff --git a/posix/spawn_int.h b/posix/spawn_int.h
> index 2cdb55b4d6..9d0de483fe 100644
> --- a/posix/spawn_int.h
> +++ b/posix/spawn_int.h
> @@ -78,6 +78,13 @@ struct __spawn_action
>  #define SPAWN_XFLAGS_TRY_SHELL	0x2
>  #define SPAWN_XFLAGS_RET_PIDFD  0x4
>  
> +/* The Unix standard contains a long explanation of the way to signal
> +   an error after the fork() was successful.  Since no new wait status
> +   was wanted there is no way to signal an error using one of the
> +   available methods.  The committee chose to signal an error by a
> +   normal program exit with the exit code 127.  */
> +#define SPAWN_ERROR	127
> +
>  extern int __posix_spawn_file_actions_realloc (posix_spawn_file_actions_t *
>  					       file_actions)
>       attribute_hidden;
> diff --git a/posix/spawni.c b/posix/spawni.c
> index 52ff5f1966..ef47dd9ea4 100644
> --- a/posix/spawni.c
> +++ b/posix/spawni.c
> @@ -19,15 +19,7 @@
>  #include <errno.h>
>  #include <spawn.h>
>  #include "spawn_int.h"
> -
> -
> -/* The Unix standard contains a long explanation of the way to signal
> -   an error after the fork() was successful.  Since no new wait status
> -   was wanted there is no way to signal an error using one of the
> -   available methods.  The committee chose to signal an error by a
> -   normal program exit with the exit code 127.  */
> -#define SPAWN_ERROR	127
> -
> +#include <arch-spawni.h>
>  
>  /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
>     Before running the process perform the actions described in FILE-ACTIONS. */
> @@ -37,8 +29,5 @@ __spawni (pid_t *pid, const char *file,
>  	  const posix_spawnattr_t *attrp, char *const argv[],
>  	  char *const envp[], int xflags)
>  {
> -  __set_errno (ENOSYS);
> -  return -1;
> +  return __arch_spawni (pid, file, file_actions, attrp, argv, envp, xflags);
>  }
> -
> -stub_warning (__spawni)

I think it should be ok to remove the stub warning since Hurd also supports it.

> diff --git a/sysdeps/generic/arch-spawni.h b/sysdeps/generic/arch-spawni.h
> new file mode 100644
> index 0000000000..ad225d642d
> --- /dev/null
> +++ b/sysdeps/generic/arch-spawni.h
> @@ -0,0 +1,27 @@
> +/* Architecture-specific __spawni 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
> +   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/>.  */
> +
> +static int
> +__arch_spawni (pid_t *pid, const char *file,
> +               const posix_spawn_file_actions_t *file_actions,
> +               const posix_spawnattr_t *attrp, char *const argv[],
> +               char *const envp[], int xflags)
> +{
> +  __set_errno (ENOSYS);
> +  return -1;
> +}
> diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/arch-spawni.h
> similarity index 99%
> rename from sysdeps/mach/hurd/spawni.c
> rename to sysdeps/mach/hurd/arch-spawni.h
> index a0d2e28c8e..6c1b9e98ad 100644
> --- a/sysdeps/mach/hurd/spawni.c
> +++ b/sysdeps/mach/hurd/arch-spawni.h
> @@ -36,12 +36,12 @@
>  
>  /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
>     Before running the process perform the actions described in FILE-ACTIONS. */
> -int
> -__spawni (pid_t *pid, const char *file,
> -	  const posix_spawn_file_actions_t *file_actions,
> -	  const posix_spawnattr_t *attrp,
> -	  char *const argv[], char *const envp[],
> -	  int xflags)
> +static int
> +__arch_spawni (pid_t *pid, const char *file,
> +	       const posix_spawn_file_actions_t *file_actions,
> +	       const posix_spawnattr_t *attrp,
> +	       char *const argv[], char *const envp[],
> +	       int xflags)
>  {
>    pid_t new_pid;
>    char *path, *p, *name;
> diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/arch-spawni.h
> similarity index 96%
> rename from sysdeps/unix/sysv/linux/spawni.c
> rename to sysdeps/unix/sysv/linux/arch-spawni.h
> index f57e92815e..8caf74f7f5 100644
> --- a/sysdeps/unix/sysv/linux/spawni.c
> +++ b/sysdeps/unix/sysv/linux/arch-spawni.h
> @@ -47,14 +47,6 @@
>     child has either exec'ed successfully or exited.  */
>  
>  
> -/* The Unix standard contains a long explanation of the way to signal
> -   an error after the fork() was successful.  Since no new wait status
> -   was wanted there is no way to signal an error using one of the
> -   available methods.  The committee chose to signal an error by a
> -   normal program exit with the exit code 127.  */
> -#define SPAWN_ERROR	127
> -
> -
>  struct posix_spawn_args
>  {
>    internal_sigset_t oldmask;
> @@ -483,11 +475,11 @@ __spawnix (int *pid, const char *file,
>  
>  /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
>     Before running the process perform the actions described in FILE-ACTIONS. */
> -int
> -__spawni (pid_t * pid, const char *file,
> -	  const posix_spawn_file_actions_t * acts,
> -	  const posix_spawnattr_t * attrp, char *const argv[],
> -	  char *const envp[], int xflags)
> +static int
> +__arch_spawni (pid_t * pid, const char *file,
> +	       const posix_spawn_file_actions_t * acts,
> +	       const posix_spawnattr_t * attrp, char *const argv[],
> +	       char *const envp[], int xflags)
>  {
>    /* It uses __execvpex to avoid run ENOEXEC in non compatibility mode (it
>       will be handled by maybe_script_execute).  */
diff mbox series

Patch

diff --git a/posix/spawn_int.h b/posix/spawn_int.h
index 2cdb55b4d6..9d0de483fe 100644
--- a/posix/spawn_int.h
+++ b/posix/spawn_int.h
@@ -78,6 +78,13 @@  struct __spawn_action
 #define SPAWN_XFLAGS_TRY_SHELL	0x2
 #define SPAWN_XFLAGS_RET_PIDFD  0x4
 
+/* The Unix standard contains a long explanation of the way to signal
+   an error after the fork() was successful.  Since no new wait status
+   was wanted there is no way to signal an error using one of the
+   available methods.  The committee chose to signal an error by a
+   normal program exit with the exit code 127.  */
+#define SPAWN_ERROR	127
+
 extern int __posix_spawn_file_actions_realloc (posix_spawn_file_actions_t *
 					       file_actions)
      attribute_hidden;
diff --git a/posix/spawni.c b/posix/spawni.c
index 52ff5f1966..ef47dd9ea4 100644
--- a/posix/spawni.c
+++ b/posix/spawni.c
@@ -19,15 +19,7 @@ 
 #include <errno.h>
 #include <spawn.h>
 #include "spawn_int.h"
-
-
-/* The Unix standard contains a long explanation of the way to signal
-   an error after the fork() was successful.  Since no new wait status
-   was wanted there is no way to signal an error using one of the
-   available methods.  The committee chose to signal an error by a
-   normal program exit with the exit code 127.  */
-#define SPAWN_ERROR	127
-
+#include <arch-spawni.h>
 
 /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
    Before running the process perform the actions described in FILE-ACTIONS. */
@@ -37,8 +29,5 @@  __spawni (pid_t *pid, const char *file,
 	  const posix_spawnattr_t *attrp, char *const argv[],
 	  char *const envp[], int xflags)
 {
-  __set_errno (ENOSYS);
-  return -1;
+  return __arch_spawni (pid, file, file_actions, attrp, argv, envp, xflags);
 }
-
-stub_warning (__spawni)
diff --git a/sysdeps/generic/arch-spawni.h b/sysdeps/generic/arch-spawni.h
new file mode 100644
index 0000000000..ad225d642d
--- /dev/null
+++ b/sysdeps/generic/arch-spawni.h
@@ -0,0 +1,27 @@ 
+/* Architecture-specific __spawni 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
+   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/>.  */
+
+static int
+__arch_spawni (pid_t *pid, const char *file,
+               const posix_spawn_file_actions_t *file_actions,
+               const posix_spawnattr_t *attrp, char *const argv[],
+               char *const envp[], int xflags)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/arch-spawni.h
similarity index 99%
rename from sysdeps/mach/hurd/spawni.c
rename to sysdeps/mach/hurd/arch-spawni.h
index a0d2e28c8e..6c1b9e98ad 100644
--- a/sysdeps/mach/hurd/spawni.c
+++ b/sysdeps/mach/hurd/arch-spawni.h
@@ -36,12 +36,12 @@ 
 
 /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
    Before running the process perform the actions described in FILE-ACTIONS. */
-int
-__spawni (pid_t *pid, const char *file,
-	  const posix_spawn_file_actions_t *file_actions,
-	  const posix_spawnattr_t *attrp,
-	  char *const argv[], char *const envp[],
-	  int xflags)
+static int
+__arch_spawni (pid_t *pid, const char *file,
+	       const posix_spawn_file_actions_t *file_actions,
+	       const posix_spawnattr_t *attrp,
+	       char *const argv[], char *const envp[],
+	       int xflags)
 {
   pid_t new_pid;
   char *path, *p, *name;
diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/arch-spawni.h
similarity index 96%
rename from sysdeps/unix/sysv/linux/spawni.c
rename to sysdeps/unix/sysv/linux/arch-spawni.h
index f57e92815e..8caf74f7f5 100644
--- a/sysdeps/unix/sysv/linux/spawni.c
+++ b/sysdeps/unix/sysv/linux/arch-spawni.h
@@ -47,14 +47,6 @@ 
    child has either exec'ed successfully or exited.  */
 
 
-/* The Unix standard contains a long explanation of the way to signal
-   an error after the fork() was successful.  Since no new wait status
-   was wanted there is no way to signal an error using one of the
-   available methods.  The committee chose to signal an error by a
-   normal program exit with the exit code 127.  */
-#define SPAWN_ERROR	127
-
-
 struct posix_spawn_args
 {
   internal_sigset_t oldmask;
@@ -483,11 +475,11 @@  __spawnix (int *pid, const char *file,
 
 /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
    Before running the process perform the actions described in FILE-ACTIONS. */
-int
-__spawni (pid_t * pid, const char *file,
-	  const posix_spawn_file_actions_t * acts,
-	  const posix_spawnattr_t * attrp, char *const argv[],
-	  char *const envp[], int xflags)
+static int
+__arch_spawni (pid_t * pid, const char *file,
+	       const posix_spawn_file_actions_t * acts,
+	       const posix_spawnattr_t * attrp, char *const argv[],
+	       char *const envp[], int xflags)
 {
   /* It uses __execvpex to avoid run ENOEXEC in non compatibility mode (it
      will be handled by maybe_script_execute).  */