diff mbox

[Ada] Spawning processes with no PATH

Message ID 20151026113725.GA55234@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 26, 2015, 11:37 a.m. UTC
This patch fixes a bug in which GNAT.Expect.Non_Blocking_Spawn fails to find an
executable when the PATH environment variable is not set. The executable
should be found if it contains a directory name.

The following test should execute quietly.

gnatmake -q do_nothing.adb
gnatmake -q spawn.adb
unset PATH
./spawn

procedure Do_Nothing is
begin
   null;
end Do_Nothing;

with GNAT.Expect;
with GNAT.OS_Lib;
Procedure Spawn is

   P : GNAT.Expect.Process_Descriptor;
   T : constant GNAT.Os_Lib.Argument_List(1..0) := ( others => null);
begin
   GNAT.Expect.Non_Blocking_Spawn(P, "./do_nothing", T);
end Spawn;

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

2015-10-26  Bob Duff  <duff@adacore.com>

	* adaint.c (__gnat_locate_exec_on_path): If the PATH environment
	variable is not set, do not return NULL, because we can still find
	the executable if it includes a directory name.
diff mbox

Patch

Index: adaint.c
===================================================================
--- adaint.c	(revision 229320)
+++ adaint.c	(working copy)
@@ -2787,16 +2787,19 @@ 
   apath_val = (char *) alloca (EXPAND_BUFFER_SIZE);
 
   WS2SC (apath_val, wapath_val, EXPAND_BUFFER_SIZE);
-  return __gnat_locate_exec (exec_name, apath_val);
 
 #else
   char *path_val = getenv ("PATH");
 
-  if (path_val == NULL) return NULL;
+  /* If PATH is not defined, proceed with __gnat_locate_exec anyway, so we can
+     find files that contain directory names.  */
+
+  if (path_val == NULL) path_val = "";
   apath_val = (char *) alloca (strlen (path_val) + 1);
   strcpy (apath_val, path_val);
+#endif
+
   return __gnat_locate_exec (exec_name, apath_val);
-#endif
 }
 
 /* Dummy functions for Osint import for non-VMS systems.