diff --git a/.gitattributes b/.gitattributes index 436185794b..02b4dadf12 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/rtl/unix/baseunix.pp b/rtl/unix/baseunix.pp index 5d4139f07e..5b6376d1b3 100644 --- a/rtl/unix/baseunix.pp +++ b/rtl/unix/baseunix.pp @@ -45,6 +45,7 @@ Uses UnixType; {$i bunxovlh.inc} +{$i genfunch.inc} implementation diff --git a/rtl/unix/genfunch.inc b/rtl/unix/genfunch.inc new file mode 100644 index 0000000000..00a09b1833 --- /dev/null +++ b/rtl/unix/genfunch.inc @@ -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); diff --git a/rtl/unix/unix.pp b/rtl/unix/unix.pp index 495c51f24d..a3f7a1b116 100644 --- a/rtl/unix/unix.pp +++ b/rtl/unix/unix.pp @@ -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;