ref: 52b8e747b71a308a9cebb0e688c128262e3bd5ab
parent: e5dd8ad363ca3747c1757e0c3245dae713b0e3c8
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Aug 27 18:22:05 EDT 2016
Split spork and espork.
--- a/lib/std/spork.myr
+++ b/lib/std/spork.myr
@@ -6,11 +6,37 @@
use "errno"
pkg std =
- const spork : (cmd : byte[:][:] -> result((pid, fd, fd, fd), errno))
+ const spork : (cmd : byte[:][:] -> result((pid, fd, fd), errno))
+ const espork : (cmd : byte[:][:] -> result((pid, fd, fd, fd), errno))
const sporkfd : (cmd : byte[:][:], infd : fd, outfd : fd, errfd : fd -> result(pid, errno))
;;
const spork = {cmd
+ var infds : fd[2], outfds : fd[2]
+ var err
+
+ /* open up pipes */
+ err = pipe(&infds)
+ if err != Enone
+ -> `Err err
+ ;;
+ err = pipe(&outfds)
+ if err != Enone
+ -> `Err err
+ ;;
+
+ match sporkfd(cmd, infds[0], outfds[1], 2)
+ | `Ok pid:
+ /* close unused fd ends */
+ close(infds[0]);
+ close(outfds[1]);
+ -> `Ok (pid, infds[1], outfds[0])
+ | `Err m:
+ -> `Err m
+ ;;
+}
+
+const espork = {cmd
var infds : fd[2], outfds : fd[2], errfds : fd[2]
var err
@@ -57,7 +83,7 @@
| `Ok _: /* nothing */
| `Err e: -> `Err e
;;
- match dup2(outfd, 2)
+ match dup2(errfd, 2)
| `Ok _: /* nothing */
| `Err e: -> `Err e
;;