[MLton-commit] r5485

Matthew Fluet fluet at mlton.org
Thu Mar 29 10:54:31 PST 2007


Patch from Nicolas Bertolotti (PolySpace).

- bug-fix-spawn-with-fork.patch

This patch consists in adding a call to "exit" when the "exec" call fails
after a successful "fork" in the "spawn" implementation. If we don't do so,
the current process will be duplicated in case the "exec" fails.


----------------------------------------------------------------------

U   mlton/trunk/basis-library/mlton/process.sml

----------------------------------------------------------------------

Modified: mlton/trunk/basis-library/mlton/process.sml
===================================================================
--- mlton/trunk/basis-library/mlton/process.sml	2007-03-29 16:57:25 UTC (rev 5484)
+++ mlton/trunk/basis-library/mlton/process.sml	2007-03-29 18:54:31 UTC (rev 5485)
@@ -242,7 +242,7 @@
                   ; dup2 (stdout, FileSys.stdout)
                   ; dup2 (stderr, FileSys.stderr)
                   ; ignore (Process.exece (path, base :: args, env))
-                  ; Process.exit 0w1 (* just in case *)
+                  ; Process.exit 0w127 (* just in case *)
                end
           | SOME pid => pid (* parent *)
 
@@ -330,7 +330,8 @@
                end
          else
             case Posix.Process.fork () of
-               NONE => Posix.Process.exece (path, args, env)
+               NONE => (Posix.Process.exece (path, args, env) handle _ => ()
+                        ; Posix.Process.exit 0w127)
              | SOME pid => pid
 
       fun spawn {args, path}= 
@@ -352,7 +353,8 @@
                end
          else    
             case Posix.Process.fork () of
-               NONE => Posix.Process.execp (file, args)
+               NONE => (Posix.Process.execp (file, args) handle _ => ()
+                        ; Posix.Process.exit 0w127)
              | SOME pid => pid
 
       open Exit




More information about the MLton-commit mailing list