public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Do not expect execv to return 0
@ 2021-10-25 15:09 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-10-25 15:09 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

[-- Attachment #1: Type: text/plain, Size: 506 bytes --]

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.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 770 bytes --]

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;



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-25 15:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-25 15:09 [Ada] Do not expect execv to return 0 Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).