This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug ada/20075] New: Bug in GNAT.Expect.Non_Blocking_Spawn
- From: "sbellon at sbellon dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Feb 2005 11:39:38 -0000
- Subject: [Bug ada/20075] New: Bug in GNAT.Expect.Non_Blocking_Spawn
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
GNAT.Expect.Non_Blocking_Spawn puts Command_With_Path into argv[0] when calling
__gnat_expect_portable_execvp (via Set_Up_Child_Communications). This leads to
problems on Windows when the path to command contains spaces as the spawned
process only returns the path up to the first space when questioning argv[0]. A
fix is to only put just Command (without the complete path) into argv[0]. The
spawn versions in GNAT.OS_Lib do it that way, so GNAT.Expect.Non_Blocking_Spawn
is inconsistent anyway.
The fix is simple and needs only to change two lines (patch for GCC 3.4.4 but is
similar for 3.15p as well):
--- 3.4.4/g-expect.adb 2005-02-19 12:28:29.350605929 +0100
+++ patched/g-expect.adb 2005-02-19 12:29:16.332632637 +0100
@@ -873,8 +873,8 @@
if Descriptor.Pid = Null_Pid then
-- Prepare an array of arguments to pass to C
- Arg := new String (1 .. Command_With_Path'Length + 1);
- Arg (1 .. Command_With_Path'Length) := Command_With_Path.all;
+ Arg := new String (1 .. Command'Length + 1);
+ Arg (1 .. Command'Length) := Command;
Arg (Arg'Last) := ASCII.NUL;
Arg_List (1) := Arg;
A minimal test case that shows the problem needs two main programs, one
(launcher.adb) which launches the other (show_params.adb):
$ cat show_params.adb
with Ada.Command_Line;
with Ada.Text_IO;
procedure Show_Params is
begin
Ada.Text_IO.Put_Line (Ada.Command_Line.Command_Name);
end Show_Params;
$ cat show launcher.adb
with Ada.Text_IO;
with GNAT.OS_Lib;
with GNAT.Expect;
procedure Launcher is
Args : GNAT.OS_Lib.Argument_List (1 .. 0);
PD : GNAT.Expect.Process_Descriptor;
Succ : Boolean;
Res : GNAT.Expect.Expect_Match;
use type GNAT.Expect.Expect_Match;
begin
Ada.Text_IO.Put_Line ("via GNAT.OS_Lib.Spawn:");
GNAT.OS_Lib.Spawn ("show_params", Args, Succ);
Ada.Text_IO.Put_Line ("via GNAT.Expect.Non_Blocking_Spawn:");
GNAT.Expect.Non_Blocking_Spawn (PD, "show_params", Args);
begin
loop
GNAT.Expect.Expect (PD, Res, ".");
if Res >= 0 then
Ada.Text_IO.Put (GNAT.Expect.Expect_Out (PD));
end if;
end loop;
exception
when GNAT.Expect.Process_Died =>
GNAT.Expect.Close (PD);
end;
end Launcher;
$ gnatmake show_params.adb
gcc-3.4 -c show_params.adb
gnatbind -x show_params.ali
gnatlink show_params.ali
$ gnatmake launcher.adb
gcc-3.4 -c launcher.adb
gnatbind -x launcher.ali
gnatlink launcher.ali
Put show_params somewhere in your $PATH and start launcher. You'll see that via
GNAT.OS_Lib, only the basename of the command is put into argv[0] and via
GNAT.Expect, the whole path is put there. Now, if you put show_params into a
path with some spaces, you'll see the problem:
$ PATH=`pwd` launcher
via GNAT.OS_Lib.Spawn:
show_params
via GNAT.Expect.Non_Blocking_Spawn:
/home/sbellon/tmp/show params/show_params
It works under GNU/Linux, but it fails on Windows. If you put show_params.exe
into a path of "C:\Program Files\show_params.exe", put that into your %PATH% and
start launcher.exe, then you'll see that only "C:\Program" is returned as
Ada.Command_Line.Command_Name.
This is true for all versions of GNAT we have looked at (GNAT 3.15p, GCC 3.3.x
and GCC 3.4.x). As the fix is very simple, I hope it can be applied to the
current version before the release of GCC 4.0 and perhaps even backported to
older versions.
According to your instructions of how to submit a bug report, I'll include all
the further details but I don't see that they're relevant here as it's a simple
bug in the GNAT lib and is present across all versions of GNAT and all
target/host configurations (applies to MinGW as well).
$ gcc-3.4 -v
Reading specs from /usr/lib/gcc/i486-linux/3.4.4/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--libexecdir=/usr/lib --with-gxx-include-dir=/usr/include/c++/3.4
--enable-shared --with-system-zlib --enable-nls --without-included-gettext
--program-suffix=-3.4 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt
--enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm
--enable-java-awt=gtk --disable-werror i486-linux
Thread model: posix
gcc version 3.4.4 20050203 (prerelease) (Debian 3.4.3-9)
--
Summary: Bug in GNAT.Expect.Non_Blocking_Spawn
Product: gcc
Version: 3.4.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: ada
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sbellon at sbellon dot de
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20075