* shell() now also uses vfork() instead of fork() on Darwin

git-svn-id: trunk@2930 -
This commit is contained in:
Jonas Maebe 2006-03-15 22:00:58 +00:00
parent 5155de6d61
commit 7d88ba2831
4 changed files with 42 additions and 8 deletions

1
.gitattributes vendored
View File

@ -4482,6 +4482,7 @@ rtl/unix/dynlibs.inc svneol=native#text/plain
rtl/unix/errors.pp svneol=native#text/plain
rtl/unix/fpmake.inc svneol=native#text/plain
rtl/unix/genfdset.inc svneol=native#text/plain
rtl/unix/genfunch.inc svneol=native#text/plain
rtl/unix/genfuncs.inc svneol=native#text/plain
rtl/unix/gensigset.inc svneol=native#text/plain
rtl/unix/initc.pp svneol=native#text/plain

View File

@ -45,6 +45,7 @@ Uses UnixType;
{$i bunxovlh.inc}
{$i genfunch.inc}
implementation

21
rtl/unix/genfunch.inc Normal file
View File

@ -0,0 +1,21 @@
{
This file is part of the Free Pascal run time library.
Copyright (c) 2002 by Marco van de Voort.
A few general purpose routines. General purpose enough for *BSD
and Linux at least.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program 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.
**********************************************************************}
function CreateShellArgV(const prog:string):ppchar;
function CreateShellArgV(const prog:Ansistring):ppchar;
procedure FreeShellArgV(p:ppchar);

View File

@ -384,6 +384,9 @@ End;
// execvP has the searchpath as array of ansistring ( const char *search_path)
{$define FPC_USE_FPEXEC}
{$if defined(FPC_USE_FPEXEC) and not defined(USE_VFORK)}
{$define SHELL_USE_FPEXEC}
{$endif}
Function Shell(const Command:String):cint;
{
Executes the shell, and passes it the string Command. (Through /bin/sh -c)
@ -399,19 +402,23 @@ Function Shell(const Command:String):cint;
- The Old CreateShellArg gives back pointers to a local var
}
var
{$ifndef FPC_USE_FPEXEC}
{$ifndef SHELL_USE_FPEXEC}
p : ppchar;
{$endif}
pid : cint;
begin
{$ifndef FPC_USE_FPEXEC}
{$ifndef SHELL_USE_FPEXEC}
p:=CreateShellArgv(command);
{$endif}
{$ifdef USE_VFORK}
pid:=fpvfork;
{$else USE_VFORK}
pid:=fpfork;
{$endif USE_VFORK}
if pid=0 then // We are in the Child
begin
{This is the child.}
{$ifndef FPC_USE_FPEXEC}
{$ifndef SHELL_USE_FPEXEC}
fpExecve(p^,p,envp);
{$else}
fpexecl('/bin/sh',['-c',Command]);
@ -422,7 +429,7 @@ begin
Shell:=WaitProcess(pid)
else // no success
Shell:=-1; // indicate an error
{$ifndef FPC_USE_FPEXEC}
{$ifndef SHELL_USE_FPEXEC}
FreeShellArgV(p);
{$endif}
end;
@ -432,18 +439,22 @@ Function Shell(const Command:AnsiString):cint;
AnsiString version of Shell
}
var
{$ifndef FPC_USE_FPEXEC}
{$ifndef SHELL_USE_FPEXEC}
p : ppchar;
{$endif}
pid : cint;
begin { Changes as above }
{$ifndef FPC_USE_FPEXEC}
{$ifndef SHELL_USE_FPEXEC}
p:=CreateShellArgv(command);
{$endif}
{$ifdef USE_VFORK}
pid:=fpvfork;
{$else USE_VFORK}
pid:=fpfork;
{$endif USE_VFORK}
if pid=0 then // We are in the Child
begin
{$ifdef FPC_USE_FPEXEC}
{$ifdef SHELL_USE_FPEXEC}
fpexecl('/bin/sh',['-c',Command]);
{$else}
fpExecve(p^,p,envp);
@ -454,7 +465,7 @@ begin { Changes as above }
Shell:=WaitProcess(pid)
else // no success
Shell:=-1;
{$ifndef FPC_USE_FPEXEC}
{$ifndef SHELL_USE_FPEXEC}
FreeShellArgV(p);
{$ENDIF}
end;