summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2014-02-24 20:28:57 +0100
committerAndreas Rumpf <rumpf_a@web.de>2014-02-24 20:28:57 +0100
commit1024e7a3dbe2686809d3388731e0700ffdab4932 (patch)
tree145fe654d5bc6346771dc56c01637b55abc1b909
parent00b69192f2fc4d5b0546d5b45a32383b2536275d (diff)
parent7314f11adc742169770ac718ca4a5417ef16d69e (diff)
downloadNim-1024e7a3dbe2686809d3388731e0700ffdab4932.tar.gz
Merge pull request #957 from zielmicha/macosx-fix
osproc: MacOSX workaround for lack of execvpe
-rw-r--r--lib/pure/osproc.nim13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim
index 79a4de04b..2a685f3fb 100644
--- a/lib/pure/osproc.nim
+++ b/lib/pure/osproc.nim
@@ -747,7 +747,7 @@ elif not defined(useNimRtl):
     var pid: TPid
     var dataCopy = data
 
-    if defined(useClone):
+    when defined(useClone):
       const stackSize = 65536
       let stackEnd = cast[clong](alloc(stackSize))
       let stack = cast[pointer](stackEnd + stackSize)
@@ -779,6 +779,9 @@ elif not defined(useNimRtl):
     discard write(data.pErrorPipe[writeIdx], addr error, sizeof(error))
     exitnow(1)
 
+  when defined(macosx):
+    var environ {.importc.}: cstringArray
+
   proc startProcessAfterFork(data: ptr TStartProcessData) =
     # Warning: no GC here!
     # Or anythink that touches global structures - all called nimrod procs
@@ -806,7 +809,13 @@ elif not defined(useNimRtl):
     discard fcntl(data.pErrorPipe[writeIdx], F_SETFD, FD_CLOEXEC)
 
     if data.optionPoUsePath:
-      discard execvpe(data.sysCommand, data.sysArgs, data.sysEnv)
+      when defined(macosx):
+        # MacOSX doesn't have execvpe, so we need workaround.
+        # On MacOSX we can arrive here only from fork, so this is safe:
+        environ = data.sysEnv
+        discard execvp(data.sysCommand, data.sysArgs)
+      else:
+        discard execvpe(data.sysCommand, data.sysArgs, data.sysEnv)
     else:
       discard execve(data.sysCommand, data.sysArgs, data.sysEnv)