[Ada] Do not expect execv to return 0

Message ID 20211025150912.GA346548@adacore.com
State Committed
Commit 1be75e7451b00aca32ed96be43223ee67d163429
Headers
Series [Ada] Do not expect execv to return 0 |

Commit Message

Pierre-Marie de Rodat Oct. 25, 2021, 3:09 p.m. UTC
  When spawning subprocesses with fork & execv there is no need to check
the result of execve, because it either succeeds and does not return or
fails and returns -1.

This is only a code cleanup related to the use of fork-vs-vfork in
GNATprove; behaviour is unaffected, though the GNAT runtime library
will be marginally smaller.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* adaint.c (__gnat_portable_spawn): Do not expect execv to
	return 0.
	(__gnat_portable_no_block_spawn): Likewise.
  

Patch

diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c
--- a/gcc/ada/adaint.c
+++ b/gcc/ada/adaint.c
@@ -2424,8 +2424,10 @@  __gnat_portable_spawn (char *args[] ATTRIBUTE_UNUSED)
   if (pid == 0)
     {
       /* The child. */
-      if (execv (args[0], MAYBE_TO_PTR32 (args)) != 0)
-	_exit (1);
+      execv (args[0], MAYBE_TO_PTR32 (args));
+
+      /* execv() returns only on error */
+      _exit (1);
     }
 
   /* The parent.  */
@@ -2822,8 +2824,10 @@  __gnat_portable_no_block_spawn (char *args[] ATTRIBUTE_UNUSED)
   if (pid == 0)
     {
       /* The child.  */
-      if (execv (args[0], MAYBE_TO_PTR32 (args)) != 0)
-	_exit (1);
+      execv (args[0], MAYBE_TO_PTR32 (args));
+
+      /* execv() returns only on error */
+      _exit (1);
     }
 
   return pid;