Forráskód Böngészése

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

git-svn-id: trunk@2930 -
Jonas Maebe 19 éve
szülő
commit
7d88ba2831
4 módosított fájl, 42 hozzáadás és 8 törlés
  1. 1 0
      .gitattributes
  2. 1 0
      rtl/unix/baseunix.pp
  3. 21 0
      rtl/unix/genfunch.inc
  4. 19 8
      rtl/unix/unix.pp

+ 1 - 0
.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

+ 1 - 0
rtl/unix/baseunix.pp

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

+ 21 - 0
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);

+ 19 - 8
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;