mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 04:49:20 +02:00
* shell() now also uses vfork() instead of fork() on Darwin
git-svn-id: trunk@2930 -
This commit is contained in:
parent
5155de6d61
commit
7d88ba2831
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -4482,6 +4482,7 @@ rtl/unix/dynlibs.inc svneol=native#text/plain
|
|||||||
rtl/unix/errors.pp svneol=native#text/plain
|
rtl/unix/errors.pp svneol=native#text/plain
|
||||||
rtl/unix/fpmake.inc svneol=native#text/plain
|
rtl/unix/fpmake.inc svneol=native#text/plain
|
||||||
rtl/unix/genfdset.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/genfuncs.inc svneol=native#text/plain
|
||||||
rtl/unix/gensigset.inc svneol=native#text/plain
|
rtl/unix/gensigset.inc svneol=native#text/plain
|
||||||
rtl/unix/initc.pp svneol=native#text/plain
|
rtl/unix/initc.pp svneol=native#text/plain
|
||||||
|
@ -45,6 +45,7 @@ Uses UnixType;
|
|||||||
|
|
||||||
{$i bunxovlh.inc}
|
{$i bunxovlh.inc}
|
||||||
|
|
||||||
|
{$i genfunch.inc}
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
21
rtl/unix/genfunch.inc
Normal file
21
rtl/unix/genfunch.inc
Normal 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);
|
@ -384,6 +384,9 @@ End;
|
|||||||
// execvP has the searchpath as array of ansistring ( const char *search_path)
|
// execvP has the searchpath as array of ansistring ( const char *search_path)
|
||||||
|
|
||||||
{$define FPC_USE_FPEXEC}
|
{$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;
|
Function Shell(const Command:String):cint;
|
||||||
{
|
{
|
||||||
Executes the shell, and passes it the string Command. (Through /bin/sh -c)
|
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
|
- The Old CreateShellArg gives back pointers to a local var
|
||||||
}
|
}
|
||||||
var
|
var
|
||||||
{$ifndef FPC_USE_FPEXEC}
|
{$ifndef SHELL_USE_FPEXEC}
|
||||||
p : ppchar;
|
p : ppchar;
|
||||||
{$endif}
|
{$endif}
|
||||||
pid : cint;
|
pid : cint;
|
||||||
begin
|
begin
|
||||||
{$ifndef FPC_USE_FPEXEC}
|
{$ifndef SHELL_USE_FPEXEC}
|
||||||
p:=CreateShellArgv(command);
|
p:=CreateShellArgv(command);
|
||||||
{$endif}
|
{$endif}
|
||||||
|
{$ifdef USE_VFORK}
|
||||||
|
pid:=fpvfork;
|
||||||
|
{$else USE_VFORK}
|
||||||
pid:=fpfork;
|
pid:=fpfork;
|
||||||
|
{$endif USE_VFORK}
|
||||||
if pid=0 then // We are in the Child
|
if pid=0 then // We are in the Child
|
||||||
begin
|
begin
|
||||||
{This is the child.}
|
{This is the child.}
|
||||||
{$ifndef FPC_USE_FPEXEC}
|
{$ifndef SHELL_USE_FPEXEC}
|
||||||
fpExecve(p^,p,envp);
|
fpExecve(p^,p,envp);
|
||||||
{$else}
|
{$else}
|
||||||
fpexecl('/bin/sh',['-c',Command]);
|
fpexecl('/bin/sh',['-c',Command]);
|
||||||
@ -422,7 +429,7 @@ begin
|
|||||||
Shell:=WaitProcess(pid)
|
Shell:=WaitProcess(pid)
|
||||||
else // no success
|
else // no success
|
||||||
Shell:=-1; // indicate an error
|
Shell:=-1; // indicate an error
|
||||||
{$ifndef FPC_USE_FPEXEC}
|
{$ifndef SHELL_USE_FPEXEC}
|
||||||
FreeShellArgV(p);
|
FreeShellArgV(p);
|
||||||
{$endif}
|
{$endif}
|
||||||
end;
|
end;
|
||||||
@ -432,18 +439,22 @@ Function Shell(const Command:AnsiString):cint;
|
|||||||
AnsiString version of Shell
|
AnsiString version of Shell
|
||||||
}
|
}
|
||||||
var
|
var
|
||||||
{$ifndef FPC_USE_FPEXEC}
|
{$ifndef SHELL_USE_FPEXEC}
|
||||||
p : ppchar;
|
p : ppchar;
|
||||||
{$endif}
|
{$endif}
|
||||||
pid : cint;
|
pid : cint;
|
||||||
begin { Changes as above }
|
begin { Changes as above }
|
||||||
{$ifndef FPC_USE_FPEXEC}
|
{$ifndef SHELL_USE_FPEXEC}
|
||||||
p:=CreateShellArgv(command);
|
p:=CreateShellArgv(command);
|
||||||
{$endif}
|
{$endif}
|
||||||
|
{$ifdef USE_VFORK}
|
||||||
|
pid:=fpvfork;
|
||||||
|
{$else USE_VFORK}
|
||||||
pid:=fpfork;
|
pid:=fpfork;
|
||||||
|
{$endif USE_VFORK}
|
||||||
if pid=0 then // We are in the Child
|
if pid=0 then // We are in the Child
|
||||||
begin
|
begin
|
||||||
{$ifdef FPC_USE_FPEXEC}
|
{$ifdef SHELL_USE_FPEXEC}
|
||||||
fpexecl('/bin/sh',['-c',Command]);
|
fpexecl('/bin/sh',['-c',Command]);
|
||||||
{$else}
|
{$else}
|
||||||
fpExecve(p^,p,envp);
|
fpExecve(p^,p,envp);
|
||||||
@ -454,7 +465,7 @@ begin { Changes as above }
|
|||||||
Shell:=WaitProcess(pid)
|
Shell:=WaitProcess(pid)
|
||||||
else // no success
|
else // no success
|
||||||
Shell:=-1;
|
Shell:=-1;
|
||||||
{$ifndef FPC_USE_FPEXEC}
|
{$ifndef SHELL_USE_FPEXEC}
|
||||||
FreeShellArgV(p);
|
FreeShellArgV(p);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user